I have a very weird problem when using a custom component.
This is my main xhtml:
<html>
<ui:repeat value="#{list}" var="item">
<h:form>
<custom:component myCode="#{item.code}"
intervals="#{myBean.intervals(item.code)}"
selectedInterval="#{myBean.selectedInterval[item.code]}"
controller="#{myController}/>
</h:form>
</ui:repeat>
</html>
And this is the component xhtml:
<html>
<cc:interface componentType="custom.myComponent">
<cc:attribute name="myCode" required="true"/>
<cc:attribute name="intervals" required="true"/>
<cc:attribute name="selectedInterval" required="true"/>
<cc:attribute name="controller" required="true"/>
</cc:interface>
<p:selectOneRadio id="selected-interval"
value="#{cc.attrs.selectedInterval}">
<f:selectItems value="#{cc.attrs.intervals}"
var="interval"
itemLabel="#{interval.name}"
itemValue="#{interval}"/>
<p:ajax event="change"
process="@this"
global="false"
update="@form"/>
</p:selectOneRadio>
<k:calendarHeader
id="calendar-interval"
dayVarStatus="dayVar"
groupRows="false">
<f:facet name="day">
<h:outputText value="#{dayVar.date}">
<f:convertDateTime pattern="d"/>
</h:outputText>
</f:facet>
<p:ajax event="change"
listener="#{cc.attrs.controller.processChanges(cc.attrs.myCode)}"
update="@this"
global="false"
process="@this"/>
</k:calendarHeader>
</html>
<k:calendarHeader>
is also a custom component of ours, but it has been working for years in several differents scenarios so I don't think the problem lies there. It basically only maps the change
event:
<composite:clientBehavior name="change" event="change" targets="calendarHeader"/>
The problem I'm having is that if the processChanges
function is getting called before manually selecting a radio button, it always has the last myCode
value of the ui:repeat.
Let's say my code list has 3 values: 200, 300, 400. The processChanges is always called with 400. BUT if I select one radio button, the form is refreshed, and then the code is correct.
The initialization of the radio button is done correctly, it's just that it seems that the "stored" value of myCode
before refreshing is incorrect.
I don't understand this behaviour because I have other <p:ajax>
calls in other areas that work like a charm in with <ui:repeat>
.
If anyone has any idea about where can the error be, I'll be very thankful, even if I understand that there is a lot of code that is not being displayed here, and thus quite difficult to see an error.