retrieve GET parameter in a request bean

Nargzul
Nargzul used Ask the Experts™
on
Hi!

I have a page accessed by a link into an email.

How can I retrieve a GET parameter from my Request Bean?

Thank you!
(I use JSF/JSP under a glassfish server with netbeans)
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016

Commented:
Why not store it in the request map and have your bean access that?

Author

Commented:
I'm sorry, I don't understand what you mean.

request map == face-config?

The url in the email will be something lik

http://myWebSite.com/MyPage.jsf?idDeal=3517&authKey=341AFE80CFB419750D

I want to have a direct access to this page.
Top Expert 2016

Commented:
>>request map == face-config?

request.setAttribute("x", y);

JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

Author

Commented:
>>request.setAttribute("x", y);
How do we get this object?

Email are in a mail, I don't think it works and they aren't sent from the same server(and it's not a J2EE server).
Top Expert 2016

Commented:

Author

Commented:
You don't really help here...

When must I use this?
What do I write in the email?
Is this really done for JSP/JSF?(because I see always "servlet" in the javadoc)
How do I get this ExternalContext?

Why is it so complicated???
It's just amazing, I only want to retrieve a Get variable. In php it's only a $_GET['my_var_name'], in .NET it's only a Request.QueryString("parameter1")
Top Expert 2016

Commented:
The difference is you're using multi-layered technologies. PHP is shallow in comparision. Exactly what layer of your app are you in? If you have access to the request object, then of course it's equally easy

Author

Commented:
Theses layer must simplify the development no?

I'm in a Bean with a Request scope, in a getter of one attribut of my bean.

Top Expert 2016

Commented:
>>Theses layer must simplify the development no?

No, that's not the objective. They actually make it more complex. The objective is to increase reusability and scalability

A bean is not meant to have circular references to the request, hence your problem. You would be better to rethink the design, but a kludge would be to pass the request into the bean

Author

Commented:
But say me how I can do it differently?

I need to have:
-a link from an email
-can load an object corresponding to the given ID in my RequestBean
Top Expert 2016

Commented:
So the user clicks on a link in an email?

>>can load an object corresponding to the given ID in my RequestBean

What object?

Author

Commented:
It's an Entity object, I've a facade(session bean) to load it
    @EJB
    private MatchFacadeRemote matchfac;
 
    public Match getMatchToReview() {
        if(matchToReview == null){
            int idMatch = xxxxxx;//here we get this object
            matchToReview = matchfac.find(idMatch);
        }
        return matchToReview;
    }

Open in new window

Top Expert 2016

Commented:
What is the first thing that gets hit when the user clicks on the link in the email? Do you have jsp, servlet or what?

Author

Commented:
It's a JSP page

Author

Commented:
Yeah it's an email, it was specified in the first message ;)
Top Expert 2016

Commented:
In that case it would be e.g.
String authKey = request.getParameter("authKey");

Open in new window

Author

Commented:
I've try but I don't have this request var
Top Expert 2016

Commented:
That's *always* present in a jsp

Author

Commented:
I'm confuse, I've responded to fast to your question, I've only JSF pages
Top Expert 2016

Commented:

Author

Commented:
I've tried to create an ExternalContext, but it's an abstract class.

I've created a FaceContext, but there isn't any getRequestMap on this method.

I've check there isn't any :

get***Map() on the ExternalContext
Top Expert 2016

Commented:
You need to read the link i posted to you - it tells you exactly what to do

Author

Commented:
Okay,

So I've try to do mixes, but when I call the page like this:
http://localhost:8080/TrustBN-war/faces/ReviewExchange.jsp?idReview=120938120839

I get a null in my code
FacesContext context = FacesContext.getCurrentInstance();
String idReview = (String)context.getExternalContext().getRequestMap().get("idReview");
System.out.println(idReview);

Open in new window

Top Expert 2016
Commented:
That should be
String idReview = (String)context.getExternalContext().getRequestParameterMap().get("idReview");

Open in new window

Author

Commented:
Yeah it works

Thank you sooo much!
Top Expert 2016

Commented:
:-)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial