|
From: Chad B. <cwb...@us...> - 2008-07-17 18:43:29
|
User: cwbrandon
Date: 08/07/17 11:43:39
Modified: andromda-jsf2/src/main/resources/templates/jsf2/controllers
Controller.java.vsl
Log:
Add a couple convience methods for getting the current action form instance within the controller
Revision Changes Path
1.22 +33 -2 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.21
retrieving revision 1.22
diff -u -w -r1.21 -r1.22
--- Controller.java.vsl 15 Jul 2008 11:42:44 -0000 1.21
+++ Controller.java.vsl 17 Jul 2008 18:43:39 -0000 1.22
@@ -86,9 +86,12 @@
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)){
+ if(org.apache.commons.lang.StringUtils.isEmpty(messageKey))
+ {
throw throwable;
- } else {
+ }
+ else
+ {
this.addErrorMessage(${managedBeansPackage}.Messages.get(messageKey, null));
}
}
@@ -581,6 +584,34 @@
#end
/**
+ * Retrieves the current action form while making sure the form is of the given
+ * <code>type</code>. If the action form is found, but not of the given type, null will
+ * be returned.
+ *
+ * @param type the type of form to retrieve.
+ * @return the found form.
+ */
+ protected Object getCurrentActionForm(final Class type)
+ {
+ Object form = this.getCurrentActionForm();
+ if (!type.isInstance(form))
+ {
+ form = null;
+ }
+ return form;
+ }
+
+ /**
+ * Retrieves the current action form instance.
+ *
+ * @return the current action form instance.
+ */
+ protected Object getCurrentActionForm()
+ {
+ return this.resolveVariable("$actionFormKey");
+ }
+
+ /**
* The name of the request attribute that stores the attributes from the current action event.
*/
private static final String ACTION_EVENT_ATTRIBUTES = "actionEventAttributes";
|