@this到底有什么作用?
据我所知,@this是表示当前触发事件的组件,例如:
<p:commandButton process="@this" ... />
在JSF 2 Ajax中,@this也可以表示封装组件,例如:
<h:inputText ...>
<f:ajax execute="@this" ... />
</h:inputText>
我有一种情况,使用 p:datatable,包括或排除 @this 会对 Ajax 部分提交产生不同的影响
这是示例,在本例中,该流程正在使用@this,并且这按预期工作,其中当流程首先发生时,然后是setPropertyActionListener,最后是操作已执行:
<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 永远不会执行,就好像它们没有执行一样那里。
我想知道为什么?也许 @this 除了当前组件之外还有其他含义,也许是本例中的当前记录?
我使用 tomcat 7,这些是我的依赖项:
<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>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
PrimeFaces
process
和标准 JSFexecute
属性应该指向组件的空格分隔的组件标识符,JSF 在整个 JSF 生命周期中应根据 ajax 请求处理这些组件(获取请求参数,验证它们) ,更新模型,执行动作)。process
默认为@form
(当前表单),execute
默认为@this
(当前组件) 。在命令链接/按钮中,这是执行与链接/按钮本身关联的操作所必需的。但是,在您的数据表中,您有
process="@this infoAnggaranForm:Anggaran"
,因此需要处理两个组件。如果省略@this
但保留其他组件,那么它将仅处理/执行其他组件,而不是链接/按钮组件。如果省略process
属性,它将默认为@form
。如果同一表单中有更多其他输入组件,那么它们也将被处理。根据具体的功能需求,您可以保留它
process="@this infoAnggaranForm:Anggaran"
,也可以省略它。然后,JSF 将至少按照您的需要处理/执行按钮和其他组件。另请参阅:
The PrimeFaces
process
and standard JSFexecute
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). Theprocess
defaults to@form
, the current form, and theexecute
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 theprocess
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: