English 中文(简体)
如何获取查询字符串 URL 参数, 支持豆的页面负荷?
原标题:How do I process GET query string URL parameters in backing bean on page load?

我读过如何使用 JSF 发送参数,但如果用户在访问登录页面时在 URL 中输入他们的 corpitationId 。 例如,

http://my.corporation.url/productName/login.faces?companyId=acme" rel="noreferrer" >http://my.corporation.url/productName/login.faces?companyId=acme

我们现在这样做的方式是, 有一些脚本代码从请求中抓取值, 然后在会话中设置它。 该参数会改变它们的外观和感觉, 从登录页面开始, 这样每个客户可以有一个不同的登录页面视图 。 我们使用 extjs, 直到我切换到 JSF 。

有没有办法用JSF 2或可能用PrimeFaces来做?

最佳回答

是的,您可以使用 < a href=""http://docs.oracle.com/javaee/6/javaserverfaces/2.1/docs/vdldocs/f/viewParam.html" rel="noreferr"\\code_lt;f:viewParam> 将请求参数设定为管理过的豆的属性。

<f:metadata>
    <f:viewParam name="companyId" value="#{bean.companyId}" />
</f:metadata>

您可以使用 (JSF2.2+) 或 援引一个豆的动作。

<f:metadata>
    <f:viewParam name="companyId" value="#{bean.companyId}" />
    <f:viewAction action="#{bean.onload}" />
</f:metadata>

使用 时,您甚至可以返回导航结果 。

public String onload() {
    // ...

    return "somepage";
}

在JSF2.2尚未公布时,您可以使用 < a href="http://docs.oracle.com/javaee/6/api/javax/faces/context/ExternalContext.html#redirect(java.lang.String)" rel=“nreferrer”\code>ExternalCtext#redirect () 。请参见What can <f:metadata>, <f:viewParam> and <f:viewAction> be used for?

  • Communication in JSF 2.0 - Processing GET request parameters
  • @ManagedProperty with request parameter not set in a @Named bean
  • 问题回答

    url 参数参数也可以作为请求参数处理,这样您也可以通过

    FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap()
    

    有一个公共图书馆,"http://showcase.omnifaces.org/cdi/Param" rel="noreferrer">OmniFaces ,在盒子里可以做到这一点。

    @Inject @Param
    private String key;
    
    @Inject @Param
    private Long id;
    

    如果您想要获得完整的查询参数字符串, 您可以使用 request.getQueryString ()





    相关问题
    JSF a4j:support with h:selectManyCheckbox

    I m having trouble with a JSF selectManyCheckbox and A4J support. The purpose is to run some action when a checkbox is selected. This works perfectly in Firefox. Yet, when testing in any IE (ie6 / ie7 ...

    Mojarra for JSF Encoding

    Can anyone teach me how to use mojarra to encode my JSF files. I downloaded mojarra and expected some kind of jar but what i had downloaded was a folder of files i don t know what to do with

    如何拦截要求终止?

    在共同基金中,如果用户要求终止,就需要采取一些行动。 我需要某种拦截器,但我不知道如何这样做。 我需要帮助。 增 编

    ICEFaces inputFile getting the file content without upload

    Is there any way of just getting the content of the browsed file without any upload/file transfer operations? I currently use ICEFaces inputFile component but I do not need the default uploading ...

    Weird behaviour of h:commandLink action (MethodExpression)

    I have two JSPs where I am displaying some info from database in a h:dataTable. One of them is showing all the info, and one of them user specifically. I have showXML.jsp that shows the "XML" column ...

    How to correctly use ResultSet with h:dataTable

    The problem is, that after displaying the ResultSet with <h:dataTable>, the connection is left open. If I close it, it closes the ResultSet too. I m thinking about copying the ResultSet data ...

    热门标签