Faces in ADF can't get the request parameters

2019-09-16 16:22发布

问题:

I have an ADF web application with Faces 1.2

In my managed bean I am trying to access the parameters of the post request, but always getting null.

This is my post form that I am posting to the Faces:

<form name="input" action="http://127.0.01:7072/myapplication/faces/login.jspx" method="post">
   <input type="hidden" name="user" id="user" value="myUserName"/>
   <input type="submit" value="Submit"/>
</form>

FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("user");

FacesContext.getCurrentInstance().getExternalContext().getRequest().getParameter("user");

But I always get null and the method of the form I get is: GET, strange!

回答1:

when you make a request for a URL like:

http://server/faces/somepage.jspx

ADF framework respone you by a "HTTP Error 302 Moved temporarily" response and redirect you to the URL like :

http://server/faces/somepage.jspx?_adf.ctrl-state=888888&_afrLoop=9999999

so your first POST request is omit and browser send an other request to the new URL that ADF returned in response, so because POST method send parameter in the request body the browser dont resend them in new Get request so i think there is no way for you to get parameters direcly in side the ADF page ! :(

but i think the best way is to create a Servlet and get you param in it and put them to session and then redirect the user from servlet to your ADF page :)



回答2:

I managed reading the request parameters through including my parsing operations in the filter mappings that my application was using.

In a very abnormal way FacesContext always rejected revealing the current parameters, till now it's a mystery for me why it's designed liked that, even through its external context ...