Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
579 views
in Technique[技术] by (71.8m points)

jsf - 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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...