如何将参数从ManagedBean转移到jsf页面 [英] how to transfer parameter from managedbean to a jsf page

查看:97
本文介绍了如何将参数从ManagedBean转移到jsf页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将参数从jsf页面传输到另一个jsf页面.像这样:

I want to transfer a parameter from a jsf page to another jsf page. Like this:

a.xhtml

<h:form>
    <h:commandLink class="navi" value="press"
               action="#{Bean.action}">
        <f:param name="id" value="5555" />
    </h:commandLink>
</h:form>

Bean.java

Bean.java

public String action() {
    HttpServletRequest request = (HttpServletRequest) FacesContext
            .getCurrentInstance().getExternalContext().getRequest();
    String param = request.getParameter("id");
    return "b?id=" + param;
}

b.xhtml

<h:inputText value=#{param.id} />

按照以前的方式,我将id从a.xhtml传输到b.xhtml,但是由于以下这一行,我不想在外部公开"... b.xhtml?id = 5555"之类的参数:

By previous way, I transfer id from a.xhtml to b.xhtml, but I don't want to expose the parameter like "...b.xhtml?id=5555" outside because of this line:

return "b?id=" + param;

ManagedBean的范围是请求.我该怎么解决这个问题?谢谢.

And the scope of ManagedBean is request. How can I do to solve this problem? Thanks.

推荐答案

您也可以尝试 viewParam

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

它基本上执行以下操作:

It does basically the following:

  • 通过名称ID获取请求参数值.
  • 如有必要,对其进行转换和验证(您可以使用必填属性,验证器和转换器属性,并像一样将a和嵌套在其中)
  • 如果转换和验证成功,则将其设置为由#{bean.id}表示的bean属性.

您可以在结果链接上传递ID(例如,b.xhtml?id = 1),然后在任何托管Bean上检索它.

You could pass the id on outcome link (b.xhtml?id=1, for example) and retrieve it on any Managed Bean.

这篇关于如何将参数从ManagedBean转移到jsf页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆