代码之家  ›  专栏  ›  技术社区  ›  Thomas Einwaller

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

  •  4
  • Thomas Einwaller  · 技术社区  · 17 年前

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

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

    3 回复  |  直到 17 年前
        1
  •  2
  •   McDowell rahul gupta    17 年前

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

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

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

    视图:

    <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>
    
        2
  •  0
  •   Powertieke    17 年前

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

    <a4j:commandLink action="#{detailviewBean.setDetailID(entity.someid)}" value="#{entity.someid}" oncomplete="document.location='/app/detailview.seam'"/>
    
        3
  •  0
  •   hkn    17 年前

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

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

    Executing Methods From LinkButton Parameters

    推荐文章