Xpages:从读取模式进入编辑模式时,Combobox不会保留值

时间:2016-05-04 19:50:54

标签: combobox expression xpages

组合框绑定到java bean。文档以读取模式打开,并显示所选值。

enter image description here

但是当我进入编辑模式时,该值会“丢失”。

enter image description here

我想避免在页面上创建两个字段,但我想如果必须的话我可以。但似乎我的代码或方法出了问题。

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlns:xe="http://www.ibm.com/xsp/coreex"
    xmlns:xc="http://www.ibm.com/xsp/custom">
    <xp:this.afterPageLoad><![CDATA[#{javascript:sessionScope.models = PCConfig.models;
viewScope.readOnly = "Yes";}]]></xp:this.afterPageLoad>
    <xp:button value="Toggle Edit Mode" id="button1">
        <xp:eventHandler event="onclick" submit="true"
            refreshMode="complete">
            <xp:this.action><![CDATA[#{javascript:if (viewScope.readOnly == "Yes")
{viewScope.readOnly = "No"}
else
{viewScope.readOnly = "Yes"}}]]></xp:this.action>
        </xp:eventHandler>
    </xp:button>
    <xp:br></xp:br>
    <xp:br></xp:br>
    <xp:text escape="true" id="computedField1" value="#{viewScope.readOnly}"></xp:text>
    <xp:br></xp:br>
    <xp:panel id="pnlAll">
        <xp:this.data>
            <xe:objectData saveObject="#{javascript:PCModel.save()}"
                var="PCModel">
                <xe:this.createObject><![CDATA[#{javascript:var pc = new com.scoular.model.PC();
var unid = sessionScope.get("key");

if (unid != null) {
    pc.loadByUnid(unid);
    sessionScope.put("key","");
    viewScope.put("readOnly","Yes");
} else {
    pc.create();
    viewScope.put("readOnly","No");
}
return pc;}]]></xe:this.createObject>
            </xe:objectData>
        </xp:this.data>
        <xp:comboBox id="model" value="#{PCModel.model}"
            disableValidators="true" disableClientSideValidation="true"
            styleClass="form-control">
            <xp:this.attrs>
                <xp:attr name="disabled" value="disabled">
                    <xp:this.rendered><![CDATA[#{javascript:if (viewScope.readOnly == "Yes")
{return true}
else
{return false}}]]></xp:this.rendered>
                </xp:attr>
            </xp:this.attrs>
            <xp:selectItems>
                <xp:this.value><![CDATA[#{javascript:"--Select A Value--|"}]]></xp:this.value>
            </xp:selectItems>
            <xp:selectItems>
                <xp:this.value><![CDATA[#{javascript:sessionScope.models}]]></xp:this.value>
            </xp:selectItems>
        </xp:comboBox>
    </xp:panel>
</xp:view>

1 个答案:

答案 0 :(得分:1)

替换您的代码以设置comboBox的属性disabled

    <xp:comboBox
        id="model"
        value="#{PCModel.model}"
        ...>
        <xp:this.attrs>
            <xp:attr name="disabled" value="disabled">
                <xp:this.rendered><![CDATA[#{javascript:if 
                    (viewScope.readOnly == "Yes")
                        {return true}
                    else
                        {return false}}]]></xp:this.rendered>
            </xp:attr>
        </xp:this.attrs>                    

通过

    <xp:comboBox
        id="model"
        value="#{PCModel.model}"
        ...
        disabled="#{javascript:viewScope.readOnly == 'Yes'}">

似乎,comboBox无法通过attr正确处理禁用的设置(而对于inputText控件它可以正常工作)。
但是,comboBox的直接属性disabled最好处理,而不是attrs / attr代码。