Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Since you are using <code>@RequestScoped</code> bean as your backing bean after each request your <code>init</code> method is getting called and your values are getting reset. To avoid that you need to use <code>@ViewScoped</code> bean as your backing bean. I updated your bean accordingly note that your backing bean now implements <code>Serializable</code> interface. This is needed as this bean will be stored in your servlet and it needs to be flushed to disk if the content can not be hold in the memory. For learning the details of <code>@ViewScoped</code> beans please check the following post:</p> <blockquote> <p><a href="http://balusc.blogspot.com/2010/06/benefits-and-pitfalls-of-viewscoped.html" rel="nofollow">http://balusc.blogspot.com/2010/06/benefits-and-pitfalls-of-viewscoped.html</a></p> </blockquote> <p>Apart from these, for naming conventions I renamed your <code>getAllLanguages</code> and <code>getSerialIDsFromOverview</code> methods to <code>initAllLanguages</code> and <code>initSerialIds</code> as methods starting with get and set can be confusing because they are mostly used for getters and setters. </p> <p>Lastly when you use <code>f:ajax</code> command by default the <code>UIInput</code> the ajax command is bind to is rendered and executed. Since you don't refresh the <code>h:selectOneMenu</code> menus according to the values of each other you don't need to render the whole form. The following will be enough for this case: </p> <pre><code>&lt;h:form id="myForm"&gt; &lt;h:panelGrid columns="4"&gt; &lt;h:outputLabel value="Language:" /&gt; &lt;h:selectOneMenu value="#{myBean.language}"&gt; &lt;f:selectItems value="#{myBean.languages}" /&gt; &lt;f:ajax listener="#{myBean.doUpdate}"/&gt; &lt;/h:selectOneMenu&gt; &lt;h:outputLabel value="SerialID:" /&gt; &lt;h:selectOneMenu value="#{myBean.serialID}"&gt; &lt;f:selectItems value="#{myBean.serialIDs}" /&gt; &lt;f:ajax listener="#{myBean.doUpdate}"/&gt; &lt;/h:selectOneMenu&gt; &lt;/h:panelGrid&gt; &lt;/h:form&gt; @ManagedBean @ViewScoped public class MyBean implements Serializable { public static final int PERMISSIONS = 2; private List&lt;String&gt; languages; private String language; private int serialID; private List&lt;Integer&gt; serialIDs; /** * init() method for initializing the bean. Is called after constuction. */ @PostConstruct protected void init() { //public MyBean () { System.out.println("lang: " + language); System.out.println("serialId: " + serialID); System.out.println("init is called"); initAllLanguages(); initSerialIds(); language = "en"; //defaultLanguage serialID = 3; } public List&lt;String&gt; getLanguages() { return languages; } public int getPERMISSIONS() { return PERMISSIONS; } public String getLanguage() { return language; } public void setLanguage(String language) { this.language = language; } public int getSerialID() { return serialID; } public void setSerialID(int serialID) { this.serialID = serialID; } public List&lt;Integer&gt; getSerialIDs() { return serialIDs; } private void initAllLanguages() { languages = new ArrayList&lt;String&gt;(); languages.add("sp"); languages.add("en"); } public void doUpdate() { System.out.println("doUpdate language " + language); System.out.println("doUpdate serialID " + serialID); } /** * Returns a list of all serialIDs present in the overview. * * @return */ private void initSerialIds() { serialIDs = new ArrayList&lt;Integer&gt;(); serialIDs.add(0); serialIDs.add(1); serialIDs.add(2); serialIDs.add(3); } } </code></pre> <p>Cheers</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload