19

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?

Tiny
  • 27,221
  • 105
  • 339
  • 599
Srikanth Ganji
  • 1,127
  • 1
  • 13
  • 29
  • Thanks a lot Balusc. I have read the link before posting this question itself and many of my doubts got clarified. But my doubt is since process defaults to form shouldn't the button get processed as one of all elements in the form? – Srikanth Ganji Mar 06 '14 at 20:30
  • Sorry for the late reply. If the validation fails for atleast one of form elements then JSF life cycle would directly render response by skipping Update Model values and Invoke application phase. So my doubt is if there are no validation errors shouldn't the button action get executed in the normal jsf lifecycle. – Srikanth Ganji Mar 27 '14 at 09:50
  • What's the source that says a commandButton must have `@this` to get processed? Do you have a working example that illustrates this? – kolossus Jul 29 '14 at 05:38

1 Answers1

52

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.

Jens Piegsa
  • 7,399
  • 5
  • 58
  • 106
Zaw Than oo
  • 9,651
  • 13
  • 83
  • 131