Foros de discusión

Pass parameters to PortletURL does not work

thumbnail
Jose Alvarez de Lara, modificado hace 11 años.

Pass parameters to PortletURL does not work

Junior Member Mensajes: 45 Fecha de incorporación: 10/12/12 Mensajes recientes
Hi,

I am trying to do a meddle step between the first one that is a request and the last one that is the result of the request.
In the meddle step the user musts validate himself by typing a key.

The first step is a jsp file that takes to the validation step and works fine but in the meddle step I do not see the request in question
Here is the code,

The view.jsp file where I do the request,

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

Welcome to our library
<br>

&lt;% 
	PortletURL redirectURL = renderResponse.createActionURL();
	redirectURL.setParameter(ActionRequest.ACTION_NAME, "redirect");
%&gt;

<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>



	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());
	}


Here is the checkuser.jsp file (the validation step)

&lt;%@ include file="/html/blue/init.jsp" %&gt;

&lt;% 
	PortletURL checkUserURL = renderResponse.createActionURL();
	checkUserURL.setParameter(ActionRequest.ACTION_NAME, "checkUser");
	
	String myaction = renderRequest.getParameter("myaction");
%&gt;

<p> Your action:&nbsp;&lt;%= myaction %&gt; </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>


I do not see 'myaction' in the portlet. And the last step does not work. Here is the code,

	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());
	}


At the end I have to get update.jsp or list.jsp file deppending on the request (myaction variable)
but it does not happen.

Any help should be appreciated.

Regards,
Jose
thumbnail
Jose Alvarez de Lara, modificado hace 11 años.

RE: Pass parameters to PortletURL does not work

Junior Member Mensajes: 45 Fecha de incorporación: 10/12/12 Mensajes recientes
Hi,

This question is really important for me, I am working in a workflow and the three users in it have access to all the portlets
for the same site and the same organization so if I need everyone have access just only to their own tools I need they validate
before doing a request.

Best regards,
Jose
thumbnail
Jose Alvarez de Lara, modificado hace 11 años.

RE: Pass parameters to PortletURL does not work

Junior Member Mensajes: 45 Fecha de incorporación: 10/12/12 Mensajes recientes
Hi,

With the help of a friend in Stackoverflow I have done a few changes in my code and now the portlet works fine.

These changes are as follows,

1.- In the java code put the complete path to the jsp file,
2.- In the jsp file catches myaction variable using ParamUtil.getString(request, "myaction")

I need to validate the users because all of them have acces to all the portlets in the workflow

Regards
Jose