ReadOnly field in Xpage not submitted

谁都会走 提交于 2019-11-26 22:11:40

问题


I have a field in my Xpage that I want to be readOnly and submitted to the database upon Save. This field gets a value from a Ajax call

Setting the property ReadOnly to true creates a <span> instead of a readonly field.

Setting the property "Show disabled control for readonly" creates a input text field with the property readonly=readonly.

<input type="text" class="xspInputFieldEditBox" readonly="readonly" name="view:_id1:_id2:_id3:_id28:callbackFieldControlSet:InstrumentShort" id="view:_id1:_id2:_id3:_id28:callbackFieldControlSet:InstrumentShort">

It will not be saved to the database.

According to my knowledge readonly fields are submitted but not disabled.

What I'm I doing wrong here?

/M


回答1:


You can add the readonly attribute with the attr-property:

<xp:inputText id="inputText2" value="#{document1.ReadOnly}">
   <xp:this.attrs>
      <xp:attr name="readonly" value="true" />
   </xp:this.attrs>
</xp:inputText>

Btw: The behaviour of the disabled and the readonly property is correct, because this is a definition on the server side. You want to edit the component with a value, that is why it must be allowed to accept values. Just disabling it on the client side has technically no effect.




回答2:


I think this is a bug. You are right, the read only field should get saved. In version 8.5.1 when the property of "Show disabled control for readonly" was not present I used to set the field as readonly through JavaScript. Here's the code snippet:

<xp:scriptBlock id="scriptBlock1">
    <xp:this.value><![CDATA[function makeFieldReadOnly() {
    document.getElementById("#{id:inputText2}").readOnly = true;
}
window.onload = makeFieldReadOnly;]]></xp:this.value>
</xp:scriptBlock>

In the above snippet the function makeFieldReadOnly marks the edit box inputText2 as readonly when page is loaded.



来源:https://stackoverflow.com/questions/14637693/readonly-field-in-xpage-not-submitted

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!