@this的功能到底是什么? [英] What is the function of @this exactly?

查看:508
本文介绍了@this的功能到底是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知, @this 表示触发事件的当前组件,例如:

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

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

在JSF 2 Ajax中, @this 也可以表示封装组件,例如:

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

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

我有一种情况,使用 p:datatable ,包括或排除 @this 会对Ajax部分提交产生不同的影响

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

这里是示例,在这种情况下,该过程使用 @this ,并且按预期工作,首先发生过程,然后是 setPropertyActionListener ,然后最后,执行操作:

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>

但是,当我在此示例中省略 @this 时,将不会执行 setPropertyActionListener action ,就好像它们没有执行一样在那里.

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

我想知道为什么吗?也许 @this 除了当前组件(在本示例中为当前记录)以外还有其他含义?

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

我正在使用tomcat 7,这些是我的依赖项:

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>

推荐答案

PrimeFaces process和标准JSF execute属性应指向以空格分隔的组件标识符,这些组件标识符应ajax请求在整个JSF生命周期中处理. (获取请求参数,对其进行验证,更新模型,执行操作). process默认为@form(当前形式),execute默认为@this(当前形式).在命令链接/按钮中,这是执行与链接/按钮本身关联的操作所必需的.

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.

但是,在数据表中有process="@this infoAnggaranForm:Anggaran",因此有两个要处理的组件.如果省略@this但保留其他组件,则它将仅处理/执行其他组件,而不处理/执行链接/按钮组件.如果省略process属性,则默认为@form.如果您还有更多其他形式相同的输入组件,则也将对其进行处理.

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.

根据具体的功能要求,您可以保留它process="@this infoAnggaranForm:Anggaran"或忽略它.然后,JSF会完全根据您的需要至少处理/执行按钮和其他组件.

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.

这篇关于@this的功能到底是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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