【问题标题】:PrimeFaces how to change attribute of @ManagedBean from xhtmlPrimeFaces如何从xhtml更改@ManagedBean的属性
【发布时间】:2015-11-23 16:14:11
【问题描述】:

我想知道是否可以更改属性的值

我试过了,但它不起作用:

<p:menuitem value="ADD" action="#{a.setA2("NewA2Value")}"/>

假设我有这个@ManagedBean 类:

@ManagedBean
public class A {
 private String a1;
 private String a2;

 public A() {
 }

 public void setA1(String a1) {
  this.a1 = a1;
 }

 public void setA2(String a2) {
  this.a2 = a2;
 }

 public String getA1() {
  return a1;
 }

 public String getA2() {
  return a2;
 }
}

【问题讨论】:

    标签: jsf-2 primefaces


    【解决方案1】:

    这里有一些选择。

    1. 方法表达式
    2. f:setPropertyActionListener
    3. f:属性
    4. f:param

    看看这个:http://www.mkyong.com/jsf2/4-ways-to-pass-parameter-from-jsf-page-to-backing-bean/

    f:setPropertyActionListener

    示例
    <p:menuitem value="ADD" action="#{a.myAction}">
        <f:setPropertyActionListener target="#{a.a1}" value="myValue" />
        <f:setPropertyActionListener target="#{a.a2}" value="myValue2" />
    </p:menuitem>
    

    不要忘记 h:form

    你的动作应该是这样的。

    public String myAction() {
      //String value = this.a1;
      //String value2 = this.a2;
      //You have to return the viewId for the navigation, or null
    }
    

    public void myAction() {
      //String value = this.a1;
      //String value2 = this.a2;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-29
      • 1970-01-01
      • 2015-04-09
      • 2017-01-20
      • 1970-01-01
      • 2013-03-22
      • 2014-05-19
      • 2013-06-17
      相关资源
      最近更新 更多