I'm trying to make use of the Star Rating component from PrimeFaces. However, it does not allow you to pass in parameters. That makes it impossible for me to do a lookup to get the entity from the database that I'd like to rate. I've tried something like this, but with no success:
<p:rating value="#{myAction.rating}">
<f:param name="myObjID" value="#{myObj.id}" />
</p:rating>
Is there another way that I can pass the parameter into my action class? Is there something I'm missing that would allow me to get the behavior I want? Thanks for your help!
I finally figured out how to do this...
<h:form>
<p:rating value="#{myAction.rating}" />
<input type="hidden" name="selectedObj" value="#{myObj.id}" />
</h:form>
Then, in my action class, I'm able to get the value for selectedObj by doing this...
String selectedObjID = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("selectedObj");
Piece of cake!
I solved it as follows:
<h:form>
<p:rating id="rate" value="#{userHomeControllerBean.rating}">
<f:param name="contentId" value="#{sharedcontent.content.id}" />
<p:ajax event="rate" listener="#{userHomeControllerBean.onrate}" update="rate" />
<p:ajax event="cancel" listener="#{userHomeControllerBean.oncancel}" update="rate" />
</p:rating>
</h:form>
In my backing bean, I'm able to get the value for contentId
as follows:
Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
int contentId = Integer.parseInt(params.get("contentId"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With