p:rating does not respect prependId=false

UI Components for JSF
Post Reply
jvpoucke
Posts: 4
Joined: 16 Oct 2009, 17:58

16 Oct 2009, 18:08

This discussion starts from issue http://code.google.com/p/primefaces/iss ... ail?id=258

When <p:rating> is nested inside a form, you cannot update a referenced
component:
Example code:

Code: Select all

<h:form id="form" prependId="false">
    <!-- p:rating works here -->
    <!--h:outputText id="globalRating" value="#{entry.rating}" /-->
     <ui:repeat value="#{entries}" var="entry">
         <div id="entry">
             <div id="test">
                 <p:rating id="rating" value="#{entry.rating}" 
                                rateListener="#{ratingmanager.handleRating}" 
                                update="globalRating"
                                stars="5" />
                 <!-- p:rating does NOT respect prependId -->
                 <!--h:outputText id="globalRating" value="#{entry.rating}" /-->
             </div>
        </div>
    </ui:repeat>
</h:form>
Maybe I am missing something, but how do I add multiple
star rating components, one for each entry?

I have tried c:forEach instead of ui:repeat, but that does not work, which is logical.
For background, see http://www.ilikespam.com/blog/c:foreach ... n-facelets

Switching order of <h:form> and <ui:repeat> does not work either.

Looking at the HTML source code, the <h:outputText> gets a wrong id.

Anybody an idea to solve this?

Thanks,
Jonas

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

16 Oct 2009, 21:11

Jonas can I ask why do you have <!-- --> for output text?

User avatar
ydarcin
Posts: 258
Joined: 04 Jan 2009, 19:02
Location: Turkey

16 Oct 2009, 21:37

Hi,

your code also seems buggy as the first globalRating ( the one outside the ui:repeat ):

<!--h:outputText id="globalRating" value="#{entry.rating}" /-->

has illegal value as entry.rating. because your define rating inside the ui:repeat. You cannot access "entry" outside the ui:repeat.

User avatar
ydarcin
Posts: 258
Joined: 04 Jan 2009, 19:02
Location: Turkey

16 Oct 2009, 21:56

Hi,

and also with the correct code, the globalRating span is actually working ;)

Yigit

jvpoucke
Posts: 4
Joined: 16 Oct 2009, 17:58

20 Oct 2009, 11:43

Hi,

Thanks for looking at my issue. Could you please post the working code?

For me, it still does not work. Sure, the first <h:outputText> is ok and works, but my problem is the second one.

I found someone else having the same problem:
http://ocpsoft.com/java/undocumented-jsf/#comment-203
and
https://javaserverfaces.dev.java.net/is ... cgi?id=994

Jonas

User avatar
ydarcin
Posts: 258
Joined: 04 Jan 2009, 19:02
Location: Turkey

20 Oct 2009, 12:53

Hi,

I used the same code,

I have just changed this : <!--h:outputText id="globalRating" value="#{entry.rating}" /-->
into this: <h:outputText id="globalRating" >

jvpoucke
Posts: 4
Joined: 16 Oct 2009, 17:58

20 Oct 2009, 17:34

Does it also work for the nested <h:outputText>, the one inside <ui:repeat>?

jvpoucke
Posts: 4
Joined: 16 Oct 2009, 17:58

29 Oct 2009, 16:41

Ok, I made it work too. So I provide the solution such that others do not have to look for it:
  • Do not use prependId="false" but use the ":" separator.
  • You then need to give each component an ID, which is not possible with ui:repeat. I used richfaces equivalent instead (http://livedemo.exadel.com/richfaces-de ... f?c=repeat).
  • Additionally, the ref needs to be computed dynamically, as a counter named by "rowKeyVar".
  • Refer to the complete hierarchy in the "update" attribute
It still makes me wonder why my first example does not work...

Sample code:

Code: Select all

<h:form id="form" prependId="false">
     <a:repeat id="entriesRepeat" value="#{entries}" var="entry" rowKeyVar="counter">
         <div id="entry">
             <div id="test">
                 <p:rating id="rating" value="#{entry.rating}"
                                rateListener="#{ratingmanager.handleRating}"
                                update="form:entriesRepeat:#{counter}:globalRating"
                                stars="5" />
                 <h:outputText id="globalRating" value="#{entry.rating}" />
             </div>
        </div>
    </a:repeat>
</h:form>

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 23 guests