0

I have a h:selectOneMenu which served me with no issues in the past but for some reason the value in searchResults.selectedCategories is always null when submitting the form.

The widget is inside a form. The backing bean has selectedCategories as a private String with accessor methods. I tried cleaning the project, closing down Eclipse, and republishing it to Tomcat. Nothing works. Any idea why?

This is the widget:

<h:selectOneMenu id="categoriesBoxSimple" value="#{searchResults.selectedCategories}" >
  <f:selectItem itemLabel="Category 1" itemValue="283331" />                    
  <f:selectItem itemLabel="Category 2" itemValue="281" />
  <f:selectItem itemLabel="Category 3" itemValue="1115"/>
</h:selectOneMenu>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Eddy
  • 3,533
  • 13
  • 59
  • 89
  • "Nothing works" is not a proper description of your actual problem. - Look for validation errors, check if the setter method is called. – stg Feb 11 '16 at 08:44
  • Are you absolutely positive the form isn't nested and the ajax action -if any- is also executing/processing the menu? Nonetheless, your problem must be one of http://stackoverflow.com/questions/2118656/commandlink-commandbutton-ajax-backing-bean-action-listener-method-not-invoked/2120183#2120183 – BalusC Feb 11 '16 at 08:44
  • @BalusC for testing I added to the widget and now the value catches. But when submitting the form it doesn't. I have other similar widgets at the same place on the page and they work as expected. – Eddy Feb 11 '16 at 08:55
  • Just create a MCVE based on the code then. – BalusC Feb 11 '16 at 08:56
  • I guess I'm just going to use it with the f:ajax from my previous comment. – Eddy Feb 11 '16 at 12:23

1 Answers1

0
`Add`
<f:ajax listener="#{yourBean.ajaxChangeValue}" />
to h:selectOneMenu

<h:selectOneMenu value = "#{yourBean.numberValue}"> 
<f:selectItem itemValue="One" />
<f:selectItem itemValue="Two" />
<f:selectItem itemValue="Three" />
<f:ajax listener="#{yourBean.ajaxChangeValue}" />
</h:selectOneMenu>

YourBean.java
public void ajaxChangeValue(final AjaxBehaviorEvent event) {    
// do something
}

//getter and setter of numberValue
Zaw Htoon
  • 59
  • 1
  • 5
  • Why? That is a (most likely not needed) workaround for a non clear problem (and already described by the OP). So it is effectively not an 'answer') and your answer is not very good formatted. Please check and edit – Kukeltje May 18 '17 at 11:50