@this 的功能究竟是什么? [英] What is the function of @this exactly?
问题描述
据我所知@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
属性应该指向 JSF 应该使用的以空格分隔的组件标识符在 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屋!