views:

1366

answers:

4

Hey,

I want to change the SelectItem[] array in the second SelectOneMenu, if the value is changed in the first one. Is that possible?

Thanks in advance!

+1  A: 

Should be possible if you bind a value change listener to the first selectOneMenu.

Get the new value from the ValueChangeEvent and update the list accordingly. the JSF page should then display the updated list.

Hope that makes sense!

Phill Sacre
I'll try it. Thanks!
wheelie
It seems that the ValueChangeEvent gets invoked only if i submit the page :\
wheelie
I also have richFaces in my project, so I guess i should use some AJAX functionality here?
wheelie
+1  A: 

I figured this out, but I used RichFaces's AJAX functionality, not only JSF. Just added the tag to my first selectOneMenu, and it works:)

<a4j:support event="onchange" action="#{bean.onChange}" reRender="otherSelectOneMenuID"/>

Thanks for the response anyway!

wheelie
Glad that you got it working. RichFaces does make it easier to do things than standard JSF!
Phill Sacre
A: 

I have tried the Richfaces a4j:support, as suggested by wheelie. The second selectOneMenu is updated correctly, but when submitting the form, a NoSuchElementException is trhown. As if JSF is not aware of the updated values in the 2nd selectOneMenu. How to fix this?

java.util.NoSuchElementException
    javax.faces.component.SelectItemsIterator.next(SelectItemsIterator.java:130)
    javax.faces.component.SelectItemsIterator.next(SelectItemsIterator.java:154)
    javax.faces.component.SelectItemsIterator.next(SelectItemsIterator.java:61)
    javax.faces.component.SelectUtils.matchValue(SelectUtils.java:82)
    javax.faces.component.UISelectOne.validateValue(UISelectOne.java:144)
    javax.faces.component.UIInput.validate(UIInput.java:875)
    javax.faces.component.UIInput.executeValidate(UIInput.java:1072)
    javax.faces.component.UIInput.processValidators(UIInput.java:672)
    javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1058)
    javax.faces.component.UIForm.processValidators(UIForm.java:235)
    javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1058)
    org.ajax4jsf.component.AjaxViewRoot$3.invokeContextCallback(AjaxViewRoot.java:442)
    org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:235)
    org.ajax4jsf.component.AjaxViewRoot.processValidators(AjaxViewRoot.java:458)
    com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
    com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
    com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
    org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
    org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
    org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
    org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
    org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75)
Jurgen H
Welcome at Stackoverflow. Please post questions as questions by pressing the `Ask Question` button at right top. Do not post questions as answers, this makes really no sense and your question will only get lost in noise.
BalusC
A: 
Didask