Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

p:selectManyCheckbox : getting the selected value into bean  RSS feed

 
bharat sripuram
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am using primefaces, I have an p:selectManyCheckbox and i need to get the selected value into the bean.

.xhtml
<p:selectManyCheckbox id="dataPanelChkBoxs"
value="#{credentialWorkFlowBean.selectedApplicantPanelList }" >
<f:selectItems value="#{credentialWorkFlowBean.userInfoElementList}"
var="appsList" itemLabel="#{appsList.displayText}"
itemValue="#{appsList.dataPanelId}"
itemDescription="#{appsList.displayText}" ></f:selectItems>
<c:set var="appsList" value="#{appsList.displayText}" />
<f:ajax listener="#{credentialWorkFlowBean.checkBoxListenerbharat(appsList.dataPanelId)}" immediate="true" ></f:ajax>

</p:selectManyCheckbox>

.java (the bean)
public void checkBoxListenerbharat(
String dataPanelBean)
//ArrayList appList)
{

System.out.println("the value is"+dataPanelBean+"very bad");

}


Here am getting empty value. Please suggest me
 
Mohamed Sanaulla
Bartender
Posts: 3174
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Why do you need the above line? Because f:selectItems "var" attribute holds the reference to appsList. So you can remove the c:set tag. Moreover your bean doesn't have the getter/setter for credentialWorkFlowBean.selectedApplicantPanelList

Can you have a look at the sample: http://www.primefaces.org/showcase/ui/selectManyCheckbox.jsf
 
Tim Holloway
Bartender
Posts: 18662
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't "get" a value into a bean. JSF automatically transfers (injects) the value into the bean. That's what JSF is for.

JSF works on the Model/View/Contoller paradigm. In MVC, changes to the View are reflected by the Controller into the Model. Changes to the Model are reflected by the Controller into the View. In many MVC systems, you have to code your own Models, Views, and Controllers, but in JSF, the Controllers are part of JSF itself, so you only have to supply Models (backing beans) and View templates (xhtml).

You most definitely do not need a lot of complicated stuff like function calls with parameters on them in the View Template or JSTL. In fact, JSTL tends to really screw up JSF, which has its own native equivalents.

To get a selection list to set a value on a backing bean, all that's needed is something like this:



JSF will inject a collection of the selected values (an array, if I'm not mistaken) by searching for and invoking a method with this signature in credentialWorkFlowBean:


The AJAX listener method doesn't need parameters. It's supposed to reference a method, not call it. The mere fact that it was invoked should be an indication to the method that the control it works with was changed.

I'm not sure about that "immediate="true"" option, though. Normally "immediate" suppresses all data transfers and only invokes the method with the backing bean properties. I think there's an alternative option for when you only want to send the associated control's values without having AJAX send down the entire form (and reject the request if an unrelated form control has an invalid value).

Also note that you had too many options on the selectItems element. There are 2 types of selectItems. One takes the value/label pairs as a list or array of SelectItem objects from the backing bean. The other one takes separate values and labels. The two are mutually exclusive.
 
bharat sripuram
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for all for your wonderful help. It worked.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!