为什么要添加process =“@ this”显式地为p:commandButton以获取操作被调用? [英] Why to add process="@this" explicitly to p:commandButton to get action invoked?
问题描述
我知道我们需要明确地添加 process =@ this
来获取 p:commandbutton
action被调用,我也知道进程属性在primefaces中默认为 @form
。
由于进程默认为 @form
不应该按钮也会与其他元素一起处理表单及其行为应该被调用。
任何人都可以解释背后的确切原因吗? @form
表示当前<$ c的形式$ c> commandLink / Button
进程 @this
表示 commandLink的当前组件/按钮
。检查下面的代码。
process.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 =@ this form1:panel_1value =Btm3id =button3action =#{ProcessBean.show}/>
< / h:panelGroup>
< / h:表格>
ProcessBean.java
@ManagedBean(name =ProcessBean)
public class ProcessBean {
private String id;
私人字符串名称;
私有字符串地址;
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);
让我们的用户输入inputbox
001 - > id
Jone - >名称
伦敦 - >地址
点击 button1
,全部 JSF组件(例如:id,name,address)
将完成整个表单的处理。输出将是:
001
Jone
伦敦
点击 button2
,这个过程本身就是(例如:button2)。没有 id,name,address
的进程。输出结果为:
null
null
null
单击 button3
,所有 JSF组件(例如:name) code>整个 panel_1
和 button3
将会被处理。输出结果为:
null
Jone
null
不会调用您的操作方法?在调用之前可能会有验证或转换失败。
I know that we need to add explicitly process="@this"
to get the p:commandbutton
action get invoked and I also know that process attribute defaults to @form
in primefaces.
Since process is defaulted to @form
shouldn't the button also get processed along with the other elements in the form and its action should get invoked.
Can anyone explain the exact reason behind this?
解决方案 Process @form
mean the current form of the commandLink/Button
Process @this
mean the current component of the commandLink/Button
. Check below code.
process.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);
}
}
Let's user input inputbox
001 -> id
Jone -> name
London -> address
Click button1
, all JSF component(Eg : id, name, address)
entire of the form will be process. Output will be :
001
Jone
London
Click button2
, The process will be itself (Eg : button2). No process for id, name, address
. Output will be:
null
null
null
Click button3
, all JSF component(Eg : name)
entire of the panel_1
and button3
will be process. Output will be :
null
Jone
null
Does not invoke your action method? There might be validation or conversion failed before invoke.
这篇关于为什么要添加process =“@ this”显式地为p:commandButton以获取操作被调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!