File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSF and the fly likes How to handle checkbox in jsf Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "How to handle checkbox in jsf" Watch "How to handle checkbox in jsf" New topic
Author

How to handle checkbox in jsf

saravana kumar
Greenhorn

Joined: May 14, 2007
Posts: 12
Hi All,
I am new to JSF framework. I have the following requirement
From the listing screen i have to select one or more record to perform delete operation thru checkbox. Can anyone tell me how to identify the selected records in jsf without using javascript...
Thanks for any help.

Regards,
Saravanan
John Bartlett
Ranch Hand

Joined: Jan 25, 2006
Posts: 116
Hi,

You will need to be more specific, where are you storing these records? In a datatable?

John
saravana kumar
Greenhorn

Joined: May 14, 2007
Posts: 12
Hi,
Please loot at the sample code in jsf

<h:dataTable var="adminList" id="mytable" value="#{messageList}" border="1" style="background-color:silver">

<h:column>
<f:facet name="header">
<hutputText value="Select All"/>
</f:facet>
<h:selectBooleanCheckbox value="{adminList.selected}"/>
</h:column>

<h:column>
<f:facet name="header">
<hutputText value="User Id"/>
</f:facet>
<h:commandLink action="#{userManager.editAdmin}" >
<hutputText value="#{adminList.userId}"/>
</h:commandLink>
</h:column>

<h:column>
<f:facet name="header">
<hutputText value="User Name"/>
</f:facet>
<hutputText value="#{adminList.userName}"/>
</h:column>

<h:column>
<f:facet name="header">
<hutputText value="Phone Number"/>
</f:facet>
<hutputText value="#{adminList.phoneNumber}"/>
</h:column>

<h:column>
<f:facet name="header">
<hutputText value="Email Id"/>
</f:facet>
<hutputText value="#{adminList.emailAddress}"/>
</h:column>

<h:column>
<f:facet name="header">
<hutputText value="Role"/>
</f:facet>
<hutputText value="#{adminList.role}"/>
</h:column>

</h:dataTable>

Regards
Saravanan
John Bartlett
Ranch Hand

Joined: Jan 25, 2006
Posts: 116
To get this to work i normally bind the data table into my bean and then access the row via the getRowIndex() on that bound in table. e.g.

Add this attribute (and appropriate getter/setter methods) to your bean


then add this to your datatable declaration in the xhtml -



now that you have the component bound into your bean, in you action method where you are deleting. you can just do this



Now you have the selected message to delete....

Is this close to what you want to do?
[ June 07, 2007: Message edited by: John Bartlett ]
saravana kumar
Greenhorn

Joined: May 14, 2007
Posts: 12
Hi,
Ya this is what i was expecting.
Thank you.

Regards,
Saravanan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to handle checkbox in jsf