我知道我们需要显式地添加process =“@ this”以获取调用p:commandbutton动作,并且我也知道processface属性默认为@face.
由于进程默认为@form,因此该按钮也不会与表单中的其他元素一起处理,并且应该调用其操作.
任何人都可以解释这背后的确切原因吗?
解决方法
Process @form表示commandLink / Button的当前形式
进程@这意味着commandLink / Button的当前组件.检查以下代码.
进程@这意味着commandLink / Button的当前组件.检查以下代码.
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); } }
让我们的用户输入输入框
001 -> id Jone -> name London -> address
单击button1,将完成整个表单的所有JSF组件(例如:id,name,address).输出将是:
001 Jone London
单击button2,该过程将是其自身(例如:button2).没有id,名称,地址的进程.输出将是:
null null null
单击button3,所有JSF组件(例如:name)整个panel_1和button3将被处理.输出将是:
null Jone null