gpt4 book ai didi

forms - 为什么要将进程 ="@this"显式添加到 p :commandButton to get action invoked?

转载 作者:行者123 更新时间:2023-12-04 01:23:00 25 4
gpt4 key购买 nike

我知道我们需要明确添加 process="@this"获取 p:commandbutton Action 被调用,我也知道进程属性默认为 @form在素面。

由于进程默认为@form按钮不应该与表单中的其他元素一起被处理,并且它的 Action 应该被调用。

谁能解释这背后的确切原因?

最佳答案

处理 @form表示 commandLink/Button 的当前形式
处理 @this表示 commandLink/Button 的当前分量.检查下面的代码。

进程.xhtml

<h:form id="form1">
<h:inputText value="#{ProcessBean.id}" id="id"/><br/>
<h:panelGroup id="panel_1">
<h:inputText value="#{ProcessBean.name}" id="name"/><br/>
</h:panelGroup>
<h:panelGroup id="panel_2">
<h:inputText value="#{ProcessBean.address}"/>
<br/>
<p:commandButton process="@form" value="Btm1" id="button1" action="#{ProcessBean.show}"/><!-- Default -->
<p:commandButton process="@this" value="Btm2" id="button2" action="#{ProcessBean.show}"/>
<p:commandButton process="@this form1:panel_1" value="Btm3" id="button3" action="#{ProcessBean.show}"/>
</h:panelGroup>
</h:form>

ProcessBean.java
@ManagedBean(name = "ProcessBean")
public class ProcessBean {
private String id;
private String name;
private String address;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}

public void show() {
System.out.println(id);
System.out.println(name);
System.out.println(address);
}
}

让我们用户输入输入框
001     -> id
Jone -> name
London -> address

点击 button1 , 所有 JSF component(Eg : id, name, address)整个表格将被处理。输出将是:
001
Jone
London

点击 button2 , 该过程将是自己的(例如:button2)。 id, name, address 没有进程.输出将是:
null
null
null

点击 button3 , 所有 JSF component(Eg : name)整个 panel_1button3将是过程。输出将是:
null
Jone
null

不调用您的操作方法?调用前可能存在验证或转换失败。

关于forms - 为什么要将进程 ="@this"显式添加到 p :commandButton to get action invoked?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22234918/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com