我可以“通过”吗?一个带有JSF参数标记的对象? [英] Can I "pass" an object with a JSF param tag?

查看:141
本文介绍了我可以“通过”吗?一个带有JSF参数标记的对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找的是在value属性中使用我自己选择的对象的f:param标记。然后,在操作的支持bean方法中,我希望能够从请求中提取此Object。 (对不起,如果我的术语不太好,我是JSF的新手。)

What I'm looking for is to have an f:param tag with an Object of my own choosing in the value attribute. Then, in the backing bean method for the action, I would like to be able to pull this Object from the request. (Sorry if my terminology isnt so good, I'm new to JSF).

现在,我可以在请求参数中传递Strings就好了。我也意识到一个参数总是在http get或post中成为一个String,所以我不是真的传递一个java对象。我也意识到,这样做的一种方法是传递某种id,然后支持bean可以使用它来识别有问题的对象。

Now, I can pass Strings around in request parameters just fine. I also realize that a parameter is always going to be a String in the http get or post, so I'm not really passing a java object. I also realize that a way to do this would be to pass an "id" of some kind which the backing bean could then use to identify the Object in question.

然而,我想知道JSF是否允许我透明地执行此操作。我可以指定任何对象作为参数的值,然后在动作方法中从RequestMap中获取它吗?

What I'm wondering, however, is if JSF will allow me to do this transparently. Can I specify any object as the value of the param and then just fetch it from the RequestMap in an action method?

推荐答案

你不能用< f:param> 来做到这一点。它需要附加到请求的URL,因此它确实需要是 String 。只需使用 < f: setPropertyActionListener> 代替。

You can't do that with <f:param>. It needs to be appended to the URL of the request, so it really needs to be a String. Just use <f:setPropertyActionListener> instead.

例如

<h:commandLink value="Submit" action="#{bean.submit}">
    <f:setPropertyActionListener target="#{bean.otherBean}" value="#{otherBean}" />
</h:commandLink>

这样#{otherBean} 是只需 this.otherBean 提交()方法中。这样你也不需要弄乱请求参数映射(对于< f:param> ,我宁愿使用托管属性使用#{param.name} 代替注入

This way the #{otherBean} is just available as this.otherBean inside submit() method. This way you also don't need to mess with the request parameter map (for which in case of <f:param> I would rather have used managed property injection with #{param.name} instead).

替代方案正在使用 < h:inputHidden> 结合转换器或使用Tomahawk's < t:saveState> 。有关更多背景信息和示例,请参阅此博客文章

Alternatives are using <h:inputHidden> in combination with a Converter or using Tomahawk's <t:saveState>. Also see this blog article for more background info and examples.

这篇关于我可以“通过”吗?一个带有JSF参数标记的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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