开发者

jsf h:selectonemenu problem

I am developing a jsf,richfaces application.where i want to populate the values of second select menu on the basis of selecting the choice from the first one .i have achieved this like: first menu:

second menu:

  <h:outputText id="section1" value="Section" />
    <h:selectOneMenu  id="section2" value="#{content.sectionname}" >
        <f:selectItems  value="#{content.sections}" />
  </h:selectOneMenu>

what exactly i want is: I have two tables one for category and one for section. If a user choose a category from drop down menu then the other drop down menu for section should have the values only for selected category.Upto this i got the desired result but at the time of submitting the form i am getting the following error:

exception

javax.servlet.ServletException
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:256)
    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.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)

root cause

java.util.NoSuchElementException
    javax.faces.component.SelectItemsIterator.next(SelectItemsIterator.java:117)
    javax.faces.component.SelectItemsIterator.next(SelectItemsIterator.java:144)
    javax.faces.component.SelectItemsIterator.next(SelectItemsIterator.java:49)
    javax.faces.component.UISelectOne.matchValue(UISelectOne.java:164)
    javax.faces.component.UISelectOne.validateValue(UISelectOne.java:137)
    javax.faces.component.UIInput.validate(UIInput.java:867)
    javax.faces.component.UIInput.executeValidate(UIInput.java:1065)
    javax.faces.component.UIInput.processValidators(UIInput.java:666)
    javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1033)
    javax.faces.component.UIComponentBase.processValidators(UIComponentBase开发者_运维知识库.java:1033)
    javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1033)
    org.richfaces.component.UISwitchablePanel.processValidators(UISwitchablePanel.java:218)
    javax.faces.component.UIForm.processValidators(UIForm.java:229)
    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:100)
    com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
    com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
    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.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)

Can anyone please tell me what is the cause of this exception and how i can resolve this. Please help.


You will get this exception when the collection behind <f:selectItems> value is not present anymore at the moment the form submit is been processed. Your managed bean is clearly been placed in the request scope. Any bean properties will get lost by end of request and needs to be prepopulated the same way in the next request.

In JSF 1.x you need to ensure that the very same collection is been prepared in the bean's constructor or postconstruct. An alternative is to put the bean in session scope. But since the stacktrace hints that you're using Ajax4jsf, you can also use the <a4j:keepAlive>.

<a4j:keepAlive beanName="#{content}" />

In JSF 2.x it's easier, just put the bean in the view scope.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜