aspose file tools*
The moose likes JSF and the fly likes Dependent Drop- Down Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Dependent Drop- Down" Watch "Dependent Drop- Down" New topic
Author

Dependent Drop- Down

Tushar Kherde
Ranch Hand

Joined: Apr 28, 2006
Posts: 56
Dear All,

I have problem regarding Dependent Drop-Down.
For Example i have drop-down for country, as soon as i select country, drop-down for state should get populate.

Any suggestion or sample code
thanks in advance


Tushar
Richard Green
Ranch Hand

Joined: Aug 25, 2005
Posts: 536
http://www.felgall.com/jstip22.htm


MCSD, SCJP, SCWCD, SCBCD, SCJD (in progress - URLybird 1.2.1)
Sergey Smirnov
Ranch Hand

Joined: May 29, 2003
Posts: 167
It is just one line of code with Ajax4jsf.

Example:
http://livedemo.exadel.com/a4j-dropDownBoxes/

Source code:
https://ajax4jsf.dev.java.net/nonav/ajax/ajax-jsf/download.html#examples
Tushar Kherde
Ranch Hand

Joined: Apr 28, 2006
Posts: 56
Thanks for reply

I cant use javascriprt because i am populating 2nd dropdown from database and not using ajax also.
Cant we do this using plain JSF on some event, if we render the whole page again.
Andres Quinones
Ranch Hand

Joined: Oct 09, 2006
Posts: 57
Originally posted by Tushar Kherde:
Thanks for reply

I cant use javascriprt because i am populating 2nd dropdown from database and not using ajax also.
Cant we do this using plain JSF on some event, if we render the whole page again.


You can do it this way
<h:selectOneMenu valueChangeListener="#{Bean.listenerMethod}" onchange="submit()" value="#{Bean.value}">
<f:selectItems value="#{Bean.list}"/>
</h:selectOneMenu>
And in the Bean you only need to add a method like this
public void listenerMethod( ValueChangeEvent e ) throws AbortProcessingException{
Object value = e.getNewValue();
}

There you will have the value you selected in the list and you can use it to populate the other dropdown.

I hope this helps
[ February 14, 2007: Message edited by: Andres Quinones ]
Armando Ruperez
Greenhorn

Joined: Jun 30, 2009
Posts: 1
Andres Quinones wrote:
Originally posted by Tushar Kherde:
Thanks for reply

I cant use javascriprt because i am populating 2nd dropdown from database and not using ajax also.
Cant we do this using plain JSF on some event, if we render the whole page again.


You can do it this way
<h:selectOneMenu valueChangeListener="#{Bean.listenerMethod}" onchange="submit()" value="#{Bean.value}">
<f:selectItems value="#{Bean.list}"/>
</h:selectOneMenu>
And in the Bean you only need to add a method like this
public void listenerMethod( ValueChangeEvent e ) throws AbortProcessingException{
Object value = e.getNewValue();
}

There you will have the value you selected in the list and you can use it to populate the other dropdown.

I hope this helps
[ February 14, 2007: Message edited by: Andres Quinones ]



I'm trying to follow this suggestion but, it doesn´t seem to work, throws a null pointer exception unless y put the rendered="#{GlobalData.selectClient!=null}" option in the second selectOneListbox, and if that is the case, after the selection of the first listbox is made, the second one never shows up.

Is something im missing?, perhaps someone can help me.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dependent Drop- Down