Question

I have am using JSF. When I am submitting a form - the data from JSF tags (like h:inputText) are somehow passed in request to the server. I do not know how JSF rewrites it on request parameters or attributes (I not even that familiar with http request). I just know how to use 'el' langue. But now I have to add to a submit request a string, I a way that allow me read that string in a filter. So I want somehow use JSF tags (probably inputHidden) to set http request parameter with a fixed name (like "MySecretToken"), then In filter I could write:

@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);
}

So the problem is "How use JSF tags (probably inputHidden) to set http request parameter with a fixed name?".

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top