This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes JSF and the fly likes Implementing p:rating in a datatable column and passing the selected row id to the managed bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Implementing p:rating in a datatable column and passing the selected row id to the managed bean" Watch "Implementing p:rating in a datatable column and passing the selected row id to the managed bean" New topic
Author

Implementing p:rating in a datatable column and passing the selected row id to the managed bean

Junliang Lim
Greenhorn

Joined: Sep 22, 2012
Posts: 2
Hi, I would like to find out how can I implement a p:rating in a datatable column?
I am puzzled with passing the id of that particular object in a list to the managedbean.

<h:form>
<p:dataTable paginator ="true" paginatorAlwaysVisible="false" rows="10" first="0" paginatorPosition="bottom"
id="inbox" tableStyleClass="table table-stripped" var="message"
value="#{messagesManagedBean.allMessages}">

<p:column id="favColumn" headerText="Bookmark" sortBy="#{message.favorite}">
<p:rating value="#{messagesManagedBean.saveStar}" stars="1" styleClass="pull-left">
<p:ajax event="rate" listener="#{messagesManagedBean.onrate}" update="favColumn" />
<p:ajax event="cancel" listener="#{messagesManagedBean.oncancel}" update="favColumn" />
</p:rating>
</p:column>

</p:dataTable>
</h:form>
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15661
    
  15

I'm not familiar specifically with the IceFaces rating control, but the standard JSF paradigm is quite simple:

1. Use a DataModel instance for the dataTable's "value=" backing property (NOT a List, array or other POJO collection object - use the DataModel as a wrapper).
2. in the "onrate" listener, use the datamodel's "getRowData()" or "getRowIndex()" to determine which row is being updated.

I have no idea how "cancel" should work here, though. Or why one would be needed. Most controls of this nature are such that to "cancel" them, you'd either just re-click back to the original value or you'd use the "reset" control to restore the value(s) as of the (partial) page load.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Implementing p:rating in a datatable column and passing the selected row id to the managed bean
 
Similar Threads
Ajax listener is not called when dragged
DataTable and UploadFile
Unable to populate values obtained from ajax call using PrimeFaces
Can't set invisible border for Table inside P:dataTable.
Datatable with column checkbox - Row Select