tags:

views:

26

answers:

1

Hi!
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 this.getSelectOne().getValue() is null.

Any idea?? Thanks in advance

+2  A: 

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).

BalusC
Thanks for your answer.My problem was that I must include everything in a form tag.Thanks
mujer esponja