jsf 1.2 - JSF 1.2 empty <h:selectManyListbox /> validation issue -


i'm kind of new jsf , i'm having trouble understand values jsf renders in form after validation fails. im using websphere 7 , default implementation of jsf, myfaces (i think 2.0).

my xhtml looks this:

<h:form id="form">     <h:inputtext id="text" value="#{backing.text}" required="true"/>     <h:message for="text" />      <h:selectmanylistbox id="options" value="#{backing.options}" required="true">         <f:selectitem itemlabel="1" itemvalue="1" />         <f:selectitem itemlabel="2" itemvalue="2" />         <f:selectitem itemlabel="3" itemvalue="3" />     </h:selectmanylistbox>     <h:message for="options" />      <h:commandbutton value="save" /> </h:form> 

and backing bean this:

public class backing {      private string text;      private string[] options;      public string gettext() {         return text;     }      public void settext(string text) {         this.text = text;     }      public string[] getoptions() {         return options;     }      public void setoptions(string[] options) {         this.options = options;     } } 
  1. i fill <h:inputtext /> text.
  2. i select 2 options <h:selectmanylistbox />
  3. i press 'save' button
  4. the form rendered value entered <h:inputtext /> , options selected on <h:selectmanylistbox /> (no validation messages shown, expected)
  5. now ...
  6. i empty <h:inputtext />
  7. i deselect 2 options <h:selectmanylistbox />
  8. i press 'save' button
  9. the form renders <h:inputtext /> empty , <h:selectmanylistbox /> previous options had selected (both validation messages shown, expected)

as can see, behaviour when rendering <h:inputtext /> , <h:selectmanylistbox /> different:

  • <h:inputtext /> renders component's submitted value
  • <h:selectmanylistbox /> renders bean's value

i've been trying render <h:selectmanylistbox /> no options selected without hacking or messing code, had no luck.

¿is bug? ¿am missing something?

the less hacky solution found copy , re-implement method renderoption, overriding default menurenderer.

the original source had decompile (version 1.2_13). notice i'm pasting lines need changed. if need use solution have copy full contents of method:

public class menurenderer extends htmlbasicinputrenderer {     protected void renderoption(facescontext context, uicomponent component, converter converter, selectitem curitem, object currentselections, object[] submittedvalues, htmlbasicrenderer.optioncomponentinfo optioninfo) throws ioexception {         (...)         object valuesarray;         object itemvalue;         if (submittedvalues != null) {             boolean containsvalue = containsavalue(submittedvalues);             if (containsvalue) {                 valuesarray = submittedvalues;                 itemvalue = valuestring;             } else {                 valuesarray = currentselections;                 itemvalue = curitem.getvalue();             }         } else {             valuesarray = currentselections;             itemvalue = curitem.getvalue();         }         (...)     } } 

i created customlistboxrenderer (listboxrenderer extends menurenderer) this:

public class customlistboxrenderer extends listboxrenderer {     @override     protected void renderoption(facescontext context, uicomponent component, converter converter, selectitem curitem, object currentselections, object[] submittedvalues, htmlbasicrenderer.optioncomponentinfo optioninfo) throws ioexception {         (...)         object valuesarray;         object itemvalue;         if (submittedvalues != null) {             valuesarray = submittedvalues;             itemvalue = valuestring;         } else {             valuesarray = currentselections;             itemvalue = curitem.getvalue();         }         (...)     } } 

and added in faces-config next lines:

<render-kit>     <renderer>         <component-family>javax.faces.selectmany</component-family>         <renderer-type>javax.faces.listbox</renderer-type>         <renderer-class>customlistboxrenderer</renderer-class>     </renderer> </render-kit> 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -