为什么要添加进程=“@this"?明确地 p:commandButton 来调用动作? [英] Why to add process="@this" explicitly to p:commandButton to get action invoked?

查看:31
本文介绍了为什么要添加进程=“@this"?明确地 p:commandButton 来调用动作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我们需要显式添加 process="@this" 来调用 p:commandbutton 操作,我也知道 process 属性默认为 <代码>@form 在primefaces 中.

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.

由于 process 默认为 @form 不应该按钮也与表单中的其他元素一起处理,并且应该调用它的操作.

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 表示commandLink/Button
的当前表单Process @this 表示commandLink/Button 的当前组件.检查下面的代码.

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

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

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,名称,地址)都会被处理.输出将是:

Click button1, all JSF component(Eg : id, name, address) entire of the form will be process. Output will be :

001
Jone
London

点击button2,进程将是它自己(例如:button2).id, name, address 无需处理.输出将是:

Click button2, The process will be itself (Eg : button2). No process for id, name, address. Output will be:

null
null
null

点击button3panel_1button3 的所有JSF 组件(例如:名称)过程.输出将是:

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.

这篇关于为什么要添加进程=“@this"?明确地 p:commandButton 来调用动作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆