|
From: Chad B. <cwb...@us...> - 2008-05-16 22:18:46
|
User: cwbrandon
Date: 08/05/16 13:27:18
Modified: andromda-jsf2/src/main/resources/templates/jsf2/controllers
Controller.java.vsl
Log:
add some convience methods to getting and setting request/session attributes (to insulate us from portlet vs http requests and sessions).
Revision Changes Path
1.14 +42 -7 cartridges/andromda-jsf2/src/main/resources/templates/jsf2/controllers/Controller.java.vsl
Index: Controller.java.vsl
===================================================================
RCS file: /cvsroot/andromdaplugins/cartridges/andromda-jsf2/src/main/resources/templates/jsf2/controllers/Controller.java.vsl,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -w -r1.13 -r1.14
--- Controller.java.vsl 15 May 2008 19:30:28 -0000 1.13
+++ Controller.java.vsl 16 May 2008 20:27:18 -0000 1.14
@@ -59,7 +59,7 @@
// IMPORTANT: it isn't possible to automatically populate any property named "id" since that
// is a reserved name in JSF (the id of a component), therefore we have to unfortunately ignore any availble "id" attribute
${managedBeansPackage}.${formPopulatorName}.populateFormFromPropertyMap(
- form, form.getDateTimeFormatters(), (java.util.Map)this.getRequest().getAttribute(ACTION_EVENT_ATTRIBUTES), new String[] {"id"});
+ form, form.getDateTimeFormatters(), (java.util.Map)this.getRequestAttribute(ACTION_EVENT_ATTRIBUTES), new String[] {"id"});
// - populate the form with any request parameters that may match
${managedBeansPackage}.${formPopulatorName}.populateFormFromPropertyMap(
form, form.getDateTimeFormatters(), this.getContext().getExternalContext().getRequestParameterMap());
@@ -77,7 +77,7 @@
}
catch (final Throwable throwable)
{
- this.getRequest().setAttribute(CONTROLLER_EXCEPTION, throwable);
+ this.setRequestAttribute(CONTROLLER_EXCEPTION, throwable);
this.setForm("$action.formKey", currentForm, false);
final String messageKey = ${managedBeansPackage}.${patternMatchingExceptionHandler}.instance().handleException(throwable);
if(!org.apache.commons.lang.StringUtils.isEmpty(messageKey))
@@ -86,7 +86,7 @@
}
catch (final Throwable throwable)
{
- this.getRequest().setAttribute(CONTROLLER_EXCEPTION, throwable);
+ this.setRequestAttribute(CONTROLLER_EXCEPTION, throwable);
this.setForm("$action.formKey", currentForm, false);
this.addExceptionMessage(throwable);
// - set the forward to null so that we stay on the current view
@@ -253,15 +253,15 @@
contextWrapper.getCurrentInstance().getPageFlowScope().put(formKey, form);
if (includeInSession)
{
- this.getSession(false).setAttribute(formKey, form);
+ this.setSessionAttribute(formKey, form);
// - add this temporary ADF context to the session so that we can retrieve from a view populator if required
this.getSession(false).setAttribute("$adfContextAttributeName", contextWrapper);
}
#else
- this.getRequest().setAttribute(formKey, form);
+ this.setRequestAttribute(formKey, form);
if (includeInSession)
{
- this.getSession(false).setAttribute(formKey, form);
+ this.setSessionAttribute(formKey, form);
}
#end
}
@@ -532,9 +532,30 @@
*/
public void action(javax.faces.event.ActionEvent event)
{
- this.getRequest().setAttribute(ACTION_EVENT_ATTRIBUTES, event.getComponent().
+ this.setRequestAttribute(ACTION_EVENT_ATTRIBUTES, event.getComponent().
getAttributes());
}
+
+ protected void setRequestAttribute(final String name, final Object object)
+ {
+ ${managedBeansPackage}.JsfUtils.setAttribute(this.getContext().getExternalContext().getRequest(), name, object);
+ }
+
+ protected Object getRequestAttribute(final String name)
+ {
+ return ${managedBeansPackage}.JsfUtils.getAttribute(this.getContext().getExternalContext().getRequest(), name);
+ }
+
+ protected void setSessionAttribute(final String name, final Object object)
+ {
+ ${managedBeansPackage}.JsfUtils.setAttribute(this.getContext().getExternalContext().getSession(false), name, object);
+ }
+
+ protected Object getSessionAttribute(final String name)
+ {
+ return ${managedBeansPackage}.JsfUtils.getAttribute(this.getContext().getExternalContext().getSession(false), name);
+ }
+
#if ($portlet)
#if ($controller.useCase.preferences)
@@ -548,6 +569,20 @@
#end
/**
+ * Sets the given form into the {@link javax.portlet.PortletSession#APPLICATION_SCOPE}.
+ *
+ * @param form the form to set into the application scope (useful when you need to pass
+ * the form to another portlet or to the webapp outside of the portlet.
+ */
+ protected void setFormInSessionApplicationScope(final Object form)
+ {
+ if (this.getContext().getExternalContext().getSession(false) instanceof javax.portlet.PortletSession)
+ {
+ this.getSession(false).setAttribute("$actionFormKey", form, javax.portlet.PortletSession.APPLICATION_SCOPE);
+ }
+ }
+
+ /**
* Gets the current action response.
*
* @return the current action response.
|