3

I have a problem to ajax update an ui:repeat. The update is triggered from a commandButton outside the ui:repeat (see the code below). The variable priceHour is required to calculate the other prices (week, Monat..)

<h:form id="myForm">
<ui:repeat id="alvs" var="alv" value="#{myBean.allV}" >  
    <h:panelGroup rendered="#{alv.status == 'ON'}" > 
    <div class="pricing">

        <h:outputText styleClass="bold" value="#{alv.shortName}: "/>

        <p:inputText value="#{alv.priceHour}" id="hour" required="true" >                 
        <f:convertNumber pattern="#.##" type="currency" />  
        </p:inputText>   

        <p:inputText value="#{alv.priceDay}" id="day" >                
        <f:convertNumber pattern="#.##" type="currency" />
        </p:inputText>

        <p:inputText value="#{alv.priceWeek}" id="week" >                 
        <f:convertNumber pattern="#.##" type="currency" /> 
        </p:inputText> 

        <p:inputText value="#{alv.priceMonth}" id="month" >                   
        <f:convertNumber pattern="#.##" type="currency" /> 
        </p:inputText>  

    </div>
    </h:panelGroup>

    <p:messages />  

    </ui:repeat>

<p:commandButton value="Calculator" actionListener="#{myBean.priceCalc}" process="@this,alvs:hour" update="alvs" /> 

</h:form >

When I click the button nothing happens and the ui:repeat and the prices are not updated. What is wrong?
I tried also update"myForm:alvs", update":myForm:alvs": nothing!
I'm using primefaces 3.5
Thanks in advance

codyLine
  • 509
  • 2
  • 8
  • 26

3 Answers3

16

ui:repeat is not a rendered component, so you won't see anything in HTML about it. You can't update something that is not rendered. Also the ui:repeat doesn't even have an id attribute.

You need to wrap your ui:repeat inside a component such as h:panelGroup for example like this :

<h:panelGroup id="alvs">
    <ui:repeat ...>
    </ui:repeat>
</h:panelGroup>

And update the panelgroup in your button :

<p:commandButton value="Calculator" actionListener="#{myBean.priceCalc}" process="@this,alvs" update="alvs" />

Notice that I've removed the :hour since you can't spectify it, each IDs will be different for each repeat.

More info :

Alexandre Lavoie
  • 8,711
  • 3
  • 31
  • 72
2

I had the same problem. The proposed answers didn't work for me: the ui:repeat doesn't want to be updated by ajax, whatever I do. I used PrimeFaces data list instead and it worked like a charm.

http://www.primefaces.org/showcase/ui/data/dataList.xhtml

Zhenya
  • 6,020
  • 6
  • 34
  • 42
0

I'm afraid I don't know the reason for it to not work, I hate when that kind of stuff happens to me working with JSF. As I workaround, you can try surrounding the ui:repeat with a p:outputPanel and then update that panel.

MaQy
  • 478
  • 3
  • 10
  • A `p:outputPanel` is a bit overkill since it will output bunch of HTML/CSS. – Alexandre Lavoie Jun 20 '13 at 22:37
  • I can't `process` the `priceHour` component any more! I tried `@this`, `@this,myForm:panel:alvs:hour`, `@this,panel:alvs:hour` and `@this,alvs:hour` nothing! – codyLine Jun 20 '13 at 22:50