3

Liferay 6 の feed.jspf のようなすぐに使えるポートレットの jsp を使用しています。

String articleId =null;
HttpServletRequest httpReq = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(renderRequest));
articleId = httpReq.getParameter("articleId");

カスタム ポートレットでも .jsp ファイルでも null 値が返されますが、値が必要です。

4

6 に答える 6

10

もちろん、いつでも標準の HttpServletRequest を使用してパラメータを取得できます。このリクエストは、次の例のように PortalUtil クラスを使用して取得できます。

HttpServletRequest request = PortalUtil.getHttpServletRequest(portletRequest);
String articleId = request.getParameter("articleId");
于 2011-02-08T14:01:23.010 に答える
8

私のLiferay- JSPでは、これを使用しています:

<!-- ... some imports... -->
<!-- ... some more imports... -->
<%@ page import="com.liferay.portal.util.PortalUtil" %>

<portlet:defineObjects /> <!-- Liferay-specific, defines renderRequest etc.-->

<%
    HttpServletRequest r = PortalUtil.getHttpServletRequest(renderRequest);
    String wellHole =  PortalUtil.getOriginalServletRequest(r).getParameter("well_hole");

%>

(これは、他の回答、特に 2012 年 7 月 23 日 17:35 の Miguel Gil Martínez の回答からの知恵の断片を組み合わせたものです。

于 2012-08-03T12:45:40.967 に答える
2

それは私のために働いた:

public void doView(RenderRequest request, RenderResponse response) throws 
  PortletException, IOException {

HttpServletRequest requestInsideThePortlet = PortalUtil.getHttpServletRequest(request);

String myURLParam =
 PortalUtil.getOriginalServletRequest(requestInsideThePortlet).getParameter("myURLParam");

....
....
....
}
于 2012-07-23T17:35:46.977 に答える
2

When working with portlets, each HttpServletRequest paramenter has a prefix which informs the "type" of the parameter and a suffix expressing which instance of the portlet should process it. So, the name of the parameters is not just "articleId". I do not know what portlet are you working but if it was a portlet called, let's say, "example" deployed through a war the parameter would be called example_WAR_exampleportletwar_articleId_w2Xd.

However, you do not have to deal with such complexity. If you are working within a JSP of some already created portlet, there should be an object called renderRequest which contains all parameters and abstracts all this name mangling. So, instead of retrieving the original servlet requestion you an use it:

String articleId = renderRequest.getParamenter("articleId");

If this object is not defined, you just need to insert the <portlet:defineObjects/> tag somewhere and after this the object will be available.

HTH. Let us know if it worked!

于 2011-02-07T14:02:43.413 に答える
1

JSFの場合、これを使用します:

@ManagedBean
@RequestScoped
public class OriginalRequest {
    private HttpServletRequest getOriginalRequest() {
        return PortalUtil.getOriginalServletRequest(
                PortalUtil.getHttpServletRequest(
                        (PortletRequest) FacesContext.getCurrentInstance()
                                .getExternalContext().getRequest() ) );
    }

    public String getParam( String name ) {
        return getOriginalRequest().getParameter( name );
    }

    public List<String> getParamNames() {
        return Collections.list( getOriginalRequest().getParameterNames() );
    }
}

次に、あなたのフェイスレットで:

#{originalRequest.getParam('my_param')}
于 2014-11-20T19:17:10.810 に答える
0

私はurソリューションを試しましたが、リクエストをレンダリングすると例外が発生するため、これは別のソリューションです。

public String obtainFromUrl(String keyFromWeb) {

    Object outcome = null;
    Map<String, Object> map = FacesContext.getCurrentInstance().getExternalContext().getRequestMap();
    if (map != null) {
        for (String key : map.keySet()) {
            if (map.get(key) instanceof HttpServletRequestWrapper) {
                HttpServletRequest request = (HttpServletRequest) ((HttpServletRequestWrapper) map.get(key))
                        .getRequest();
                outcome = request.getParameter(keyFromWeb);
                break;
            }
        }
    }
    return (String) outcome;

}
于 2011-03-10T23:32:29.393 に答える