0

我想通过键入他的个人密钥来验证用户的请求。首先他执行请求,现在 portlet 重定向到第二个 jsp 文件,他在其中使用密钥进行验证,最后如果没问题, portlet 完成请求,否则返回第一步。

这是代码,

1.- view.jsp(请求)

<%@ include file="/html/blue/init.jsp" %>

Welcome to our Colors workflow
<br/>

<% 
PortletURL redirectURL = renderResponse.createActionURL();
redirectURL.setParameter(ActionRequest.ACTION_NAME, "redirect");
%>

<aui:form name="fmAdd" method="POST" action="<%= redirectURL.toString() %>">
<aui:input type="hidden" name="myaction" value="add" />
<aui:button type="submit" value="Add New Box"/>
</aui:form>
&nbsp;
<aui:form name="fmList" method="POST" action="<%= redirectURL.toString() %>">
<aui:input type="hidden" name="myaction" value="list" />
<aui:button type="submit" value="Show All Boxes"/>
</aui:form>

2.- java代码,

public void redirect(ActionRequest actionRequest,
        ActionResponse actionResponse) throws IOException, PortletException {

    String action = ParamUtil.getString(actionRequest, "myaction");

    PortletURL redirectURL = null;
    String redirectJSP = "/checkuser.jsp";
    if(action != null) {
        String portletName = (String)actionRequest.getAttribute(WebKeys.PORTLET_ID);
        ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
        redirectURL = PortletURLFactoryUtil.create(PortalUtil.getHttpServletRequest(actionRequest),
                portletName, themeDisplay.getLayout().getPlid(), PortletRequest.RENDER_PHASE);
        redirectURL.setParameter("myaction", action);
        redirectURL.setParameter("jspPage", redirectJSP);
    }

    actionResponse.sendRedirect(redirectURL.toString());
}

3._ checkuser.jsp(用户用他的密钥验证)

<%@ include file="/html/blue/init.jsp" %>

<% 
PortletURL checkUserURL = renderResponse.createActionURL();
checkUserURL.setParameter(ActionRequest.ACTION_NAME, "checkUser");

String myaction = renderRequest.getParameter("myaction");
%>

<p> Your action:&nbsp;<%= myaction %> </p>

<aui:form name="fm" method="POST" action="<%= checkUserURL.toString() %>">
<aui:input type="hidden" name="myaction" value="<%= myaction %>" />
<aui:input type="text" name="key" value=""/>
<aui:button type="submit" value="Save"/>
</aui:form>

在这个阶段,我遇到了第一个问题,因为我没有看到请求的值(myaction 变量)。这仅用于调试。

4._捕捉最后一种形式的java代码,

public void checkUser(ActionRequest actionRequest,
        ActionResponse actionResponse) throws IOException, PortletException {

    String key = ParamUtil.getString(actionRequest, "key");
    String action = ParamUtil.getString(actionRequest, "myaction");

    String portletName = (String)actionRequest.getAttribute(WebKeys.PORTLET_ID);
    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
    PortletURL redirectURL = PortletURLFactoryUtil.create(PortalUtil.getHttpServletRequest(actionRequest),
            portletName, themeDisplay.getLayout().getPlid(), PortletRequest.RENDER_PHASE);

    String redirectJSP = "/view.jsp";
    if(key != null) {
        if(key.equalsIgnoreCase("blue")) {
            if(action != null) {
                if(action.equalsIgnoreCase("add")) {
                    redirectJSP = "/update.jsp";
                }
                if(action.equalsIgnoreCase("list")) {
                    redirectJSP = "/list.jsp";
                }
            }
        }
    }

    redirectURL.setParameter("jspPage", redirectJSP);
    actionResponse.sendRedirect(redirectURL.toString());
}

在这个阶段,portlet 总是转到用户执行请求的 view.jsp。我认为 key 和 action 变量都是 null 或至少其中一个。

我究竟做错了什么?

问候,何塞

4

1 回答 1

2

在 Liferay 中,参数是使用命名空间设置的,因此当页面上存在超过 1 个 portlet 时它们不会引起问题。特别是如果您在页面上有两次完全相同的 portlet!所以当你设置时myaction,它真的被设置为类似_myportlet_INSTANCE_xlka_myaction或类似的东西。

您可以使用它com.liferay.portal.kernel.util.ParamUtil来帮助您获取参数,而不必担心范围。例如:

ParamUtil.getString(request, "myaction");
于 2013-02-05T18:27:27.083 回答