Xpages sets the value for a field from a repeat field

I am trying to set a value for a field (which is not inside a repeat slider) from a field that is in a repeat slider.

Field from replay:

<xp:inputText id="inputText2" disabled="true">
        <xp:this.value><![CDATA[#{viewScope.field_2[index]}]]></xp:this.value>
        <xp:eventHandler event="onchange" submit="true"
                    refreshMode="partial" refreshId="sus">
                    <xp:this.action><![CDATA[#{javascript:getComponent("inputText4").setValue("1234");}]]></xp:this.action>
        </xp:eventHandler>
</xp:inputText>

      

And the target field, as you can see, is inside the panel, id = "sus".

Also, the target field is bound to the form field.

but no value is assigned. How can I achieve this?

+3


source to share


1 answer


Components are just visualizations of the data model. Always bind your controls and go after the model value, not the component. Disabled input text cannot start the value, but in the code snippet above disabled="true"

. The onchange event cannot fire.

This will work:

<xp:inputText id="inputText2" disabled="false">
    <xp:this.value><![CDATA[#{viewScope.field_2[index]}]]></xp:this.value>
    <xp:eventHandler event="onchange" submit="true"
                refreshMode="partial" refreshId="sus">
                <xp:this.action><![CDATA[#{javascript:viewScope.someValue=42;}]]></xp:this.action>
    </xp:eventHandler>
</xp:inputText>

      

Your target control will look like this:

<xp:inputText id="inputText4" value="#{viewScope.someValue}">
</xp:inputText>

      



If your target element is attached to something else (for example #{document1.test}

), your code should update it. ( document1.replaceItemValue("test",42)

)

Again 3 important aspects:

  • Never go behind UI elements, always update the associated model (aka: Talk to data, not UI , also known as: Controller updates MODEL, not view)
  • Make sure your target is part of the updated fields.
  • Disabled fields do not fire events

Let us know how it's done

+3


source







All Articles