Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

How to add instances of SelectItem as Argument to method

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The following code in Add Role method results in error
public String addRole() {
deviceRoles.addAll(selectedUserRoles);
return null;
}

ERROR:
javax.faces.FacesException: Collection referenced by UISelectItems with binding

'#{test.deviceRoles}' and Component-Path : {Component-Path : [Class:

org.ajax4jsf.framework.ajax.AjaxViewRoot,ViewId: /page.jsp][Class:

javax.faces.component.html.HtmlForm,Id: _id0][Class:

org.ajax4jsf.ajax.html.HtmlAjaxOutputPanel,Id: _id6][Class:

javax.faces.component.html.HtmlPanelGrid,Id: _id13][Class:

javax.faces.component.html.HtmlSelectManyListbox,Id: _id19][Class:

javax.faces.component.UISelectItems,Id: _id20]} <b>does not contain Objects of type

SelectItem
</b>


I fixed the error by hardcoding the values into Add Role method as shown below

public String addRole() {

deviceRoles.add(new SelectItem("10"," Admin"));
deviceRoles.add(new SelectItem("20"," Focal"));
deviceRoles.add(new SelectItem("30","Architect"));

return null;
}

So I guess the call to "selectedUserRoles" in deviceRoles.addAll(selectedUserRoles); should

return instances of SelectItem with Id and Value as arguments.

That means whenever users selects multiple values from user roles h:selectManyList box, the setselectedUserRoles() method should recieve both Id and Value as instance of Select Item.

Hence i changed the declaration to
private List selectedUserRoles = new ArrayList<SelectItem>();

But not sure how to change the defination of setselectedUserRoles() method to recieve instances of SelectItem with Id and Value as Arguments. Here is the defination

public void setSelectedUserRoles(List selectedUserRoles) {
this.selectedUserRoles = selectedUserRoles;
System.out.println("Setter this.selectedUserRoles "+ this.selectedUserRoles);}




Any pointers/suggestions will be highly appreciated in this regard.
Here is the code snippet in backing bean :

--------------------------------
TestBean.java (Backing Bean)
------------------------------------
private List<Role> userRoles;
private List deviceRoles = new ArrayList<SelectItem>();
private List selectedUserRoles = new ArrayList<SelectItem>();
private List selectedDeviceRoles = new ArrayList<SelectItem>();


public List getSelectedUserRoles() {
System.out.println("Getter this.selectedUserRoles"+selectedUserRoles);
return selectedUserRoles;
}



public void setSelectedUserRoles(List selectedUserRoles) {
this.selectedUserRoles = selectedUserRoles;
System.out.println("Setter this.selectedUserRoles "+ this.selectedUserRoles);}


public String addRole() {
deviceRoles.addAll(selectedUserRoles);
return null;
}

Regards
Bansi
 
My cellmate was this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic