I need to be able to edit and read multiple fields on a document a la Name1, Number1, Name2, Number2, Name3,Number3, etc.
I figured I could read/edit these fields through a repeat control but I cannot figure out how to dynamically bind the data sources to the fields.
record.Name1 binds just fine but I need to be able to do something like record.Name + index (index would come from the repeat control) so when the repeat runs we get record.Name1, record.Name2…
Anyone know of if this is possible?
Subject: Re: XPages: Can you dynamically bind a control to a field?
I’ve come up with something that could actually solve your problem. But my solution is pretty ugly, I’m sure there is a nicer way of doing it. My repeat control with two edit boxes (for Name and Number) in it has the following code:
<xp:repeat id=“repeat1” rows=“5” value=“#{javascript:return 5;}” indexVar=“index” first=“1”>
<xp:inputText id="inputText1" value="#{record[requestScope.name]}">
<xp:this.rendered><![CDATA[#{javascript:requestScope.name = "Name"+index; return true;}]]></xp:this.rendered>
</xp:inputText>
<xp:inputText id="inputText2" value="#{record[requestScope.number]}">
<xp:this.rendered><![CDATA[#{javascript:requestScope.number = "Number"+index; return true;}]]></xp:this.rendered>
</xp:inputText>
</xp:repeat>
I’ve used the ‘rendered’ property of edit boxes to set the two requestScope variables ‘requestScope.name’ and ‘requestScope.number’ to dynamic values containing the field name for the current index.
Then I’ve used the values of these requestScope variables in the Expression Language Statement #{record[requestScope.xxx]} for the data binding.
I’m pretty sure there is a better way to do this. It would be nice if you could do something like this with the EL:
<xp:repeat id=“repeat1” rows=“5” value=“#{javascript:return 5;}” indexVar=“index” first=“1”>
<xp:inputText id="inputText1" value="#{record['Name'+index]}"></xp:inputText>
<xp:inputText id="inputText2" value="#{record['Number'+index]}"></xp:inputText>
</xp:repeat>
Somebody with a better knowledge of the JSF Expression Language than me could possibly help out here…
Anyway, good luck solving your problem.
Steve
Subject: EL Experts??
Steve,
Thanks. We are on the same page…I thought about your solution and I may head down that path but I wanted to check and see if anyone had found a way to do what you and I both want to do…
<xp:inputText id=“inputText1” value=“#{record[‘Name’+index]}”></xp:inputText>
Any EL Experts out there 'cause the above ain’t working for us…??