0

I would like to get two values from a p:selectOneMenu.

Here the code:

        <p:selectOneMenu 
        id="ip1" value="#{loginBean.f_selectedProject}" rendered="#{loginBean.f_prjType == 'project'}">
            <f:selectItem itemLabel="Select One" itemValue="dummy"/>
            <f:selectItems value="#{loginBean.f_prjListComplete}" var="prj" itemLabel="#{prj.projectDesc}" itemValue="#{prj.projectCd}"/>
        </p:selectOneMenu>

I need to get prj.projectCd and prj.projectDesc values.

Thanks, Giuseppe

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • BalusC the question is different. – Giuseppe Franzese Jul 21 '17 at 10:33
  • When you select an item from f_prjListComplete, selected item is stored in f_selectedItem in your LoginBean. You should access to its properties using f_selectedItem.getProjectCd() and f_selectedItem.getProjectDesc() if you defined getters properly. Exactly same as marked reference to duplicated item. – stakahop Jul 21 '17 at 11:45
  • But the value is written to the variable "f_selectedProject", right? So, how I can write two values into two different variables? – Giuseppe Franzese Jul 21 '17 at 13:10
  • Make one inside . That method will be invoked every time when you select item. In that method you can do everything you want with f_selectedItem. Make two variables and set f_selectedItem.getProjectCd() and f_selectedItem.getProjectDesc() to them if that is what you want. Hope that helps.. – stakahop Jul 21 '17 at 13:16
  • Ok, i understood. I try. Thanks a lot :) – Giuseppe Franzese Jul 21 '17 at 14:28
  • 1
    Why don't you save whole `Project` object to a backing bean? – peterremec Jul 24 '17 at 13:25
  • 1
    @peterremec you are right. I did not see itemValue="#{prj.projectCd}"/> part. – stakahop Jul 26 '17 at 20:58

0 Answers0