Jsf 使用请求参数打开详细信息视图

Jsf 使用请求参数打开详细信息视图,jsf,richfaces,myfaces,Jsf,Richfaces,Myfaces,我使用myfaces和richfaces创建了一个简单的主/细节。通过单击rich:dataTable中的h:commandLink,用户可以打开详细视图并编辑实体 现在我想创建一个允许用户直接打开细节视图的URL。通常我会通过创建一个像/detail.jsp?id=12这样的URL来实现这一点-我如何用JSF实现这一点 您可以使用链接控件上的参数构造URL: <h:outputLink value="reqscope.faces"> <f:param

我使用myfaces和richfaces创建了一个简单的主/细节。通过单击rich:dataTable中的h:commandLink,用户可以打开详细视图并编辑实体


现在我想创建一个允许用户直接打开细节视图的URL。通常我会通过创建一个像/detail.jsp?id=12这样的URL来实现这一点-我如何用JSF实现这一点

您可以使用链接控件上的参数构造URL:

    <h:outputLink value="reqscope.faces">
        <f:param name="id" value="#{row.id}" />
        <h:outputText value="link" />
    </h:outputLink>

在目标页面上,您可以直接使用表达式语言或通过托管bean从参数映射中读取id

视图:


id=

id=
豆子:

公共类LookupBean实现可序列化{
公共字符串getId(){
FacesContext context=FacesContext.getCurrentInstance();
ExternalContext=context.getExternalContext();
Map params=extContext.getRequestParameterMap();
返回参数get(“id”);
}
}
faces-config.xml声明:

<managed-bean>
    <managed-bean-name>lookupBean</managed-bean-name>
    <managed-bean-class>reqscope.LookupBean</managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
</managed-bean>

长相的
reqscope.LookupBean
要求

我使用a4j:commandlink首先将要显示详细信息的实体的id传递给详细视图bean。然后我只需使用document.location导航到视图

<a4j:commandLink action="#{detailviewBean.setDetailID(entity.someid)}" value="#{entity.someid}" oncomplete="document.location='/app/detailview.seam'"/>

如果您使用的是JSF 1.2,那么可以使用f:setPropertyActionListener:

<h:commandLink action="#{reqscope.faces}">
    <h:outputText value="link"/>
    <f:setPropertyActionListener 
        value="#{id}" 
        target="#{lookupBean.id}"/>
</h:commandLink>

<a4j:commandLink action="#{detailviewBean.setDetailID(entity.someid)}" value="#{entity.someid}" oncomplete="document.location='/app/detailview.seam'"/>
<h:commandLink action="#{reqscope.faces}">
    <h:outputText value="link"/>
    <f:setPropertyActionListener 
        value="#{id}" 
        target="#{lookupBean.id}"/>
</h:commandLink>