0

I got a ui:repeat with a few input elements with actionlisteners and i want to change the style of the elements, if they were edited by a user.

I'm aware that through the ui:repeat we have different scopes for the components on the server and client side. Therefore i wanted to get the selected loop index or the clientID of a element to call a javascript function to change the style.

This works fine for e.g my selectOneMenu, i call a method with ajax and get the right clientID. But if i try the same thing with my calendar i always get the last element / index of the ui:repeat loop and not the selected one...

My jsf:

<ui:repeat var="carservice" value="#{searchCarProject.editProjects}" varStatus="loop" id="repeat">
<p:selectOneMenu id="menu1" value="#{carservice.carProject.brand}" style="width:38px !important;">
    <f:selectItem itemLabel="" itemValue="" />
    <f:selectItems value="#{searchCarProject.carProjectBeanService.brands}" var="i" itemLabel="#{i.value} - #{i.label}" itemValue="#{i}"/>
    <p:ajax event="change" listener="#{searchCarProject.menuSelect}" update="errorGrid innerGrid " partialSubmit="true"/>
    <f:converter binding="#{mlCarProjectAttributeConverter}" />
</p:selectOneMenu>

<p:calendar id="cal1" widgetVar="deDateWidget" pattern="dd.MM.yyyy" value="#{carservice.carProject.termin_de}" mindate="#{searchCarProject.currentDate}" navigator="true">
    <p:ajax event="dateSelect" listener="#{searchCarProject.calSelect}"/>
</p:calendar>
</ui:repeat>

My server-methods:

    //for selectOneMenues
public void menuSelect(final AjaxBehaviorEvent event) {
    final String id = event.getComponent().getClientId();
    //id = selectionForm:entryActionTabs:repeat:0:menu1 <- 0 = the right selected one    
}

//for calendar
public void calSelect(final AjaxBehaviorEvent event) {
    final String id = event.getComponent().getClientId();
    //id = selectionForm:entryActionTabs:repeat:5:cal1 <- always 5 = always the last index    
}

So after the event won't give me the right value for the calendar i thought i should try it with the var attributes:

<p:calendar id="de_calendar" widgetVar="deDateWidget" pattern="dd.MM.yyyy" value="#{carservice.carProject.termin_de}" mindate="#{searchCarProject.currentDate}" navigator="true">
    <f:ajax event="dateSelect" listener="#{searchCarProject.calSelectWithAttributes(**loop.index,carservice.carProject.name**)}"/>
</p:calendar>

But i still get only the last values, if i do the same with the selectOneMenu i get the selected ones...

public void calSelectWithAttributes(final int index, final String name) {
index = always 5 = always the last index, name = obj name, is always the last one same as index
}

So i have no idea why selectOneMenu gives me the right loop.index / attribute / event but only the calendar always the last...

Edit: Even tried it with a h:dataTable, excactly the same problem...Ajaxevent returns always the last id for the calendar.

dontcare
  • 935
  • 3
  • 16
  • 34

2 Answers2

2

Delete the widgetVar="deDateWidget" in your p:calendar when you use the ui:repeat

Infinite Recursion
  • 6,511
  • 28
  • 39
  • 51
zedtimi
  • 306
  • 1
  • 6
  • 2
    Well spotted. Answer would be nicer if you replace "try" by an explanation. – BalusC Jul 16 '15 at 13:33
  • can't belive i didnt try this, but the problem is that i need the widget for other stuff :O – dontcare Jul 16 '15 at 13:40
  • 3
    @dontcare: It's client side. You can inline loop index in widget var. See also a.o. http://stackoverflow.com/questions/13199595/primefaces-lightboxs-widgetvar-interfering-with-uirepeat/ – BalusC Jul 16 '15 at 14:18
0

It seems that the calendar is simply bugged, tried a ton of other primefaces components and all work fine expcept the calendar...

So i gave up with the normal approach to fix that problem. I nocited that the e.g onclick="jsMethod(this)" will get me the id via javascript. so now i call my js method, get the id, trigger a remotecommand and read the saved value from the remotecommand method. its a ugly workaround but i can't think of anything better than this.

you can find a example of this here: http://blogs.bytecode.com.au/glen/2013/09/25/calling-primefaces-remotecommand-with-javascript-arguments.html

dontcare
  • 935
  • 3
  • 16
  • 34