2011-08-09 105 views
1

我有一個簡單的用例Struts2的股利阿賈克斯刷新

<div id="contentDiv"> 

      <!-- This does not work --> 
      <div id="frmDiv"> 
        <s:form action=".."> 
          <s:a target="contentDiv" theme="ajax">Reload</s:a> 
        </s:form> 
      </div> 

      <!--This works --> 
      <div id="listDiv"> 
        <s:a target="frmDiv" theme="ajax" someaction >Click Me</s:a> 
      </div> 
    </div> 

我注意到,當一個鏈接的目標是相同的目標內,則該阿賈克斯行動是行不通的。而當鏈接的目標是在div之外時,按需要工作。

任何解決方法重新加載相同的div或將其設置爲ajax結果的目標。

我用struts 2.0.14

而且,這裏,而不是鏈接,如果我用這個按鈕不起作用。任何解決方法將不勝感激。

回答

2

只需使用html即可。從長遠來看,使用ajax witout標籤庫可能是更快的方法。它們適用於模板和簡單的邏輯,但隨着客戶端需求變得更加苛刻,它們很快就會失敗。

你應該升級應用程序,這是非常不可能的事情會破壞,你會得到一些新的功能。您可能遇到的問題不存在。還沒有測試過,但自該版本以來,標籤庫已經進行了一些改進和修復。

<a href="#first">link to first</a> 
<a href="#second">link to second</a> 

<!-- following weird ognl was used because you are at version 2.0.14, you should upgrade then I could have used the begin and end attributes, like in c:forEach--> 
<s:iterator value="(84).{ #this }" > 
    <br/> 
</s:iterator> 

<div id="first"> 
This is first. 
</div> 

<s:iterator value="(84).{ #this }" > 
    <br/> 
</s:iterator> 

<div id="second"> 
This is second 
</div>