开发者

selectOneMenu with selectItems

I am trying to make a filter using selectOneMenu.

I have two categories, when one is selectect, must filter the results shown, and also the second category.

JSF code:

<div id="box-categories" class="box-left">
            <b>Filter by topic</b>
            <h:selectOneMenu id="cat1" binding="#{interfaceContainer.documentFormContainer.selectOnes['cat1'].selectOne}" rendered="true"  onchange="javascript:refreshResults(); return false;">
                                        <f:selectItems value="#{interfaceContainer.documentFormContainer.selectOnes['cat1'].items}" />
                                </h:selectOneMenu>
            <b>and subtopic</b>
 <h:selectOneMenu id="cat2" binding="#{interfaceContainer.documentFormContainer.selectOnes['cat2'].selectOne}" rendered="true"  onchange="javascript:refreshResults(); return false;" value="#{interfaceContainer.documentFormContainer.selectOnes['cat2'].value}">
                                        <f:selectItems value="#{interfaceContainer.documentFormContainer.selectOnes['cat2'].items}" />
                                </h:selectOneMenu>
        </div>  

But I have problems when I try to get the values using this java code:

public String getStringValue(){
      if ( this.selectOne ==null || this.getSelectOne().getValue()==null)
          return "";
      return this.getSelectOne().getValue().toString();
  }

I realised that the problem is just with getValue(), because debugging, this.getSelectOne() is in the rigth value, but th开发者_运维百科is.getSelectOne().getValue() is null.

Any idea?? Thanks in advance


UIInput#getValue() will return null when you attempt to access it during any phase before the Update Model Values phase. You're apparently accessing it at the "wrong" moment in the JSF lifecycle. Anyway, creating dependent dropdown menus in JSF without help of a shot of Ajax is terrible.

Long story short, here's how to do it: Populate child menu's (with complete and working code examples).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜