Fóruns

Início » Liferay Portal » English » 3. Development

Visualização combinada Visão plana Exibição em árvore
Tópicos [ Anterior | Próximo ]
toggle
Koshy Abraham
How do I read parameters from a query string in JSF/Facelets portlet
25 de Março de 2010 17:32
Resposta

Koshy Abraham

Ranking: New Member

Mensagens: 3

Data de entrada: 30 de Janeiro de 2008

Mensagens recentes

I have created a page in Liferay (e.g. http://localhost:8080/web/guest/bookingpage) containing a single Facelets portlet. I would like to be able to go directly to that page from another page or link and pass in some parameters as a query string (e.g. http://localhost:8080/web/guest/bookingpage?mfbStartDate=20081111&mfbEndDate=20081112).

I have tried to read the parameters passed in using a few different methods like using the managed bean declaration in the faces-config.xml

e.g.
<managed-bean>
<description>
BookingHome is the portlet entry point and process the query string passed in
</description>
<managed-bean-name>bookingHomeBean</managed-bean-name>
<managed-bean-class>com.rehotels.mayfairweb.bookingportlet.webui.BookingHomeBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>mfbStartDate</property-name>
<value>#{param.mfbStartDate}</value>
</managed-property>
<managed-property>
<property-name>mfbEndDate</property-name>
<value>#{param.mfbEndDate}</value>
</managed-property>
</managed-bean>

and also going through the faces context:


FacesContext context = FacesContext.getCurrentInstance();
ExternalContext ext_context = context.getExternalContext();
RenderRequest req = (RenderRequest) ext_context.getRequest();
Map<String, String> req_params = req.getParameterMap();

StringBuffer sb = new StringBuffer();
for (Iterator<Entry<String, String>> iter = req_params.entrySet().iterator(); iter.hasNext();) {
Entry<String, String> param = iter.next();
sb.append("\n " + param.getKey() + "=" + param.getValue());
}

System.out.println("BookingHomeBean::BookingHomeBean - RenderRequest" + sb.toString());

None of these methods see to return anything.

Does anyone out there know how to do this?

TIA

Koshy
---
Koshy Abraham
RE: How do I read parameters from a query string in JSF/Facelets portlet
10 de Julho de 2008 03:55
Resposta

Koshy Abraham

Ranking: New Member

Mensagens: 3

Data de entrada: 30 de Janeiro de 2008

Mensagens recentes

I have found a solution to this problem from a previous thread which happened to resurface a couple of hours after I asked my question.

See:
http://www.liferay.com/web/guest/community/forums/-/message_boards/message/788799

Using that solution the following works:

FacesContext context = FacesContext.getCurrentInstance();
ExternalContext ext_context = context.getExternalContext();
RenderRequest req = (RenderRequest) ext_context.getRequest();

HttpServletRequest request = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(req));
mfbStartDate = request.getParameter("mfbStartDate");
mfbEndDate = request.getParameter("mfbEndDate");


Note: This makes the portlet non-portable as it uses a Liferay library called portal-service.jar

Koshy
--
petar banicevic
RE: How do I read parameters from a query string in JSF/Facelets portlet
11 de Julho de 2008 08:46
Resposta

petar banicevic

Ranking: Junior Member

Mensagens: 73

Data de entrada: 27 de Maio de 2008

Mensagens recentes

Are you sure that this works???

HttpServletRequest request = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(req));

I am getting exception:

15:24:50,937 ERROR [jsp:52] java.lang.RuntimeException: Unable to get the HTTP servlet request from com.icesoft.faces.webapp.http.portlet.PortletExternalContext$4
at com.liferay.portal.util.PortalImpl.getHttpServletRequest(PortalImpl.java:696)
at com.liferay.portal.util.PortalUtil.getHttpServletRequest(PortalUtil.java:201)


Getting PortletRequest would be possible but not HttpServletRequest. Let me know if this really works for you, I would be interested to have HttpServletRequest in backing bean.

Thx.
Koshy Abraham
RE: How do I read parameters from a query string in JSF/Facelets portlet
13 de Julho de 2008 17:31
Resposta

Koshy Abraham

Ranking: New Member

Mensagens: 3

Data de entrada: 30 de Janeiro de 2008

Mensagens recentes

I am redirecting to a page containing a portlet that is written using Facelets. On the facelets page I access a backing bean. Depending on the phase I can get access to HttpServletRequest. See the code below. When I access the request parameters in the constructor it all works.


FacesContext context = FacesContext.getCurrentInstance();
ExternalContext ext_context = context.getExternalContext();
try {
HttpServletRequest request; //= PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(req));
Object reqo = ext_context.getRequest();
if (reqo instanceof RenderRequest) {
RenderRequest req = (RenderRequest) ext_context.getRequest();
request = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(req));
} else if (reqo instanceof ActionRequest) {
//THIS FAILS
//ActionRequest areq = (ActionRequest)ext_context.getRequest();
//request = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(areq));
return;
} else {
return;
}

// See: http://www.liferay.com/web/guest/community/forums/-/message_boards/message/788799
// about the following HACK
//HttpServletRequest request = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(req));

// Read a parameter
String checkInDateStr = request.getParameter("mfbtCheckInDate");
Neil Griffin
RE: How do I read parameters from a query string in JSF/Facelets portlet
26 de Agosto de 2010 16:50
Resposta

Neil Griffin

LIFERAY STAFF

Ranking: Liferay Legend

Mensagens: 2511

Data de entrada: 26 de Julho de 2005

Mensagens recentes

With the portletfaces-tools project, you can get a request parameter like this:

portletFacesContext.getRequestQueryStringParameter("parameter_name");

See: http://www.portletfaces.org/projects/portletfaces-tools
Richard Oliver Legendi
RE: How do I read parameters from a query string in JSF/Facelets portlet
15 de Abril de 2013 08:23
Resposta

Richard Oliver Legendi

Ranking: Junior Member

Mensagens: 35

Data de entrada: 30 de Novembro de 2009

Mensagens recentes

Just a small update: as I understand, PortletFacesContext is deprecated, one should use LiferayFacesContext instead. On the other hand, to handle the namespace issues the ParamUtil class may help.

So in the end this was my solution:

1long myParam = ParamUtil.getLong( (RenderRequest) LiferayFacesContext.getCurrentInstance()
2                .getExternalContext()
3                .getRequest(), "myParam" );
Neil Griffin
RE: How do I read parameters from a query string in JSF/Facelets portlet
15 de Abril de 2013 09:05
Resposta

Neil Griffin

LIFERAY STAFF

Ranking: Liferay Legend

Mensagens: 2511

Data de entrada: 26 de Julho de 2005

Mensagens recentes

I would recommend that you use the new LiferayFacesContext that comes with the liferay-faces-portal.jar dependency. There is a method called getRequestQueryStringParameter() that should return the value you are looking for from the query string.

Participate in the State of Liferay Community 2017. Help the community and even win some prizes!