0

我正在使用 JSF。当我提交表单时——来自 JSF 标记(如 h:inputText)的数据以某种方式在请求中传递给服务器。我不知道 JSF 如何在请求参数或属性上重写它(我什至不熟悉 http 请求)。我只知道如何使用“el”语言。但是现在我必须在提交请求中添加一个字符串,这是一种允许我在过滤器中读取该字符串的方法。所以我想以某种方式使用JSF标签(可能是inputHidden)来设置具有固定名称(如“MySecretToken”)的http请求参数,然后在过滤器中我可以写:

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

HttpServletRequest httpRequest = (HttpServletRequest) request;

if ( isTokenValid( httpRequest.getParameter("MySecretToken") ))
     doThis(...);
else
     doThat(...);

     chain.doFilter(request, response);
}

所以问题是“如何使用JSF标签(可能是inputHidden)来设置具有固定名称的http请求参数?”。

4

1 回答 1

2

Easiest way is to use the <f:param> in <h:commandXxx> component. It basically adds a HTTP request parameter with exactly the specified name and value.

<h:commandButton ...>
    <f:param name="MySecretToken" value="#{bean.mySecretToken}" />
</h:commandButton>

A more JSF-ish way would be to create a custom component for the job. E.g. <my:token />. You could even create a custom component event listener which automagically adds this custom component to the form everytime.

于 2013-01-18T14:04:07.573 回答