2016-05-04 26 views
0

コンボボックスはJava Beanにバインドされています。ドキュメントは読み取りモードで開き、選択した値が表示されます。Xpages:読み取りモードから編集モードに移行するとき、Comboboxは値を保持しません

enter image description here

しかし、私が編集モードに入るとき、値が「失われます」。

enter image description here

私は、ページ上の2つのフィールドを作り避けたいが、私は私がしなければならない場合は私ができると思います。しかし、私のコードや私のアプローチで何かが間違っているようです。

<?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

それが動作するのに対し、

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

思えによって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>      

コンボボックスのプロパティを設定するためのコードを置き換え、コンボボックスはattr(で無効に設定して正しく対処することはできませんinputTextコントロールの場合は問題ありません)。
しかし、コンボボックスの直接プロパティdisabledは、とにかくattrs/attrコードよりも処理する方が良いです。

+0

また、部分リフレッシュライフサイクル中にレンダリングされた計算が何回も実行されるため、パフォーマンスは向上しますが、パフォーマンスは向上します。また、パネルにはreadonlyプロパティがあります。機能と要件に応じて、別の方法があります(特に、同じパネルに複数のコンポーネントがある場合)。 –

+0

Paul、素晴らしい提案。私のデザインは、フィールドのグループを有効/無効にする必要があることを意味します。そのため、グループを別のパネルに配置し、そのレベルで有効/無効にします。 –

関連する問題