PrimeFaces如何从xhtml更改@ManagedBean的属性(PrimeFaces how to change attribute of @ManagedBean from xhtml)

编程入门 行业动态 更新时间:2024-10-27 22:34:18
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:param

Take 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

本文发布于:2023-07-24 00:33:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1239330.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:属性   xhtml   PrimeFaces   ManagedBean   attribute

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!