Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing parameters to PrimeFaces Star Rating component?

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!

like image 288
Shadowman Avatar asked Jan 27 '11 19:01

Shadowman


2 Answers

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!

like image 108
Shadowman Avatar answered Nov 09 '22 13:11

Shadowman


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"));
like image 42
Shafeek v Avatar answered Nov 09 '22 14:11

Shafeek v