Fórum
RE: How do I read parameters from a query string in JSF/Facelets portlet
Koshy Abraham, modificado 15 Anos atrás.
How do I read parameters from a query string in JSF/Facelets portlet
New Member Postagens: 3 Data de Entrada: 30/01/08 Postagens 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
---
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, modificado 15 Anos atrás.
RE: How do I read parameters from a query string in JSF/Facelets portlet
New Member Postagens: 3 Data de Entrada: 30/01/08 Postagens 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:
[indent]http://www.liferay.com/web/guest/community/forums/-/message_boards/message/788799[/indent]
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
--
See:
[indent]http://www.liferay.com/web/guest/community/forums/-/message_boards/message/788799[/indent]
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, modificado 15 Anos atrás.
RE: How do I read parameters from a query string in JSF/Facelets portlet
Junior Member Postagens: 73 Data de Entrada: 27/05/08 Postagens 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.
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, modificado 15 Anos atrás.
RE: How do I read parameters from a query string in JSF/Facelets portlet
New Member Postagens: 3 Data de Entrada: 30/01/08 Postagens 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");
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, modificado 13 Anos atrás.
RE: How do I read parameters from a query string in JSF/Facelets portlet
Liferay Legend Postagens: 2655 Data de Entrada: 27/07/05 Postagens 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
portletFacesContext.getRequestQueryStringParameter("parameter_name");
See: http://www.portletfaces.org/projects/portletfaces-tools
Richard Oliver Legendi, modificado 10 Anos atrás.
RE: How do I read parameters from a query string in JSF/Facelets portlet
Junior Member Postagens: 35 Data de Entrada: 30/11/09 Postagens 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:
So in the end this was my solution:
long myParam = ParamUtil.getLong( (RenderRequest) LiferayFacesContext.getCurrentInstance()
.getExternalContext()
.getRequest(), "myParam" );
Neil Griffin, modificado 10 Anos atrás.
RE: How do I read parameters from a query string in JSF/Facelets portlet
Liferay Legend Postagens: 2655 Data de Entrada: 27/07/05 Postagens 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.