Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to display values from "selectManyCheckbox" after form submit?

 
kevin redd
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following simple "selectManyCheckbox" specified in my jsf page:-

<h:selectManyCheckbox id="animalsmc" layout="pageDirection" value="#{animalSelectionBean.selectedAnimals}">
<f:selectItem itemValue="1" itemLabel="Lion"/>
<f:selectItem itemValue="2" itemLabel="Tiger"/>
<f:selectItem itemValue="3" itemLabel="Elephant"/>
<f:selectItem itemValue="4" itemLabel="Eagle"/>
<f:selectItem itemValue="5" itemLabel="kangaroo"/>
</h:selectManyCheckbox>


I have the following specified in my bean class:-

private int [] selectedAnimals;
...
public int[] getSelectedAnimals() {
return selectedAnimals;
}

public void setSelectedAnimals(int[] selectedAnimals) {
this.selectedAnimals = selectedAnimals;
}


I would like to know how to display the values of selected checkboxes on the JSF page after submitting the form? I tried outputtext, however it displays the object and not the values. I cannot even frame the outputformat for the same.

Thanks in advance.
 
Tim Holloway
Bartender
Posts: 18419
60
Android Eclipse IDE Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand what you mean by "display values". JSF will automatically select the indicated items in a selectManyCheckbox as determined by what's returned from the "getSelectedAnimals" method.

If you want the selections to display in some other format, you need to determine what that format should be and create a suitable sub-view template.
 
kevin redd
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim,

Thanks for the reply.

For example if I select 1(Lion), 3(Elephant) check boxes and then if I click on submit.

On the webpage(where the submit will take me to, For example on the same page), then I would like to know how to display Lion and Elephant on the webpage.

PutputText and OutputFormat does not meet this requirement.

Is there any other Tag in core JSF which would get the values(Array or Collection) from the object returned from getSelectedAnimals() and print them on the web page?

May be I am missing something as I am pretty novice to JSF, and have just started my learning journey a couple of days ago.

Thanks in Advance.

Regards,
Kevin.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!