我使用 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>

在目标页面,则可以从参数映射读取的ID,或者直接使用表达式语言或经由托管Bean。

查看:

<f:view>
    id= <h:outputText value="#{param['id']}" />
    <br />
    id= <h:outputText value="#{lookupBean.id}" />
</f:view>

豆:

public class LookupBean implements Serializable {

    public String getId() {
        FacesContext context = FacesContext.getCurrentInstance();
        ExternalContext extContext = context.getExternalContext();
        Map<String, String> params = extContext.getRequestParameterMap();
        return params.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>

其他提示

我使用A4J:commandlink先通过我要显示为到详细视图豆细节的实体的ID。然后我简单地使用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>

从 LinkBut​​ton 参数执行方法

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top