2014-05-08 41 views
1

我無法在Xpages中獲得簡單的兩個字段依賴關係。Xpages從屬字段查找

Field1是一個組合框,其選擇來自DBLookup。

Field2是一個組合框,其選擇來自一個DBLookup,該DBLookup使用Field1中的值對子集進行選擇。

我的代碼如下:

<?xml version="1.0" encoding="UTF-8"?> 
    <xp:view xmlns:xp="http://www.ibm.com/xsp/core" 
     xmlns:xp_1="http://www.ibm.com/xsp/coreex"> 
     <xp:this.data> 
      <xp:dominoDocument var="document1" formName="timeEntry"></xp:dominoDocument> 
     </xp:this.data> 

     <xp:comboBox id="comboBox1"> 
      <xp:this.defaultValue><![CDATA[#{javascript:""}]]></xp:this.defaultValue> 
      <xp:selectItems> 
       <xp:this.value><![CDATA[#{javascript:var db = new Array(@DbName()[0], 'TSCTT.nsf'); 
    @DbColumn(db, "workCategoryView", 1)}]]></xp:this.value> 
      </xp:selectItems> 
      <xp:eventHandler event="onchange" submit="true" 
       refreshMode="complete"> 
      </xp:eventHandler> 
      </xp:comboBox> 
     <xp:br></xp:br> 
     <xp:br></xp:br> 
     <xp:br></xp:br> 
     <xp:comboBox id="comboBox2"> 
      <xp:selectItems> 
       <xp:this.value><![CDATA[#{javascript:var db = new Array(@DbName()[0], 'TSCTT.nsf'); 
    var key:String = document1.getItemValueString("comboBox1"); 
    @DbLookup(db,"(DBLookupWorkSubCategoryView)",key,2);}]]></xp:this.value> 
      </xp:selectItems> 
     </xp:comboBox> 
     <xp:br></xp:br> 
     <xp:br></xp:br> 
     <xp:br></xp:br> 
     <xp:br></xp:br> 
     <xp:selectItems> 
       <xp:this.value><![CDATA[#{javascript:var db = new Array(@DbName()[0], 'TSCTT.nsf'); 
    var key:String = document1.getItemValueString("djFilteringSelect1"); 
    @DbLookup(db,"(DBLookupWorkSubCategoryView)",key,2);}]]></xp:this.value> 
      </xp:selectItems> 

</xp:selectItems></xp:view> 

我更新的代碼如你所說,但它仍然無法正常工作。

<?xml version="1.0" encoding="UTF-8"?> 
    <xp:view xmlns:xp="http://www.ibm.com/xsp/core" 
     xmlns:xp_1="http://www.ibm.com/xsp/coreex"> 
     <xp:this.data> 
      <xp:dominoDocument var="document1" formName="timeEntry"></xp:dominoDocument> 
     </xp:this.data> 

     <xp:comboBox id="comboBox1" value="#{document1.workCategory}"> 
      <xp:selectItems> 
       <xp:this.value><![CDATA[#{javascript:var db = new Array(@DbName()[0], 'TSCTT.nsf'); 
    @DbColumn(db, "workCategoryView", 1)}]]></xp:this.value> 
      </xp:selectItems> 
      <xp:eventHandler event="onchange" submit="true" 
       refreshMode="partial" refreshId="comboBox2"> 
      </xp:eventHandler> 
     </xp:comboBox> 
     <xp:br></xp:br> 
     <xp:br></xp:br> 
     <xp:br></xp:br> 
     <xp:comboBox id="comboBox2" value="#{document1.workSubCategory}"> 
      <xp:selectItems> 
       <xp:this.value><![CDATA[#{javascript://var db = new Array(@DbName()[0], 'TSCTT.nsf'); 
    var key:String = document1.getItemValueString("comboBox1"); 
    //@DbLookup(db,"(DBLookupWorkSubCategoryView)",key,2); 
    //var key = document1.getItemValue("comboBox1"); 
    //var key = currentDocument.getItemValueString("comboBox1") 
    key 

    //var item = document1.getValue("comboBox1"); 
    //return item;}]]></xp:this.value> 
      </xp:selectItems> 
     </xp:comboBox> 
     <xp:br></xp:br> 
     <xp:selectItems> 
       <xp:this.value><![CDATA[#{javascript:var db = new Array(@DbName()[0], 'TSCTT.nsf'); 
    var key:String = document1.getItemValueString("djFilteringSelect1"); 
    @DbLookup(db,"(DBLookupWorkSubCategoryView)",key,2);}]]></xp:this.value> 
      </xp:selectItems></xp:view> 

回答

3

事情改變:

  • 改變你的onChange事件的第二個組合框的局部刷新

  • 綁定您的組合框上文檔1場。現在他們都沒有綁定,你可以因此不使用document1.getItemValueString()獲取選中值

  • 刪除已放置在您的組合框之外

+0

我更新了我的代碼,但它仍然無法正常工作。 –

+0

你的查找鍵需要使用workCategory而不是combobox1 –

+0

這對我來說真是愚蠢。我得到它的工作。但是,如果這些字段是自定義控件的一部分,則看起來不起作用。如果我把它們放在自己的XPage中,它們就可以工作,但是如果它們在CC中,它們不會。那是對的嗎? –

1

我注意到,第三selectItems標籤代碼價值attribut評估2次,所以我更喜歡查找或計算事件:

<xp:view xmlns:xp="http://www.ibm.com/xsp/core"> 

    <xp:this.data> 
     <xp:dominoDocument var="document1" 
      formName="TestComboDependency"> 
     </xp:dominoDocument> 
    </xp:this.data> 

    <xp:this.beforePageLoad><![CDATA[#{javascript: 
     viewScope.choiceList1 = @DbColumn("", "($LkpChoiceList1)", 1); 
     viewScope.choiceEmpty2 = " --- Select a value for combo1 before --- "; 
     viewScope.choiceList2 = null; 
    }]]></xp:this.beforePageLoad> 

    <xp:comboBox id="comboBox1" value="#{document1.Combo1}"> 
     <xp:selectItem 
      itemLabel=" --- Select a value --- " 
      itemValue="" 
      id="selectItem1" /> 
     <xp:selectItems 
      value="#{viewScope.choiceList1}" 
      id="selectItems1" /> 
     <xp:eventHandler event="onchange" submit="true" 
      refreshMode="partial" refreshId="comboBox2" 
      disableValidators="true"> 
      <xp:this.action><![CDATA[#{javascript: 
       var sKey:string = document1.getItemValueString("Combo1"); 
       viewScope.choiceEmpty2 = " --- Select a value --- "; 
       viewScope.choiceList2 = @DbLookup("", "($LkpChoiceList2)", sKey, 2); 
      }]]></xp:this.action> 
     </xp:eventHandler> 
    </xp:comboBox> 

    <xp:comboBox id="comboBox2" value="#{document1.Combo2}"> 
     <xp:selectItem 
      itemLabel="#{viewScope.choiceEmpty2}" 
      itemValue="" 
      id="selectItem2" /> 
     <xp:selectItems 
      value="#{viewScope.choiceList2}" 
      id="selectItems2" /> 
    </xp:comboBox> 

</xp:view>