如何调用有条件呈现的UICommand组件的操作方法? [英] How to call an action method of a UICommand Component which was rendered conditionally?
问题描述
操作方法未调用请参考此问题- ,我的UICommand组件之一是有条件地渲染的,在链接的问题5的回答中说-如果该组件或其任何父代的渲染或禁用属性为假,那么不会调用action方法吗?如果是这样,我如何实现相同的功能?有没有解决的办法?还是一个把戏?或其他任何方法?
action method is not called Please refer to this question - , One of my UICommand Component is rendered conditionally , it was said in the answer of the linked question - point 5 - that if the Component's or any of its parents rendered or disabled attributes are false - then the action method will not be called ? If thats the case- How do i achieve the same functionality? Is there a work around ? or a trick ? or any other approach ?
谢谢!
推荐答案
至此,您希望在后续请求中保留负责rendered
条件的属性.有几种解决此问题的方法:
To the point, you'd like to retain the property responsible for the rendered
condition in the subsequent request. There are several solutions for this problem:
-
将bean放入会话范围.这很容易,但是很痛.这对用户体验不利,因为更改将反映在用户在同一会话中打开的所有选项卡/窗口中.
Put bean in session scope. It's easy, but it hurts. It's bad for user experience since changes will be reflected in all tabs/windows the user has open in the same session.
使用<h:inputHidden>
传输属性.从理论上讲很容易,但是在实践中它也会带来伤害.每当以相同形式出现的任何其他输入中发生验证/转换错误时,该值即会丢失.这是JSF处理隐藏输入元素的方式的一个奇怪之处.一种解决方法是使用<h:inputHidden binding="#{bean.hidden}">
并在bean中执行hidden.getValue()
和hidden.setValue()
.
Use <h:inputHidden>
to transfer the property. In theory easy, but in practice it hurts as well. The value will namely get lost whenever a validation/conversion error has occurred in any of other inputs in the same form. This is an odditity in how JSF handles hidden input elements. A workaround is to use <h:inputHidden binding="#{bean.hidden}">
and do a hidden.getValue()
and hidden.setValue()
in bean.
如果使用的是<h:commandLink>
而不是<h:commandButton>
,则可以使用<f:param>
来传输属性.它可以作为request参数使用,您可以在bean的(post)构造函数中进行检查.
If you're using <h:commandLink>
instead of <h:commandButton>
, then you can use <f:param>
to transfer the property. It will be available as request parameter, you can check for it in bean's (post)constructor.
使用 Tomahawk的
Use Tomahawk's <t:saveState>
. The perfect solution as far. This will retain the value (or even a complete bean) in the subsequent request.
如果您已经在使用JSF 2.0,则 @ViewScoped
可以解决所有问题.它的行为类似于<t:saveState>
.
If you're already on JSF 2.0, the @ViewScoped
would have solved this all. It behaves like the <t:saveState>
.
这篇关于如何调用有条件呈现的UICommand组件的操作方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!