Note that there are some explanatory texts on larger screens.

plurals
  1. POJSF SelectOneMenu selected item
    primarykey
    data
    text
    <p>I can't get the selected item from a SelectOneMenu. I supply an ArrayList to the menu and want the user to select one of it. I put the menu into a form, so I have a commandButton which I intended to use to perform the selection. This implementation gives me this error : Cannot convert user3 of type class java.lang.String to class java.util.ArrayList when I select from the menu "user3", so it actually performs the selection correctly. The error refers to this line</p> <pre><code>&lt;h:selectOneMenu value="#{user.myUsers}" </code></pre> <p>Here is the part of my xhtml which generates the selectOneMenu.</p> <pre><code> &lt;h:panelGrid columns="3"&gt; &lt;h:form&gt; &lt;h:selectOneMenu value="#{user.myUsers}"&gt; &lt;f:selectItems value="#{user.myUsers }"/&gt; &lt;/h:selectOneMenu&gt; &lt;h:commandButton value="#{msgs.remove_user}" action="#{user.select }" &gt;&lt;/h:commandButton&gt; &lt;/h:form&gt; &lt;h:outputText value="#{ user.select}"&gt;&lt;/h:outputText&gt; &lt;/h:panelGrid&gt; </code></pre> <p>And here is my UserBean:</p> <pre><code> @ManagedBean(name="user") @SessionScoped public class UserBean implements Serializable { private String selected; public ArrayList&lt;String&gt; getMyUsers()throws Exception { ArrayList&lt;String&gt; ret; MySQLConnection conn = new MySQLConnection(); try{ ret = conn.getMyUsers(name); }finally { conn.closeConnection(); } return ret; } public String getSelect() throws Exception { if (this.selected==null) return this.getMyUsers().get(0); return this.selected; } public void setSelect(String s) { this.selected = s; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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