Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the function of @this exactly?

As far as I know the @this is to denote the current component triggering the event, such as :

<p:commandButton process="@this" ... />

And in JSF 2 Ajax, the @this can also mean the encapsulating component, like :

<h:inputText ...>
  <f:ajax execute="@this" ... />
</h:inputText>

And I have one case where using p:datatable, including or excluding @this can have a different impact upon Ajax partial submit

Here's the example, in this case, the process is using @this, and this works as expected, where when process happens first, and then followed by setPropertyActionListener and last, the action is executed :

<p:column>
    <p:commandLink 
        value="#{anggaranDetail.map['code']}"
        process="@this infoAnggaranForm:Anggaran"
        update="detailDialogForm:Anggaran detailDialogForm:SubAnggaran"  
        oncomplete="infoAnggaranDialog.hide()" 
        image="ui-icon ui-icon-search"
        action="#{tInputBean.updateAnggaranSubAnggaran}">
        <f:setPropertyActionListener value="#{anggaranDetail}"
            target="#{infoAnggaranBean.selectedAnggaranDetail}" />
    </p:commandLink>
</p:column>

But when I omit the @this from this example, the setPropertyActionListener and the action are never executed, as if they're not there.

I wonder why ? Perhaps @this has some other meaning other than the current component, perhaps the current record in this example ?

Im using tomcat 7, and these are my dependencies :

<dependency>
    <groupId>org.primefaces</groupId>
    <artifactId>primefaces</artifactId>
    <version>2.2.1</version>
</dependency>
<dependency>
    <groupId>com.sun.faces</groupId>
    <artifactId>jsf-api</artifactId>
    <version>2.0.4-b09</version>
    <scope>compile</scope>
</dependency>
<dependency>
    <groupId>com.sun.faces</groupId>
    <artifactId>jsf-impl</artifactId>
    <version>2.0.4-b09</version>
    <scope>compile</scope>
</dependency>
like image 251
Albert Gan Avatar asked Apr 18 '11 06:04

Albert Gan


1 Answers

The PrimeFaces process and standard JSF execute attributes should point to spaceseparated component identifiers of components which JSF should process during the entire JSF lifecycle upon an ajax request (get request parameters, validate them, update model, execute action). The process defaults to @form, the current form, and the execute defaults to @this, the current component. In command links/buttons this is mandatory to execute the actions associated with the link/button itself.

However, in your datatable you have process="@this infoAnggaranForm:Anggaran", thus two components to process. If you omit @this but keep the other component, then it will only process/execute the other component and not the link/button component. If you omit the process attribute it will default to @form. If you have more other input components in the same form, then they will also be processed.

Depending on the concrete functional requirement, you could just keep it process="@this infoAnggaranForm:Anggaran", or omit it. JSF will then process/execute at least both the button and the other component, exactly as you want.

See also:

  • Understanding PrimeFaces process/update and JSF f:ajax execute/render attributes
like image 193
BalusC Avatar answered Nov 01 '22 13:11

BalusC