Set selected for <p:selectOneMenu>

UI Components for JSF
Post Reply
loright
Posts: 42
Joined: 10 Aug 2011, 09:55

22 Dec 2011, 15:56

Hello, i need to set selected item in <p:selectOneMenu>, i try this:

Code: Select all

<p:selectOneMenu value="#{networkBean.selectedLinkTypes}" converter="linkType" >
                    <f:selectItems value="#{networkBean.linkTypesList}" var="linkType" itemLabel="#{linkType.name}" itemValue="#{linkType}"/>
                </p:selectOneMenu> 

Code: Select all

 @SessionScoped
@ManagedBean(name = "networkBean")

public class NetworkBean implements Serializable
{
    private List<LinkType> linkTypesList=new ArrayList<LinkType>();
    private LinkType selectedLinkTypes;
    //getters & setters

public void listener()
    {
        System.out.println("listener() work")
        setSelectedLinkTypes(selectedNetwork.getLinkType());
    }
} 
I try to connect listener() as actionListener for button, but has occurred nothing. Listener() works, but selection not work.
Primefaces 3.4 + JBoss 6.1. Final

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

22 Dec 2011, 18:41

In your bean constructor, default or assign value to the following bean attribute (selectedLinkTypes), and then you will see when the page is first rendered or displayed in browser, then p:selectOneMenu will have a selected value.

Code: Select all

value="#{networkBean.selectedLinkTypes}"
Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

loright
Posts: 42
Joined: 10 Aug 2011, 09:55

23 Dec 2011, 13:46

Sorry, but i don't understand you. I try to call setter of selectedLinkType and it works. But when i call it in body of other function, it doesn't work.
Primefaces 3.4 + JBoss 6.1. Final

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

23 Dec 2011, 15:33

1. Are you new to Java and JSF development? Please review the following:

Creating a Simple JavaServer Faces Application (Hello World sample shows how "Hello World" is defaulted in the constructor)
http://docs.oracle.com/javaee/6/tutorial/doc/gjaam.html

2. Please see code samples at the following URLs that might help you.

http://balusc.blogspot.com/search/label ... esults=100

http://balusc.blogspot.com/2010/06/bene ... tDataModel

3. See my signature below and let us know your test/development environment as I did in my signature. It makes it easier to answer questions when this information is provided.
Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: Google [Bot] and 33 guests