Java Code Examples for javax.portlet.PortletSession#removeAttribute()

The following examples show how to use javax.portlet.PortletSession#removeAttribute() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DispatcherTests3S_SPEC2_19_IncludeServletAction.java    From portals-pluto with Apache License 2.0 6 votes vote down vote up
@Override
public void render(RenderRequest portletReq, RenderResponse portletResp) throws PortletException, IOException {

   long tid = Thread.currentThread().getId();
   portletReq.setAttribute(THREADID_ATTR, tid);

   PrintWriter writer = portletResp.getWriter();

   PortletSession ps = portletReq.getPortletSession();
   String msg = (String) ps.getAttribute(RESULT_ATTR_PREFIX + V2DISPATCHERTESTS3S_SPEC2_19_INCLUDESERVLETACTION_DISPATCH4);
   if (msg != null) {
      writer.write("<p>" + msg + "</p><br/>\n");
      ps.removeAttribute(RESULT_ATTR_PREFIX + V2DISPATCHERTESTS3S_SPEC2_19_INCLUDESERVLETACTION_DISPATCH4);
   }

   /* TestCase: V2DispatcherTests3S_SPEC2_19_IncludeServletAction_dispatch4 */
   /* Details: "The parameters associated with a request dispatcher are */
   /* scoped only for the duration of the include or forward call" */
   {
      PortletURL aurl = portletResp.createActionURL();
      aurl.setParameters(portletReq.getPrivateParameterMap());
      TestButton tb = new TestButton(V2DISPATCHERTESTS3S_SPEC2_19_INCLUDESERVLETACTION_DISPATCH4, aurl);
      tb.writeTo(writer);
   }

}
 
Example 2
Source File: SimpleAttributeTest.java    From portals-pluto with Apache License 2.0 6 votes vote down vote up
protected TestResult checkRemoveAttribute(PortletSession session) {
    TestResult res = new TestResult();
    res.setName("Remove Session Attribute Test");
    res.setDescription("Sets, removes and retrieves portlet request attribute.");

    session.setAttribute(KEY, VAL);
    session.removeAttribute(KEY);
    Object val = session.getAttribute(KEY);
    if(val!=null) {
        res.setReturnCode(TestResult.FAILED);
        res.setResultMessage("Retrieved value: '"+val+"' - Expected '"+VAL+"'");
    }
    else {
        res.setReturnCode(TestResult.PASSED);
    }

    return res;
}
 
Example 3
Source File: SimpleAttributeTest.java    From portals-pluto with Apache License 2.0 6 votes vote down vote up
protected TestResult checkSetAttribute(PortletSession session) {
    TestResult res = new TestResult();
    res.setName("Set Attribute Test");
    res.setDescription("Sets and retrieves portlet sessionuest attribute.");

    session.setAttribute(KEY, VAL);
    Object val = session.getAttribute(KEY);
    if(!VAL.equals(val)) {
        res.setReturnCode(TestResult.FAILED);
        res.setResultMessage("Retrieved value: '"+val+"' - Expected '"+VAL+"'");
    }
    else {
        res.setReturnCode(TestResult.PASSED);
    }

    session.removeAttribute(KEY);
    return res;
}
 
Example 4
Source File: PortletRequestAttributes.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Override
public void removeAttribute(String name, int scope) {
	if (scope == SCOPE_REQUEST) {
		if (isRequestActive()) {
			this.request.removeAttribute(name);
			removeRequestDestructionCallback(name);
		}
	}
	else {
		PortletSession session = getSession(false);
		if (session != null) {
			if (scope == SCOPE_GLOBAL_SESSION) {
				session.removeAttribute(name, PortletSession.APPLICATION_SCOPE);
				this.globalSessionAttributesToUpdate.remove(name);
			}
			else {
				session.removeAttribute(name);
				this.sessionAttributesToUpdate.remove(name);
			}
		}
	}
}
 
Example 5
Source File: PortletHelper.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public static void clearErrorMessage(PortletRequest request)
{   
	PortletSession pSession = request.getPortletSession(true);
	pSession.removeAttribute("error.message");
	pSession.removeAttribute("error.output");
	pSession.removeAttribute("error.map");
}
 
Example 6
Source File: SakaiIFrame.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public void processAction(ActionRequest request, ActionResponse response)
throws PortletException, IOException {

	log.debug("==== processAction called ====");

	PortletSession pSession = request.getPortletSession(true);

	// Our first challenge is to figure out which action we want to take
	// The view selects the "next action" either as a URL parameter
	// or as a hidden field in the POST data - we check both

	String doCancel = request.getParameter("sakai.cancel");
	String doUpdate = request.getParameter("sakai.update");

	// Our next challenge is to pick which action the previous view
	// has told us to do.  Note that the view may place several actions
	// on the screen and the user may have an option to pick between
	// them.  Make sure we handle the "no action" fall-through.

	pSession.removeAttribute("error.message");

	if ( doCancel != null ) {
		response.setPortletMode(PortletMode.VIEW);
	} else if ( doUpdate != null ) {
		processActionEdit(request, response);
	} else {
		log.debug("Unknown action");
		response.setPortletMode(PortletMode.VIEW);
	}

	log.debug("==== End of ProcessAction  ====");
}
 
Example 7
Source File: PortletHelper.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public static void clearErrorMessage(PortletRequest request)
{   
	PortletSession pSession = request.getPortletSession(true);
	pSession.removeAttribute("error.message");
	pSession.removeAttribute("error.output");
	pSession.removeAttribute("error.map");
}
 
Example 8
Source File: DispatcherTests3S_SPEC2_19_IncludeJSPAction.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
@Override
public void render(RenderRequest portletReq, RenderResponse portletResp) throws PortletException, IOException {

   long tid = Thread.currentThread().getId();
   portletReq.setAttribute(THREADID_ATTR, tid);

   PrintWriter writer = portletResp.getWriter();

   PortletSession ps = portletReq.getPortletSession();
   String msg = (String) ps.getAttribute(RESULT_ATTR_PREFIX + V2DISPATCHERTESTS3S_SPEC2_19_INCLUDEJSPACTION_DISPATCH4,
         APPLICATION_SCOPE);
   if (msg != null) {
      writer.write("<p>" + msg + "</p><br/>\n");
      ps.removeAttribute(RESULT_ATTR_PREFIX + V2DISPATCHERTESTS3S_SPEC2_19_INCLUDEJSPACTION_DISPATCH4, APPLICATION_SCOPE);
   }

   /* TestCase: V2DispatcherTests3S_SPEC2_19_IncludeJSPAction_dispatch4 */
   /* Details: "The parameters associated with a request dispatcher are */
   /* scoped only for the duration of the include or forward call" */
   {
      PortletURL aurl = portletResp.createActionURL();
      aurl.setParameters(portletReq.getPrivateParameterMap());
      TestButton tb = new TestButton(V2DISPATCHERTESTS3S_SPEC2_19_INCLUDEJSPACTION_DISPATCH4, aurl);
      tb.writeTo(writer);
   }

}
 
Example 9
Source File: IMSBLTIPortlet.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
private void clearSession(PortletRequest request)
{
	PortletSession pSession = request.getPortletSession(true);

	pSession.removeAttribute("sakai.url");
	pSession.removeAttribute("sakai.widget");
	pSession.removeAttribute("sakai.descriptor");
	pSession.removeAttribute("sakai.attemptdescriptor");

	for (String element : fieldList) {
		pSession.removeAttribute("sakai."+element);
	}
}
 
Example 10
Source File: SakaiIFrame.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public void processAction(ActionRequest request, ActionResponse response)
throws PortletException, IOException {

	log.debug("==== processAction called ====");

	PortletSession pSession = request.getPortletSession(true);

	// Our first challenge is to figure out which action we want to take
	// The view selects the "next action" either as a URL parameter
	// or as a hidden field in the POST data - we check both

	String doCancel = request.getParameter("sakai.cancel");
	String doUpdate = request.getParameter("sakai.update");

	// Our next challenge is to pick which action the previous view
	// has told us to do.  Note that the view may place several actions
	// on the screen and the user may have an option to pick between
	// them.  Make sure we handle the "no action" fall-through.

	pSession.removeAttribute("error.message");

	if ( doCancel != null ) {
		response.setPortletMode(PortletMode.VIEW);
	} else if ( doUpdate != null ) {
		processActionEdit(request, response);
	} else {
		log.debug("Unknown action");
		response.setPortletMode(PortletMode.VIEW);
	}

	log.debug("==== End of ProcessAction  ====");
}
 
Example 11
Source File: PortletIFrame.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public void processAction(ActionRequest request, ActionResponse response)
throws PortletException, IOException {

	// log.info("==== processAction called ====");

	PortletSession pSession = request.getPortletSession(true);

	// Our first challenge is to figure out which action we want to take
	// The view selects the "next action" either as a URL parameter
	// or as a hidden field in the POST data - we check both

	String doCancel = request.getParameter("sakai.cancel");
	String doUpdate = request.getParameter("sakai.update");

	// Our next challenge is to pick which action the previous view
	// has told us to do.  Note that the view may place several actions
	// on the screen and the user may have an option to pick between
	// them.  Make sure we handle the "no action" fall-through.

	pSession.removeAttribute("error.message");

	if ( doCancel != null ) {
		response.setPortletMode(PortletMode.VIEW);
	} else if ( doUpdate != null ) {
		processActionEdit(request, response);
	} else {
		// log.info("Unknown action");
		response.setPortletMode(PortletMode.VIEW);
	}

	// log.info("==== End of ProcessAction  ====");
}
 
Example 12
Source File: DispatcherTests3S_SPEC2_19_ForwardJSPAction.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
@Override
public void render(RenderRequest portletReq, RenderResponse portletResp) throws PortletException, IOException {

   long tid = Thread.currentThread().getId();
   portletReq.setAttribute(THREADID_ATTR, tid);

   PrintWriter writer = portletResp.getWriter();

   PortletSession ps = portletReq.getPortletSession();
   String msg = (String) ps.getAttribute(RESULT_ATTR_PREFIX + V2DISPATCHERTESTS3S_SPEC2_19_FORWARDJSPACTION_DISPATCH4,
         APPLICATION_SCOPE);
   if (msg != null) {
      writer.write("<p>" + msg + "</p><br/>\n");
      ps.removeAttribute(RESULT_ATTR_PREFIX + V2DISPATCHERTESTS3S_SPEC2_19_FORWARDJSPACTION_DISPATCH4, APPLICATION_SCOPE);
   }

   /* TestCase: V2DispatcherTests3S_SPEC2_19_ForwardJSPAction_dispatch4 */
   /* Details: "The parameters associated with a request dispatcher are */
   /* scoped only for the duration of the include or forward call" */
   {
      PortletURL aurl = portletResp.createActionURL();
      aurl.setParameters(portletReq.getPrivateParameterMap());
      TestButton tb = new TestButton(V2DISPATCHERTESTS3S_SPEC2_19_FORWARDJSPACTION_DISPATCH4, aurl);
      tb.writeTo(writer);
   }

}
 
Example 13
Source File: RenderStateTests_SPEC2_12_MutableRenderState2.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
@Override
public void render(RenderRequest portletReq, RenderResponse portletResp)
      throws PortletException, IOException {

   portletResp.setContentType("text/html");
   PrintWriter writer = portletResp.getWriter();

   PortletSession ps = portletReq.getPortletSession();
   String msg = (String) ps.getAttribute(Constants.RESULT_ATTR_PREFIX + "RenderStateTests_SPEC2_12_MutableRenderState2");
   ps.removeAttribute(Constants.RESULT_ATTR_PREFIX + "RenderStateTests_SPEC2_12_MutableRenderState2");

   if (msg != null && msg.length() > 0) {
      writer.write("<p>" + msg + "</p>\n");
   }
   
   /*
    * TestCase:
    * V3RenderStateTests_SPEC2_12_MutableRenderState_getRenderParameters3
    */
   /*
    * Details:
    * "If no render parameters are available, the object will be empty."
    */
   {
      ActionURL actionURL = portletResp.createActionURL();
      MutableActionParameters mutableActionParams = actionURL
            .getActionParameters();
      mutableActionParams.clear();
      TestButton tb = new TestButton(
            V3RENDERSTATETESTS_SPEC2_12_MUTABLERENDERSTATE_GETRENDERPARAMETERS3,
            actionURL);
      tb.writeTo(writer);
   }

}
 
Example 14
Source File: DispatcherTests4_SPEC2_19_ForwardJSPAction.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
@Override
public void render(RenderRequest portletReq, RenderResponse portletResp) throws PortletException, IOException {

   long tid = Thread.currentThread().getId();
   portletReq.setAttribute(THREADID_ATTR, tid);

   PrintWriter writer = portletResp.getWriter();

   PortletSession ps = portletReq.getPortletSession();
   String msg = (String) ps.getAttribute(RESULT_ATTR_PREFIX + "DispatcherTests4_SPEC2_19_ForwardJSPAction",
         APPLICATION_SCOPE);
   if (msg != null) {
      writer.write("<p>" + msg + "</p><br/>\n");
      ps.removeAttribute(RESULT_ATTR_PREFIX + "DispatcherTests4_SPEC2_19_ForwardJSPAction", APPLICATION_SCOPE);
   }

   /* TestCase: V2DispatcherTests4_SPEC2_19_ForwardJSPAction_invoke3 */
   /* Details: "Parameters to the forward method for a target servlet */
   /* can be wrapped request and response classes from the portlet */
   /* lifecyle method initiating the include" */
   {
      PortletURL aurl = portletResp.createActionURL();
      aurl.setParameters(portletReq.getPrivateParameterMap());
      TestButton tb = new TestButton(V2DISPATCHERTESTS4_SPEC2_19_FORWARDJSPACTION_INVOKE3, aurl);
      tb.writeTo(writer);
   }

}
 
Example 15
Source File: AnnotationTests_ProcessAction_ApiAction.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
@Override
public void render(RenderRequest portletReq, RenderResponse portletResp)
    throws PortletException, IOException {

  long tid = Thread.currentThread().getId();
  portletReq.setAttribute(THREADID_ATTR, tid);

  PrintWriter writer = portletResp.getWriter();

  PortletSession ps = portletReq.getPortletSession();
  String msg =
      (String) ps.getAttribute(RESULT_ATTR_PREFIX + "AnnotationTests_ProcessAction_ApiAction",
          APPLICATION_SCOPE);
  if (msg != null) {
    writer.write("<p>" + msg + "</p><br/>\n");
    ps.removeAttribute(RESULT_ATTR_PREFIX + "AnnotationTests_ProcessAction_ApiAction",
        APPLICATION_SCOPE);
  }

  /* TestCase: V2AnnotationTests_ProcessAction_ApiAction_name */
  /* Details: "Method name(): On an action request, the method is */
  /* executed if the parameter \"javax.portlet.action\" matches the */
  /* name field" */
  {
    PortletURL aurl = portletResp.createActionURL();
    aurl.setParameter(ActionRequest.ACTION_NAME, V2ANNOTATIONTESTS_PROCESSACTION_APIACTION_NAME);
    TestButton tb = new TestButton(V2ANNOTATIONTESTS_PROCESSACTION_APIACTION_NAME, aurl);
    tb.writeTo(writer);
  }

}
 
Example 16
Source File: PortletIFrame.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
private void sendAlert(RenderRequest request, Context context) {
	PortletSession pSession = request.getPortletSession(true);
	String str = (String) pSession.getAttribute(ALERT_MESSAGE);
	pSession.removeAttribute(ALERT_MESSAGE);
	if ( str != null && str.length() > 0 ) context.put("alertMessage", formattedText.escapeHtml(str, false));
}
 
Example 17
Source File: EnvironmentTests_PortletRequestDispatcher_ApiRender.java    From portals-pluto with Apache License 2.0 4 votes vote down vote up
@Override
public void render(RenderRequest renderReq, RenderResponse renderResp)
    throws PortletException, IOException {

  long tid = Thread.currentThread().getId();
  renderReq.setAttribute(THREADID_ATTR, tid);

  PrintWriter writer = renderResp.getWriter();

  PortletSession ps = renderReq.getPortletSession();
  String msg = (String) ps.getAttribute(
      RESULT_ATTR_PREFIX + "V2EnvironmentTests_PortletRequestDispatcher_ApiRender_forward1",
      APPLICATION_SCOPE);
  if (msg != null) {
    writer.write("<p>" + msg + "</p><br/>\n");
    ps.removeAttribute(
        RESULT_ATTR_PREFIX + "V2EnvironmentTests_PortletRequestDispatcher_ApiRender_forward1",
        APPLICATION_SCOPE);
  }

  // Create result objects for the tests

  PortletRequest portletReq = renderReq;
  PortletResponse portletResp = renderResp;

  /* TestCase: V2EnvironmentTests_PortletRequestDispatcher_ApiRender_includeA1 */
  /* Details: "Method include(PortletRequest, PortletResponse): */
  /* Includes the content of a JSP page in the response" */
  String target_tr0 =
      JSP_PREFIX + "V2EnvironmentTests_PortletRequestDispatcher_ApiRender_includeA1" + JSP_SUFFIX
          + "?" + QUERY_STRING;
  PortletRequestDispatcher rd_tr0 =
      portletConfig.getPortletContext().getRequestDispatcher(target_tr0);
  rd_tr0.include(portletReq, portletResp);

  /* TestCase: V2EnvironmentTests_PortletRequestDispatcher_ApiRender_includeA2 */
  /* Details: "Method include(PortletRequest, PortletResponse): */
  /* Includes the content of a HTML Page in the response" */
  String target_tr1 = HTML_PREFIX
      + "V2EnvironmentTests_PortletRequestDispatcher_ApiRender_includeA2" + HTML_SUFFIX;
  PortletRequestDispatcher rd_tr1 =
      portletConfig.getPortletContext().getRequestDispatcher(target_tr1);
  rd_tr1.include(portletReq, portletResp);

  /* TestCase: V2EnvironmentTests_PortletRequestDispatcher_ApiRender_includeA3 */
  /* Details: "Method include(PortletRequest, PortletResponse): The */
  /* included servlet cannot change the status code. The attempt is */
  /* ignored" */
  String target_tr2 = SERVLET_PREFIX
      + "V2EnvironmentTests_PortletRequestDispatcher_ApiRender_PortletRequest_Include"
      + SERVLET_SUFFIX;
  PortletRequestDispatcher rd_tr2 =
      portletConfig.getPortletContext().getRequestDispatcher(target_tr2);
  rd_tr2.include(portletReq, portletResp);

  /* TestCase: V2EnvironmentTests_PortletRequestDispatcher_ApiRender_includeB1 */
  /* Details: "Method include(RenderRequest, RenderResponse): Includes */
  /* the content of a JSP page in the response" */
  String target_tr3 =
      JSP_PREFIX + "V2EnvironmentTests_PortletRequestDispatcher_ApiRender_includeB1" + JSP_SUFFIX
          + "?" + QUERY_STRING;
  PortletRequestDispatcher rd_tr3 =
      portletConfig.getPortletContext().getRequestDispatcher(target_tr3);
  rd_tr3.include(portletReq, portletResp);

  /* TestCase: V2EnvironmentTests_PortletRequestDispatcher_ApiRender_includeB2 */
  /* Details: "Method include(RenderRequest, RenderResponse): Includes */
  /* the content of a HTML Page in the response" */
  String target_tr4 = HTML_PREFIX
      + "V2EnvironmentTests_PortletRequestDispatcher_ApiRender_includeB2" + HTML_SUFFIX;
  PortletRequestDispatcher rd_tr4 =
      portletConfig.getPortletContext().getRequestDispatcher(target_tr4);
  rd_tr4.include(portletReq, portletResp);

  /* TestCase: V2EnvironmentTests_PortletRequestDispatcher_ApiRender_includeB3 */
  /* Details: "Method include(RenderRequest, RenderResponse): The */
  /* included servlet cannot change the status code. The attempt is */
  /* ignored" */
  String target_tr5 = SERVLET_PREFIX
      + "V2EnvironmentTests_PortletRequestDispatcher_ApiRender_RenderRequest_Include"
      + SERVLET_SUFFIX;
  PortletRequestDispatcher rd_tr5 =
      portletConfig.getPortletContext().getRequestDispatcher(target_tr5);
  rd_tr5.include(portletReq, portletResp);



}
 
Example 18
Source File: SakaiIFrame.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
private void sendAlert(RenderRequest request, Context context) {
	PortletSession pSession = request.getPortletSession(true);
	String str = (String) pSession.getAttribute(ALERT_MESSAGE);
	pSession.removeAttribute(ALERT_MESSAGE);
	if ( str != null && str.length() > 0 ) context.put("alertMessage", formattedText.escapeHtml(str, false));
}
 
Example 19
Source File: PortletIFrame.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
private void sendAlert(RenderRequest request, Context context) {
	PortletSession pSession = request.getPortletSession(true);
	String str = (String) pSession.getAttribute(ALERT_MESSAGE);
	pSession.removeAttribute(ALERT_MESSAGE);
	if ( str != null && str.length() > 0 ) context.put("alertMessage", formattedText.escapeHtml(str, false));
}
 
Example 20
Source File: PortletHelper.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
public static void clearDebugOutput(PortletRequest request)
{   
	PortletSession pSession = request.getPortletSession(true);
	pSession.removeAttribute("debug.print");
}