PrimeFaces如何从xhtml更改@ManagedBean的属性(PrimeFaces how to change attribute of @ManagedBean from xhtml)
我想知道是否可以更改属性的值
我试过这个,但它不起作用:
<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; } }I'm wondering if is it possible to change the value of an attribute
I tried this but it does not work:
<p:menuitem value="ADD" action="#{a.setA2("NewA2Value")}"/>Assume that I have this @ManagedBean class:
@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; } }最满意答案
你有一些选择。
方法表达 F:setPropertyActionListener F:属性附加伤害 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:表格
你的行动应该是这样的。
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; }You have some options here.
Method expression f:setPropertyActionListener f:atribute f:paramTake a look to this: http://www.mkyong.com/jsf2/4-ways-to-pass-parameter-from-jsf-page-to-backing-bean/
Example with 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>Don't forget the h:form
And your action should looks like this.
public String myAction() { //String value = this.a1; //String value2 = this.a2; //You have to return the viewId for the navigation, or null }or
public void myAction() { //String value = this.a1; //String value2 = this.a2; }更多推荐
value,public,setA,电脑培训,计算机培训,IT培训"/> <meta name="description
发布评论