Author: adubovsky
Date: 2008-11-21 08:18:37 -0500 (Fri, 21 Nov 2008)
New Revision: 11287
Modified:
trunk/test-applications/automator/src/main/java/comboBox/ComboBoxGeneral.java
trunk/test-applications/automator/src/main/webapp/component/comboBox.jsp
Log:
+ converter
Modified: trunk/test-applications/automator/src/main/java/comboBox/ComboBoxGeneral.java
===================================================================
---
trunk/test-applications/automator/src/main/java/comboBox/ComboBoxGeneral.java 2008-11-21
09:42:06 UTC (rev 11286)
+++
trunk/test-applications/automator/src/main/java/comboBox/ComboBoxGeneral.java 2008-11-21
13:18:37 UTC (rev 11287)
@@ -7,6 +7,8 @@
import javax.faces.component.UIComponent;
import javax.faces.component.html.HtmlPanelGrid;
import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+import javax.faces.convert.ConverterException;
import javax.faces.event.ActionEvent;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;
@@ -29,11 +31,12 @@
private boolean required;
private String align;
private String validatorMessage;
+ private SelectItem value;
private boolean statusValidator = false;
private String phaseValidator = "UNDEFINED";
private String validatorMessageTest = "";
-
+
private boolean statusValueChangeListener = false;
private String phaseValueChangeListener = "UNDEFINED";
@@ -42,7 +45,7 @@
private ArrayList<Attribute> generalAttrs = attrs.getCommonAttributes();
public ComboBoxGeneral() {
- immediate = false;
+ immediate = true;
required = true;
align = "right";
validatorMessage = "validator test message!";
@@ -62,28 +65,24 @@
DrawGrids.showResultGrid(panelGrid, generalAttrs);
}
-
+
public void valueChangeListener(ValueChangeEvent e) {
- System.out.println("valueChangeListener work!!!!!!!!!!!!!!");
-
statusValueChangeListener = true;
phaseValueChangeListener = PhaseTracker.currentPhase.toString();
}
-
- public void valueChangeListenerCheck() {
+
+ private void valueChangeListenerCheck() {
int index = generalAttrs.indexOf(new Attribute("valueChangeListener"));
if (index == -1) {
- generalAttrs
- .add(new Attribute(
- "valueChangeListener",
- "",
- "", Status.IMPLEMENTED));
+ generalAttrs.add(new Attribute("valueChangeListener", "",
"",
+ Status.IMPLEMENTED));
} else {
Attribute attr = generalAttrs.get(index);
if (statusValueChangeListener) {
if ((phaseValueChangeListener.equals("PROCESS_VALIDATIONS 3"))
&& (!immediate)
- || (phaseValueChangeListener.equals("APPLY_REQUEST_VALUES 2"))
+ || (phaseValueChangeListener
+ .equals("APPLY_REQUEST_VALUES 2"))
&& (immediate)) {
attr.setStatus(Status.PASSED);
} else {
@@ -103,13 +102,14 @@
statusValidator = true;
phaseValidator = PhaseTracker.currentPhase.toString();
- String selectedItem = null;
- if (value != null)
- selectedItem = value.toString();
- if (selectedItem.equals("Gosha"))
- throw new ValidatorException(new FacesMessage(
- FacesMessage.SEVERITY_ERROR, "Validation error",
- "Incorrect input"));
+ if (value != null) {
+ SelectItem st = (SelectItem) value;
+ if (st.getLabel().equals("Gosha")) {
+ throw new ValidatorException(new FacesMessage(
+ FacesMessage.SEVERITY_ERROR, "Validation error",
+ "Incorrect input"));
+ }
+ }
}
private void validatorCheck() {
@@ -140,6 +140,44 @@
}
}
+ public Converter getConvert() {
+ return new Converter() {
+ public Object getAsObject(FacesContext context,
+ UIComponent component, String newValue)
+ throws ConverterException {
+
+ if (false)
+ throw new ConverterException(new FacesMessage(
+ FacesMessage.SEVERITY_ERROR, "Converter error",
+ "Error while convert to Object"));
+
+ return new SelectItem(newValue);
+ }
+
+ public String getAsString(FacesContext context,
+ UIComponent component, Object value)
+ throws ConverterException {
+
+ if (false)
+ throw new ConverterException(new FacesMessage(
+ FacesMessage.SEVERITY_ERROR, "Converter error",
+ "Error while convert to String"));
+
+ String result = "";
+ if (value != null) {
+ if(value instanceof SelectItem) {
+ SelectItem st = (SelectItem) value;
+ result = st.getLabel();
+ } else {
+ result = value.toString();
+ }
+ }
+
+ return result;
+ }
+ };
+ }
+
private void alignCheck() {
int index = generalAttrs.indexOf(new Attribute("align"));
if (index == -1) {
@@ -246,4 +284,12 @@
public void setValidatorMessageTest(String validatorMessageTest) {
this.validatorMessageTest = validatorMessageTest;
}
+
+ public SelectItem getValue() {
+ return value;
+ }
+
+ public void setValue(SelectItem value) {
+ this.value = value;
+ }
}
\ No newline at end of file
Modified: trunk/test-applications/automator/src/main/webapp/component/comboBox.jsp
===================================================================
--- trunk/test-applications/automator/src/main/webapp/component/comboBox.jsp 2008-11-21
09:42:06 UTC (rev 11286)
+++ trunk/test-applications/automator/src/main/webapp/component/comboBox.jsp 2008-11-21
13:18:37 UTC (rev 11287)
@@ -12,9 +12,12 @@
<h:messages id="mess" style="color: red" />
<rich:comboBox id="comboBox"
binding="#{comboBoxGeneral.comboBox}"
align="#{comboBoxGeneral.align}"
+ immediate="#{comboBoxGeneral.immediate}"
+ value="#{comboBoxGeneral.value}"
validator="#{comboBoxGeneral.validate}"
required="#{comboBoxGeneral.required}"
validatorMessage="#{comboBoxGeneral.validatorMessage}"
+ converter="#{comboBoxGeneral.convert}"
onblur="callOnblur('comboBox')"
onmouseover="callOnmouseover('comboBox')"
onclick="callOnclick('comboBox')"
onchange="callOnchange('comboBox')"
Show replies by date