In JSF - What is the correct way to do this? Two dropdown lists with dependency.

Posted by Ben on Stack Overflow See other posts from Stack Overflow or by Ben
Published on 2010-03-25T08:33:09Z Indexed on 2010/03/25 9:23 UTC
Read the original article Hit count: 296

Filed under:
|

Hi,

I'm making two dropdown lists in JSF which are dependent. Specifically, one list has all the languages and the second list contains values that are displayed in the currently selected language.

I've implemented this by having the second list use information from a Hash and rebuilding that Hash in the setter of the currently selected language.

JSF Code Bit:

<rich:dropDownMenu value="#{bean.currentlySelectedLanguage}" id="languageSelector">
 ... (binding to languages hash) ...
<rich:dropDownMenu value="#{bean.currentlySelectedScript}" id="ScriptPullDown">
 ... (binding to scripts hash) ...

Backing Bean Code Bit:

setCurrentlySelectedLanguage(String lang){
this.currentlySelectedLanguage = lang;
rebuildScriptNames(lang);
}

I'm wondering if that's a good way of doing this or if theres a better method that I am not aware of.

Thank you!

EDIT - Adding info.. I used a a4j:support that with event="onchange" and ReRender="ScriptPullDown" to rerender the script pull down. I could probably add an action expression to run a method when the value changes. But is there a benefit to doing this over using code in the setter function?

© Stack Overflow or respective owner

Related posts about best-practices

Related posts about jsf