2016-09-08 75 views
0

我在嘗試this tutorial,它描述瞭如何將屬性設置爲服務器調用以及如何分析backing bean上的屬性;Ajax請求和屬性

<h:commandButton id="submit" 
actionListener="#{userData.attributeListener}" action="result"> 
    <f:attribute name="value" value="Show Message" />     
    <f:attribute name="username" value="JSF 2.0 User" /> 
</h:commandButton> 

我GOOGLE了很多,但最例子展示瞭如何設置同步-ED ATTRS要求不是非同步-ED者:S所以我的問題是...如何在服務器發送的屬性,如果這將是ajax調用以及如何讓它們支持bean(請參閱建議代碼片段)?

建議答:

<h:commandButton id="submit" 
    actionListener="#{userData.attributeListener}" action="result"> 
     <f:ajax> 
      <f:attribute/>? how to 
     </f:ajax> 

    </h:commandButton> 

,如果有關於這個問題請你分享鏈接:)

感謝一個很好的教程

+0

究竟是什麼問題?通常情況下,在這種情況下很少使用命令組件上的'f:attribute',比如'commandButton'。你應該更容易使用button的'action'屬性和'f:setPropertyActionListener'來設置一個後臺bean屬性或'h:inputHidden'。 – djmj

+0

@djmj問題是以一種或多或少的最佳方式在一個請求中以#{tagAValue}和#{tagBValue}的形式發送兩個標籤的值; – cbhogf

+1

或者使用EL的最新版本,您可以將參數傳遞給方法......我從不需要使用這樣的構造。 – Kukeltje

回答

0

好,我只是寫了一個測試,將屬性設置爲ajax塊:

<h:commandButton id="submit" 
    actionListener="#{userData.callWithAttributes}" action="result"> 
     <f:attribute name="a" value="#{testa}"/> 
     <f:attribute name="b" value="#{testb}"/> 
     <f:ajax .../> 
</h:commandButton> 

...和支持bean

... 
public void callWithAttributes(ActionEvent e){ 
    String a=(String) e.getComponent().getAttributes().get("a"); 
    ... 
} 
... 

好像它做工精細:)所以屬性應該放到事件使得組件塊 - 在這種特殊情況下的h:commandButton ...

0

要設置後臺bean的兩個屬性,你可以使用f:setPropertyActionListener

<h:commandButton action="#{bean.method}"> 
    <f:setPropertyActionListener value="#{testA}" target="#{bean.valueA}/> 
    <f:setPropertyActionListener value="#{testB}" target="#{bean.valueB}/> 
</h:commandButton> 

或EL方法參數的支持:

<h:commandButton action="#{bean.method(testA, testB)}"/>