JSF 访问支持地图对象
我有一个 jsp 子视图页面,我已向该页面传递了一个参数,然后我想将该参数传递给存储在会话 bean 中的地图的 get() 方法。
例如:
<h:panelGrid id="panelGrid1" rendered="#{MySessionBean[param.id].showPanelGrid1}">
...
</h:panelGrid>
在上面的示例中,MySessionBean 实现了 Map 接口,并且我有自己的自定义 get 方法,该方法将创建一个对象并将其放入映射中(如果不存在键 [params.id])。当我在调试模式下运行代码时,我的 MySessionBean 的 get 方法永远不会被调用,并且我的面板始终会呈现。是我参数传递不正确吗?或者正确访问传递给子视图的参数?
以下是我将参数传递给此子视图的方法:
<f:subview id="subview1">
<jsp:include page="/MyTemplatePage.jsp">
<jsp:param name="id" value="staticUniqueId1"/>
</jsp:include>
</f:subview>
我尝试这样做的原因是这样我可以在单个页面中多次包含此模板子视图,以便每个实例不会具有相同的支持 bean 对象。因此,在会话中使用映射并向其传递 id 来获取对每个实例的支持 bean 的访问权限。
另外,我仅限于 JSF 1.2、JSTL 1.1、JBoss 4.0.4。因此,我无法使用使用 RichFaces 或 JSF 2 的答案。
编辑:11/11/22 11:23
我将 [param.id] 替换为静态字符串值。
<h:panelGrid id="panelGrid1" rendered="#{MySessionBean.MY_TEMP_VAL.showPanelGrid1}">
...
</h:panelGrid>
一切顺利。它触发了我的地图获取方法并访问了会话 bean 和所有内容。所以它显然不喜欢使用 [params.id] 传递给地图对象的整体。不知道从这里该做什么。
I have a jsp subview page that I have passed a parameter to and I want to then pass that parameter to a map's get() method that is stored in a session bean.
Ex:
<h:panelGrid id="panelGrid1" rendered="#{MySessionBean[param.id].showPanelGrid1}">
...
</h:panelGrid>
In the above example MySessionBean implements the Map interface and I have my own custom get method that will create an object and put it in the map if none exists for the key [params.id]. When I run the code in debug mode my get method for MySessionBean never gets called and my panel is always rendered. Am I not passing parameters correctly? Or accessing the parameter passed to the subview correclty?
Here is how I passed the parameter to this subview:
<f:subview id="subview1">
<jsp:include page="/MyTemplatePage.jsp">
<jsp:param name="id" value="staticUniqueId1"/>
</jsp:include>
</f:subview>
The reason I'm trying to do this is so I can include this template subview multiple times in a single page so that each instance won't have the same backing bean objects. Thus using a map in the session and passing it an id to gain access to the backing beans for each instance.
Also, I am limited JSF 1.2, JSTL 1.1, JBoss 4.0.4. So I can't use answers that use RichFaces or JSF 2.
EDIT: 11/22/11 11:23
I Replaced the [param.id] with a static string value.
<h:panelGrid id="panelGrid1" rendered="#{MySessionBean.MY_TEMP_VAL.showPanelGrid1}">
...
</h:panelGrid>
And everything worked. It triggered my map get method and accessed the session beans and everything. So it is clearly not liking the whole using [params.id] passing to the map object. Not sure what to do from here.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 JSF2 中,正确且简单的解决方案是使用复合组件。由于您受困于 JSF 1.2 和 jsp,您可以使用 标记文件 相反。它们与常规 jsps 类似,但具有扩展名
tag
或tagx
并放置在WEB-INF/tags
下。我在下面的示例中使用 xml 语法,文件名为example.tagx
:在 jspx 中,您必须声明命名空间,如
xmlns:myTags="urn:jsptagdir: /WEB-INF/tags/"
,在 jsp 中,语法如下:自定义标签可以在页面上多次使用,并且右支持 bean 可以作为属性传递,如下所示:
编辑:您可能还需要一个文件
WEB-INF/tags/implicit.tld
来指定版本:In JSF2 the proper and easy solution would be to use composite components. Since you are stuck with JSF 1.2 and jsp you could use tag files instead. These are like regular jsps but with the extension
tag
ortagx
and placed underWEB-INF/tags
. I'm using the xml syntax in the example below, in a file nameexample.tagx
:In a jspx you then have to declare the namespace like
xmlns:myTags="urn:jsptagdir:/WEB-INF/tags/"
, in a jsp the syntax would be:The custom tag can then be used multiple times on a page and the right backing bean can be passed as an attribute like this:
Edit: You might also need a file
WEB-INF/tags/implicit.tld
to specify the version: