2016-06-28 7 views
1

私は隠しテーブルを部分的にリフレッシュするコンボボックスを持っています。デフォルト値以外の値が選択されると、テーブルを表示しようとしています。私は、表のレンダリングを制御するかどうかをスコープ変数にバインドされた隠し編集フィールドを使用しています。私は、スコープ変数が設定される前に部分的なリフレッシュを最初にやっているというコードがあることを信じています(onCompleteのコードを参照してください)。しかし、リフレッシュが発生する前にスコープ変数を最初に設定する方法が不明です。誰かが私を正しい方向に向けることができますか?一部のページの更新中にエラーが発生しました

<xp:comboBox id="vendorAppAdvSkills1"> 
    <xp:selectItem itemLabel="-Select a Category-" 
     itemValue="" id="selectItem1"> 
    </xp:selectItem> 
    <xp:selectItems id="selectItems1"> 
     <xp:this.value><![CDATA[#{javascript:getComponent("vendorAppSkills1").getValue();}]]></xp:this.value> 
    </xp:selectItems> 
    <xp:eventHandler event="onblur" submit="false" 
     id="eventHandler1"> 
     <xp:this.script><![CDATA[ 
XSP.partialRefreshPost("#{id:tblAdvertising}", 
{ 
    // Added showAdvertising code to hide the advertising table until the user selects their free category! 
    onComplete: function() 
    { 
     // Fetch a handle to the first category field 
     var freeCategory = dojo.byId('#{id:vendorAppAdvSkills1}'); 
     var showAdvertising = document.getElementById('#{id:showAdvertising}'); 
     // If it's blank, force the cursor off the field to fire the onBlur Event 
     if(freeCategory.value == "" || freeCategory.value == null) 
     { 
      if($('body').scrollTop()>0) 
      { 
       $('body').scrollTop(0);   //Chrome,Safari 
      } 
      else 
      { 
       if($('html').scrollTop()>0) 
       { //IE, FF 
        $('html').scrollTop(0); 
       } 
      } 
      showAdvertising.value = false; 
      // Notify the user this is required 
      alert("Please Select Your FREE Category Listing!"); 
      // Place the cursor back in the first category field again 
      freeCategory.focus(); 
     } 
     else 
      showAdvertising.value = true; 
    } 
});]]></xp:this.script> 
    </xp:eventHandler> 
</xp:comboBox> 

NEW CODEは、代わりにXSP.partialRefreshPostで部分的にリフレッシュを行うのHERE

<xp:comboBox id="vendorAppAdvSkills1"> 
<xp:selectItem itemLabel="-Select a Category-" 
    itemValue="" id="selectItem1"> 
</xp:selectItem> 
<xp:selectItems id="selectItems1"> 
    <xp:this.value><![CDATA[#{javascript:getComponent("vendorAppSkills1").getValue();}]]></xp:this.value> 
</xp:selectItems> 
<xp:eventHandler event="onblur" submit="true" refreshMode="partial" refreshId="tblAdvertising" 
    onComplete="alert('ssjs code done')"> 
    <xp:this.script><![CDATA[#{javascript: 
    var vendorAppSkills = getComponent("vendorAppSkills1").getValue(); 
    print("vendorAppSkills: " + vendorAppSkills); 
    print("typeof vendorAppSkills: " + typeof vendorAppSkills); 
    if(typeof vendorAppSkills == "java.util.Vector") 
    { 
     if(vendorAppSkills.contains("-Select a Category-")) 
      viewScope.put("showAdvertising", false); 
    } 
    else 
    { 
     if(typeof(vendorAppSkills == "String")) 
      if(vendorAppSkills.equalsIgnoreCase("-Select a Category-")) 
       viewScope.put("showAdvertising", false); 
      else 
       viewScope.put("showAdvertising", true); 
    } 
    }]]></xp:this.script> 

答えて

2

を追加して、あなたのonCompleteのコードは、スコープ変数の後に実行されます、あなたのスコープの変数を設定し、イベントハンドラのrefreshIdパラメータを使用します

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

     <xp:this.afterPageLoad><![CDATA[#{javascript:viewScope.myVar = "initial value";}]]></xp:this.afterPageLoad> 
     <xp:comboBox id="comboBox1"> 
      <xp:selectItem itemLabel="val 1" itemValue="val1"></xp:selectItem> 
      <xp:selectItem itemLabel="val 2" itemValue="val2"></xp:selectItem> 
      <xp:eventHandler event="onchange" submit="true" refreshMode="partial" 
       refreshId='#{javascript:(viewScope.myVar == "someValue") ? "idToUpdate" : ""}' 
       onComplete="alert('ssjs code done');"> 
       <xp:this.action><![CDATA[#{javascript:viewScope.myVar = "someValue";}]]></xp:this.action> 
      </xp:eventHandler> 
     </xp:comboBox> 

     <xp:panel id="idToUpdate"> 
      <xp:this.rendered><![CDATA[#{javascript:(viewScope.myVar == "someValue")}]]></xp:this.rendered> 
      table data 
     </xp:panel> 
    </xp:view> 
+0

あなたが言ったことを実装しようとしましたが、同じエラーが発生しました:( 新しいコードを見て、間違っているとわかったら教えてください。 – Bitwyse1

+0

また、私のprintステートメントは、リフレッシュではなく読み込み時にのみ実行されることに気づきました。 – Bitwyse1

+0

サーバサイドのコードはすべて、タグではなく、 'でなければなりません。私の例の構文を使って試してみてください。 '<![CDATA [#{javascript:' – jpishko

関連する問題