Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Mike Harris
Query String parameters question
August 30, 2011 10:21 AM
Answer

Mike Harris

Rank: Junior Member

Posts: 91

Join Date: March 28, 2011

Recent Posts

I'm able to access parameters that are in the query string by getting the original request and using ParamUtil.getParameter().
But, I'd like to know if the parameter is coming from the query string or was posted from a form...

Is there a way to do this?
Jay Patel
RE: Query String parameters question
August 30, 2011 11:31 PM
Answer

Jay Patel

Rank: Regular Member

Posts: 116

Join Date: February 23, 2010

Recent Posts

Mike Harris:
I'm able to access parameters that are in the query string by getting the original request and using ParamUtil.getParameter().
But, I'd like to know if the parameter is coming from the query string or was posted from a form...

Is there a way to do this?



Hi Mike,
I guess you may give a try to following code:

HttpServletRequest httpRequest = PortalUtil.getHttpServletRequest(renderRequest);
HttpServletRequest request = PortalUtil.getOriginalServletRequest(httpRequest);
String queryString = request.getQueryString();
if(queryString.contains("yourParameter")){
// do your stuff..
}

Hope this helps...

Cheers..
Jay.
Hitesh Dangi
RE: Query String parameters question
August 31, 2011 12:57 AM
Answer

Hitesh Dangi

Rank: New Member

Posts: 11

Join Date: December 13, 2010

Recent Posts

I think you can check the given request's method..either it's a POST or GET and read parameter and confirm that how it's comming...from queryParam or as a form.

HttpServletRequest httpRequest = PortalUtil.getHttpServletRequest(request);
String httpMethodName=httpRequest.getMethod();

Thanks
Mike Harris
RE: Query String parameters question
August 31, 2011 10:23 AM
Answer

Mike Harris

Rank: Junior Member

Posts: 91

Join Date: March 28, 2011

Recent Posts

Hi Jay!

I put this in my controller (I'm using Spring MVC) :

1HttpServletRequest httpRequest = PortalUtil.getHttpServletRequest(renderRequest);
2        HttpServletRequest request = PortalUtil.getOriginalServletRequest(httpRequest);
3        String queryString = request.getQueryString();
4        System.out.println(queryString);


The only thing that is ever printed is p_l_id=11745 even if I have a tons of query string parameters. I don't know if it's a problem with spring or LR or the portlet model but it doesn't seems to work. emoticon
Mike Harris
RE: Query String parameters question
August 31, 2011 10:30 AM
Answer

Mike Harris

Rank: Junior Member

Posts: 91

Join Date: March 28, 2011

Recent Posts

Hello Hitesh,
It works to check if the request is a GET or a POST but I would need to know each individual parameters where they are comming from. Some parameters are needed in the query string and others are not.
Basically, I'm trying to make a "language switch" link and it kinda repost each form. For example, if I just paid something then switch the language, it will repost the datas to the controller.
Jay Patel
RE: Query String parameters question
September 12, 2011 2:41 AM
Answer

Jay Patel

Rank: Regular Member

Posts: 116

Join Date: February 23, 2010

Recent Posts

Mike Harris:
Hi Jay!

I put this in my controller (I'm using Spring MVC) :

1HttpServletRequest httpRequest = PortalUtil.getHttpServletRequest(renderRequest);
2        HttpServletRequest request = PortalUtil.getOriginalServletRequest(httpRequest);
3        String queryString = request.getQueryString();
4        System.out.println(queryString);


The only thing that is ever printed is p_l_id=11745 even if I have a tons of query string parameters. I don't know if it's a problem with spring or LR or the portlet model but it doesn't seems to work. emoticon


Bingo,

then it means that it is coming from form using POST.

Cheers,
Jay.