Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Junliang Lim
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18218
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic