如何正确地从JSF中的URL获取参数? [英] How to get parameters from the URL in JSF properly?

查看:172
本文介绍了如何正确地从JSF中的URL获取参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我相信有两种方法可以从JSF中的URL获取参数.

I believe there are 2 ways to get the parameters from the URL in JSF.

一个在豆子里:

Map<String, String> params =FacesContext.getCurrentInstance().
                   getExternalContext().getRequestParameterMap();
String parameterOne = params.get("parameterOne");

另一个在facelets页面中

and the other one being in the facelets page

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

很显然,后一个将在类中需要一个字段并为其进行getter/setter设置.

Obviously the latter one will require a field in the class and getter / setter for it.

此外,这两种不同方法之间有什么区别?应该首选哪一个?

Besides that, what are the differences between these 2 different approaches? Which one should be preferred?

推荐答案

我认为这可能会有所帮助: 从JSF页面获取请求和会话参数及属性

I think this may help: Get Request and Session Parameters and Attributes from JSF pages

实际上,应该有一个查询:

In fact, there should be a query:

<h:outputText value="#{param['id']}" />

这篇关于如何正确地从JSF中的URL获取参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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