Java JSF-重定向到页面并记住用于搜索的参数ID

Java JSF-重定向到页面并记住用于搜索的参数ID,java,jsf,richfaces,Java,Jsf,Richfaces,我有两个xhtml页面和两个托管bean 在第一页,我有一个主题列表(来自数据库表的记录-第二列包含标记): 部分简化代码: <rich:column><h:outputText value="#{item.id}"/></rich:column> <rich:column><h:outputText value="#{item.createdBy}"/></rich:column> <rich:column>

我有两个xhtml页面和两个托管bean

在第一页,我有一个主题列表(来自数据库表的记录-第二列包含
标记):

部分简化代码:

<rich:column><h:outputText value="#{item.id}"/></rich:column>
<rich:column><h:outputText value="#{item.createdBy}"/></rich:column>
<rich:column>
  <h:commandLink value="#{item.topic}" action="#{myTools.setMenuItem('posts')}"/>
</rich:column>
但是我仍然不知道如何将
topic.getId()
参数传递给另一个bean(MyPosts)


在commandLink中。

您可以添加一个隐藏字段,在提交之前将ID存储在该字段中(在Javascript中使用
onclick
),并将该隐藏字段绑定到Bean中的变量

<h:inputHidden id="selectedId" value="#{beakbean.selectedId}">

<h:commandLink value="#{item.topic}" onclick="updateSelectedId()" action="#{myTools.setMenuItem('posts')}"/>

function updateSelectedId(){
    //put the selected id in the field selectedId
}

函数updateSelectedId(){
//将所选id放入selectedId字段
}
也把它传过去

例如



bean不需要也不应该在会话范围内。视野很好。否则,在多个浏览器选项卡/窗口中与同一页面交互时,最终用户将面临不直观的行为。

谢谢你,凯,这真的很有效!我的帖子必须是sessionscope,而不是viewscope。谢谢你,巴卢斯克,我也尝试过类似的方法,但当我使用
menuItem+“?faces redirect=true&id=“+id
,我不知道如何在bean MyPosts中使用参数
id
。?在目标视图
posts.xhtml
中使用
,或在目标bean
MyPosts
中使用
@ManagedProperty
。另见
<h:inputHidden id="selectedId" value="#{beakbean.selectedId}">

<h:commandLink value="#{item.topic}" onclick="updateSelectedId()" action="#{myTools.setMenuItem('posts')}"/>

function updateSelectedId(){
    //put the selected id in the field selectedId
}
public String navigate(String menuItem, Long id) {
    this.menuItem = menuItem;
    return menuItem + "?faces-redirect=true&id=" + id;
}