0

我正在尝试本教程,该教程描述了如何将属性设置为服务器调用以及如何分析支持 bean 上的属性;

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

我用谷歌搜索了很多,但大多数示例显示了如何为同步调用而不是异步调用设置属性:S 所以我的问题是......如果那是 ajax 调用,如何在服务器上发送属性以及如何获取它们在支持 bean 上(参见建议 A 代码片段)?

建议A:

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

    </h:commandButton>

如果有关于这个问题的好教程,请分享链接:)

谢谢

4

2 回答 2

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>

...在支持豆上

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

似乎它工作正常:) 所以属性应该放在事件制作组件块中 -h:commandButton在这种特殊情况下......

于 2016-09-15T22:00:22.473 回答
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)}"/> 
于 2016-10-27T17:33:00.537 回答