0

I am pretty new to JSF and was trying to the following

I have a p:selectCheckboxMenu which have the list of employees and one among them will be made their leader. So I was trying to create a p:selectCheckBoxMenu which will give me the list. The selected names will be stored in a list and a p:selectOneMenu will be updated, which will again present those selected names and one among them will be selected(from p:selectOneMenu). Basically from p:selectcheckbox we can select many names. and p:selectonemenu we will select one among those selected.

My Code :

<p:outputLabel for="teamMemb" value="Select Team Members"></p:outputLabel>
<p:selectCheckboxMenu id="teamMemb" value="#{teamMaintainanceController.teamMemb}">
    <p:ajax update="teamLeader"></p:ajax>
    <f:selectItems value="#{employeeMaintainanceController.possibleManagerList}"></f:selectItems>
</p:selectCheckboxMenu>

<p:outputLabel for="teamLeader" value="Select Team Leader"></p:outputLabel>
<p:selectOneMenu id="teamLeader" value="#{teamMaintainanceController.teamLeader}">
    <f:selectItem itemLabel="Select One" itemValue="" />
    <f:selectItems itemLabel="#{teamMaintainanceController.teamMemb}" itemValue="#{teamMaintainanceController.teamMemb}" value="#{teamMaintainanceController.teamMemb}"/>
</p:selectOneMenu>

<p:commandButton id="applyBtn" value="Add" ajax="false" actionListener="#{teamMaintainanceController.addTeam}"/>

Everything is enclosed in a form. Now the problem is, When I select the values from p:selectCheckboxMenu the p:selectOneMenu gets updated and shows the list of people that were selected earlier, but when I select one of them and click on the button, it shows validation error and console shows that value is required. I checked and the null value is going when we click on button.

I don't really get why. Please help

P.S : I am using @conversationScoped

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Ayush choubey
  • 606
  • 6
  • 23
  • 1
    You should check usage vor selectItems. http://stackoverflow.com/questions/2434902/how-to-dynamically-create-a-fselectitem-list – sgpalit Mar 16 '15 at 13:49
  • Where did you learn to use `itemLabel` and `itemValue` that way? – BalusC Mar 16 '15 at 15:25
  • Well I was trying out many things. Generally, I am using ItemLabel for Name kind of things and itemValue for id ind of things. In this case, I was frustrated and trying out random things before posting here. In my previous attempt, I was using just values, but it didn't work. So, i tried with labels. I get the feeling that it's wrong. – Ayush choubey Mar 16 '15 at 15:28
  • It introduces a red herring in the question. In any case, what validation error exactly did you got? Error messages are usually quite searchable. Is it [Validation error: Value is not valid](http://stackoverflow.com/questions/9069379/validation-error-value-is-not-valid/9069660#9069660)? – BalusC Mar 16 '15 at 15:34
  • Yes, that is the exact error. I followed the link, and read about the solutions. but couldn't understand it. I am not using any converter so that rules it out. I have conversation scope right now. Now for this, "Also perform the business logic in bean's PostConstruct instead of getter.", how can i do this. I mean teamMaintainanceController.teamMemb which is a list will store all the checked values(using setters) and then update the selectonemenu. How will I store that teamMemb list in @postconstruct – Ayush choubey Mar 17 '15 at 02:33
  • @BalusC : I would really like your help here. The items of selectOneMenu is prepared by the items that are checked in selectCheckboxMenu. I really don't have any idea. Can you please help? :) – Ayush choubey Mar 17 '15 at 10:25

0 Answers0