Win a copy of Kotlin in Action this week in the Kotlin 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  RSS feed

Junliang Lim
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.

<p:dataTable paginator ="true" paginatorAlwaysVisible="false" rows="10" first="0" paginatorPosition="bottom"
id="inbox" tableStyleClass="table table-stripped" var="message"

<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" />

Tim Holloway
Posts: 18709
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.
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!