Surface selectOneMenu listener is not called with objects other than strings

I am implementing webapp using Jsf 2.0 and Primefaces 3.2. I noticed this unexpected behavior: I have selectOneMenuand commandButton, as shown below

<p:selectOneMenu id="selsel" value="#{bean.myObj}">
  <f:selectItems value="#{bean.myObjList}" />
</p:selectOneMenu>
<p:commandButton id="btnid" value="Ok" actionListener="#{bean.updateSelectValues()}" />

What happens, if myObjnot String, the method is updateSelectValuesnot called. I do not see any exceptions or errors at all, it is simply not caused. Here is the bean support:

private List<MyObj> myObjList;
private MyObj myObj;
// getters and setters

public void updateSelectValues() {
  System.out.println(this.myObj);
}

Code for myObj:

public class MyObj implements Serializable {

  private static final long serialVersionUID = 1L;

  private String param1;
  private int param2;

  @Override
  public String toString() {
    StringBuilder builder = new StringBuilder();
    builder.append("MyObj [param1=");
    builder.append(this.param1);
    builder.append(", param2=");
    builder.append(this.param2);
    builder.append("]");
    return builder.toString();
  }

}
+2
source share
1 answer

, HTML HTTP Java. Java String, HTML JSF. HTTP-, String, Java, JSF.

, <h:message>, <h:messages> PrimeFaces, ( ajax), "null converter" ". , , .

Converter, MyObj String. :

@FacesConverter(forClass=MyObj.class)
public class MyObjConverter implements Converter {

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object valueToRender) {
        // Convert MyObj to its unique String representation.
    }

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String submittedValue) {
        // Convert String to MyObj.
    }

}

. String.

+8

All Articles