From: Chad B. <cwb...@us...> - 2008-04-08 16:29:14
|
User: cwbrandon Date: 08/04/08 09:29:07 Modified: andromda-jsf2/src/main/resources/templates/jsf2/flow ViewPopulator.java.vsl LogOutServlet.java.vsl andromda-jsf2/src/main/resources/templates/jsf2/utils JsfUtils.java.vsl andromda-jsf2/src/main/resources/templates/jsf2/flow/crud ViewPopulator.java.vsl Log: more improvement to portlet form serialization Revision Changes Path 1.7 +9 -16 cartridges/andromda-jsf2/src/main/resources/templates/jsf2/flow/ViewPopulator.java.vsl Index: ViewPopulator.java.vsl =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-jsf2/src/main/resources/templates/jsf2/flow/ViewPopulator.java.vsl,v retrieving revision 1.6 retrieving revision 1.7 diff -u -w -r1.6 -r1.7 --- ViewPopulator.java.vsl 8 Apr 2008 01:42:35 -0000 1.6 +++ ViewPopulator.java.vsl 8 Apr 2008 16:29:06 -0000 1.7 @@ -52,18 +52,11 @@ { // - we need to retrieve the faces context differently since we're outside of the // faces servlet - final LifecycleFactory lifecycleFactory = - (LifecycleFactory)FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY); - final Lifecycle lifecycle = lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE); - final FacesContextFactory facesContextFactory = - (FacesContextFactory)FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY); - final FacesContext facesContext = - facesContextFactory.getFacesContext( - this.config.getServletContext(), - request, - response, - lifecycle); - populateFormAndViewVariables(facesContext, null); +#set ($facesContextUtilsFullyQualifiedName = "FacesContextUtils") +#if ($stringUtils.isNotBlank($managedBeansPackage)) +#set($facesContextUtilsFullyQualifiedName = "${managedBeansPackage}.${facesContextUtilsFullyQualifiedName}") +#end + populateFormAndViewVariables(${facesContextUtilsFullyQualifiedName}.getFacesContext(request, response), null); chain.doFilter(request, response); } @@ -108,7 +101,7 @@ // - if the form is still null, see if we can get it from a serialized state if (form == null) { - form = ${managedBeansPackage}.JsfUtils.getSerializedForm(session); + form = ${managedBeansPackage}.JsfUtils.getSerializedForm(facesContext); } #end if (form != null) @@ -143,13 +136,13 @@ // - if the form is still null, see if we can get it from a serialized state if (form == null) { - form = ${managedBeansPackage}.JsfUtils.getSerializedForm(session); + form = ${managedBeansPackage}.JsfUtils.getSerializedForm(facesContext); } else { // - pass any properties from the serialized form along org.andromda.presentation.jsf2.FormPopulator.populateForm( - org.andromda.presentation.jsf2.JsfUtils.getSerializedForm(session), form); + org.andromda.presentation.jsf2.JsfUtils.getSerializedForm(facesContext), form); } #end } @@ -181,7 +174,7 @@ // - serialize the form if (form != null) { - ${managedBeansPackage}.JsfUtils.serializeForm(session, form); + ${managedBeansPackage}.JsfUtils.serializeForm(facesContext, form); } #end #if (!$view.variables.empty || !$view.backingValueVariables.empty) 1.2 +8 -1 cartridges/andromda-jsf2/src/main/resources/templates/jsf2/flow/LogOutServlet.java.vsl Index: LogOutServlet.java.vsl =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-jsf2/src/main/resources/templates/jsf2/flow/LogOutServlet.java.vsl,v retrieving revision 1.1 retrieving revision 1.2 diff -u -w -r1.1 -r1.2 --- LogOutServlet.java.vsl 5 Dec 2006 19:39:29 -0000 1.1 +++ LogOutServlet.java.vsl 8 Apr 2008 16:29:06 -0000 1.2 @@ -18,6 +18,8 @@ public class LogOutServlet extends HttpServlet { + private static final long serialVersionUID = 1L; + /** * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) */ @@ -27,7 +29,12 @@ throws ServletException, IOException { #if ($formSerialization) - ${managedBeansPackage}.JsfUtils.deleteSerializedForm(request.getSession()); +#set ($facesContextUtilsFullyQualifiedName = "FacesContextUtils") +#if ($stringUtils.isNotBlank($managedBeansPackage)) +#set($facesContextUtilsFullyQualifiedName = "${managedBeansPackage}.${facesContextUtilsFullyQualifiedName}") +#end + ${managedBeansPackage}.JsfUtils.deleteSerializedForm( + ${facesContextUtilsFullyQualifiedName}.getFacesContext(request, response)); #end request.getSession().invalidate(); response.sendRedirect(request.getContextPath() + "${useCase.path}.${facesServletExtension}"); 1.4 +67 -29 cartridges/andromda-jsf2/src/main/resources/templates/jsf2/utils/JsfUtils.java.vsl Index: JsfUtils.java.vsl =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-jsf2/src/main/resources/templates/jsf2/utils/JsfUtils.java.vsl,v retrieving revision 1.3 retrieving revision 1.4 diff -u -w -r1.3 -r1.4 --- JsfUtils.java.vsl 8 Apr 2008 01:20:28 -0000 1.3 +++ JsfUtils.java.vsl 8 Apr 2008 16:29:07 -0000 1.4 @@ -4,8 +4,6 @@ #end import org.apache.commons.lang.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; /** * Utilities used within the JSF Cartridge @@ -14,7 +12,8 @@ */ public class $className { - private static Log logger = LogFactory.getLog(JsfUtils.class); + private static org.apache.commons.logging.Log logger = + org.apache.commons.logging.LogFactory.getLog(JsfUtils.class); /** * The location of the temporary directoy used the JSF cartridge. @@ -45,15 +44,18 @@ /** * Attempts to serialize the given <code>form</code> to disk so that it * can later be retrieved when the user's session times out. - * @param session the session from which to create the serialization path. + * @param context the FacesContext from which to create the serialization path. * @param form the form to serialize. */ - public static void serializeForm(final $jsfUtils.sessionClassName session, final Object form) + public static void serializeForm(final javax.faces.context.FacesContext context, final Object form) { java.io.ObjectOutputStream objectStream = null; try { - final java.io.File serializationFile = new java.io.File(getFormSerializationPath(session)); + final String path = getFormSerializationPath(context); + if (StringUtils.isNotBlank(path)) + { + final java.io.File serializationFile = new java.io.File(getFormSerializationPath(context)); final java.io.File parent = serializationFile.getParentFile(); if (parent != null) { @@ -63,6 +65,7 @@ objectStream = new java.io.ObjectOutputStream(fileStream); objectStream.writeObject(form); } + } catch (final Exception exception) { logger.warn(exception); @@ -85,20 +88,24 @@ /** * Retrieves the current serialized form for the given session. - * @param session the session. + * @param context the FacesContext * @return the serialized form. * @throws Exception */ - public static Object getSerializedForm(final $jsfUtils.sessionClassName session) + public static Object getSerializedForm(final javax.faces.context.FacesContext context) { Object form = null; java.io.ObjectInputStream objectStream = null; try { - java.io.FileInputStream fileStream = new java.io.FileInputStream(getFormSerializationPath(session)); + final String path = getFormSerializationPath(context); + if (StringUtils.isNotBlank(path)) + { + java.io.FileInputStream fileStream = new java.io.FileInputStream(path); objectStream = new java.io.ObjectInputStream(fileStream); form = objectStream.readObject(); } + } catch (final Exception exception) { // - ignore if we couldn't retrieve the serialized form @@ -125,10 +132,13 @@ * * @param session the session for which to remove the serialized form. */ - public static void deleteSerializedForm(final $jsfUtils.sessionClassName session) + public static void deleteSerializedForm(final javax.faces.context.FacesContext context) + { + final String path = getFormSerializationPath(context); + if (StringUtils.isNotBlank(path)) { final java.io.File serializationFile = - new java.io.File(getFormSerializationPath(session)); + new java.io.File(getFormSerializationPath(context)); serializationFile.delete(); final java.io.File directory = serializationFile.getParentFile(); if (directory != null) @@ -136,20 +146,49 @@ directory.delete(); } } - + } +#if ($standalone) /** * The name of the file storing the serialized form. */ private static final String SERIALIZED_FORM_FILE_NAME = "/form.ser"; +#else + /** + * Pattern used to strip characters not used in the portlet serialization file. + */ + private static final String NAMESPACE_STRIP_PATTERN = "\\p{Punct}"; + + private static String getSerializationFileName(final Object response) + { + String fileName = null; + if (response instanceof javax.portlet.RenderResponse) + { + fileName = ((javax.portlet.RenderResponse)response).getNamespace().replaceAll(NAMESPACE_STRIP_PATTERN, ""); + } + return fileName; + } + +#end /** * Retrieves the path in which the serialized form will be stored. * @param session the session containing the unique id in which to create the path. * @return the path to which serialization occurs. */ - private static String getFormSerializationPath(final $jsfUtils.sessionClassName session) + private static String getFormSerializationPath(final javax.faces.context.FacesContext context) + { + final String sessionId = (($jsfUtils.sessionClassName)context.getExternalContext().getSession(true)).getId(); +#if ($standalone) + return TEMPORARY_DIRECTORY + sessionId + SERIALIZED_FORM_FILE_NAME; +#else + final String serializationFileName = getSerializationFileName(context.getExternalContext().getResponse()); + String path = null; + if (StringUtils.isNotBlank(serializationFileName)) { - return TEMPORARY_DIRECTORY + session.getId() + SERIALIZED_FORM_FILE_NAME; + path = TEMPORARY_DIRECTORY + sessionId + '/' + serializationFileName; + } + return path; +#end } /** @@ -201,5 +240,4 @@ } throw new RuntimeException("Parameter "+parameterName+" not found"); } - } 1.4 +8 -8 cartridges/andromda-jsf2/src/main/resources/templates/jsf2/flow/crud/ViewPopulator.java.vsl Index: ViewPopulator.java.vsl =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-jsf2/src/main/resources/templates/jsf2/flow/crud/ViewPopulator.java.vsl,v retrieving revision 1.3 retrieving revision 1.4 diff -u -w -r1.3 -r1.4 --- ViewPopulator.java.vsl 18 Jan 2007 10:11:07 -0000 1.3 +++ ViewPopulator.java.vsl 8 Apr 2008 16:29:07 -0000 1.4 @@ -76,7 +76,7 @@ // - if the form is still null, see if we can get it from a serialized state if (form == null) { - form = ${managedBeansPackage}.JsfUtils.getSerializedForm(session); + form = ${managedBeansPackage}.JsfUtils.getSerializedForm(facesContext); } #end try @@ -95,7 +95,7 @@ // - serialize the form if (form != null) { - ${managedBeansPackage}.JsfUtils.serializeForm(session, form); + ${managedBeansPackage}.JsfUtils.serializeForm(facesContext, form); } #end } |
From: Walter M. <wal...@us...> - 2008-07-26 12:10:41
|
User: walterim Date: 08/07/26 05:10:50 Modified: andromda-jsf2/src/main/resources/META-INF/andromda metafacades.xml namespace.xml andromda-jsf2/src/main/resources/templates/jsf2/controllers/crud Controller.java.vsl andromda-jsf2/src/main/java/org/andromda/cartridges/jsf2 JSFGlobals.java andromda-jsf2/src/main/uml JSFMetafacadeModel.xml.zip andromda-jsf2/src/main/java/org/andromda/cartridges/jsf2/metafacades JSFManageableEntityLogicImpl.java andromda-jsf2/src/main/resources/templates/jsf2/flow/crud ViewPopulator.java.vsl Log: Get rid off the manageableActionFormKey, since it looks not needed and was leading to errors in jsf messages forwarding. Revision Changes Path 1.6 +0 -1 cartridges/andromda-jsf2/src/main/resources/META-INF/andromda/metafacades.xml Index: metafacades.xml =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-jsf2/src/main/resources/META-INF/andromda/metafacades.xml,v retrieving revision 1.5 retrieving revision 1.6 diff -u -w -r1.5 -r1.6 --- metafacades.xml 10 Jul 2008 14:59:51 -0000 1.5 +++ metafacades.xml 26 Jul 2008 12:10:48 -0000 1.6 @@ -135,7 +135,6 @@ <stereotype>MANAGEABLE</stereotype> </mapping> <property reference="crudValueObjectSuffix"/> - <property reference="manageableActionFormKey"/> <property reference="defaultTableExportTypes"/> <property reference="viewPopulatorPattern"/> </metafacade> 1.13 +0 -8 cartridges/andromda-jsf2/src/main/resources/META-INF/andromda/namespace.xml Index: namespace.xml =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-jsf2/src/main/resources/META-INF/andromda/namespace.xml,v retrieving revision 1.12 retrieving revision 1.13 diff -u -w -r1.12 -r1.13 --- namespace.xml 10 Jul 2008 14:59:51 -0000 1.12 +++ namespace.xml 26 Jul 2008 12:10:48 -0000 1.13 @@ -80,14 +80,6 @@ The suffix to append to the names of generated value objects used in CRUD (manageable entities). </documentation> </property> - <property name="manageableActionFormKey"> - <default>manageableForm</default> - <documentation> - The name of the key under which each manageable action form is stored. This - form is passed along from action to action in order to transfer - all parameters. - </documentation> - </property> </propertyGroup> <propertyGroup name="Configuration"> <documentation> 1.18 +31 -11 cartridges/andromda-jsf2/src/main/resources/templates/jsf2/controllers/crud/Controller.java.vsl Index: Controller.java.vsl =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-jsf2/src/main/resources/templates/jsf2/controllers/crud/Controller.java.vsl,v retrieving revision 1.17 retrieving revision 1.18 diff -u -w -r1.17 -r1.18 --- Controller.java.vsl 21 Jul 2008 22:35:56 -0000 1.17 +++ Controller.java.vsl 26 Jul 2008 12:10:48 -0000 1.18 @@ -14,7 +14,7 @@ try { - contextWrapper.getCurrentInstance().getPageFlowScope().put("${manageable.formKey}", form); + contextWrapper.getCurrentInstance().getPageFlowScope().put("${actionFormKey}", form); this.doInit(form); } @@ -77,7 +77,7 @@ try { - contextWrapper.getCurrentInstance().getPageFlowScope().put("${manageable.formKey}", form); + contextWrapper.getCurrentInstance().getPageFlowScope().put("${actionFormKey}", form); this.doLoad(${idParamClass}.valueOf(((javax.faces.component.UIParameter)event.getComponent().findComponent("${manageable.manageableIdentifier.name}")).getValue().toString()),form); } @@ -122,7 +122,7 @@ try { - contextWrapper.getCurrentInstance().getPageFlowScope().put("${manageable.formKey}", form); + contextWrapper.getCurrentInstance().getPageFlowScope().put("${actionFormKey}", form); this.doCancel(form); } @@ -157,7 +157,7 @@ try { - contextWrapper.getCurrentInstance().getPageFlowScope().put("${manageable.formKey}", form); + contextWrapper.getCurrentInstance().getPageFlowScope().put("${actionFormKey}", form); this.doStartNew(form); } @@ -245,7 +245,7 @@ try { - contextWrapper.getCurrentInstance().getPageFlowScope().put("${manageable.formKey}", form); + contextWrapper.getCurrentInstance().getPageFlowScope().put("${actionFormKey}", form); this.doSave(form); } @@ -319,7 +319,7 @@ try { - contextWrapper.getCurrentInstance().getPageFlowScope().put("${manageable.formKey}", form); + contextWrapper.getCurrentInstance().getPageFlowScope().put("${actionFormKey}", form); this.doSave(form); this.doStartNew(form); @@ -351,7 +351,7 @@ try { - contextWrapper.getCurrentInstance().getPageFlowScope().put("${manageable.formKey}", form); + contextWrapper.getCurrentInstance().getPageFlowScope().put("${actionFormKey}", form); this.doSearch(form); } @@ -440,7 +440,7 @@ try { - contextWrapper.getCurrentInstance().getPageFlowScope().put("${manageable.formKey}", form); + contextWrapper.getCurrentInstance().getPageFlowScope().put("${actionFormKey}", form); this.doDelete(${idParamClass}.valueOf(((javax.faces.component.UIParameter)event.getComponent().findComponent("${manageable.manageableIdentifier.name}")).getValue().toString()),form); } @@ -600,8 +600,28 @@ */ protected java.lang.Object resolveVariable(final String name) { + org.apache.myfaces.trinidad.context.RequestContext adfContext = org.apache.myfaces.trinidad.context.RequestContext.getCurrentInstance(); + Object variable = adfContext.getPageFlowScope().get(name); + // - if we couldn't get the variable from the regular ADF context, see if + // the session contains an ADF context with the variable + if (variable == null) + { + final javax.servlet.http.HttpSession session = this.getSession(false); + if (session != null) + { + final org.trinityssm.webapp.AdfFacesContextWrapper contextWrapper = + (org.trinityssm.webapp.AdfFacesContextWrapper)session.getAttribute("AndroMDAADFContext"); + adfContext = contextWrapper != null ? contextWrapper.getCurrentInstance() : null; + } + variable = adfContext != null ? adfContext.getPageFlowScope().get(name) : null; + } + // - finally try resolving it in the standard JSF manner + if (variable == null) + { final javax.faces.context.FacesContext context = this.getContext(); - return context.getApplication().getVariableResolver().resolveVariable(context, name); + variable = context != null ? context.getApplication().getVariableResolver().resolveVariable(context, name) : null; + } + return variable; } /** @@ -677,7 +697,7 @@ { final javax.faces.application.FacesMessage facesMessage = new javax.faces.application.FacesMessage(severity, message, message); final org.apache.myfaces.trinidad.context.RequestContext adfContext = org.apache.myfaces.trinidad.context.RequestContext.getCurrentInstance(); - final Object form = adfContext.getPageFlowScope().get("$actionFormKey"); + final Object form = adfContext.getPageFlowScope().get("${actionFormKey}"); if (form != null) { try 1.6 +0 -5 cartridges/andromda-jsf2/src/main/java/org/andromda/cartridges/jsf2/JSFGlobals.java Index: JSFGlobals.java =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-jsf2/src/main/java/org/andromda/cartridges/jsf2/JSFGlobals.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -w -r1.5 -r1.6 --- JSFGlobals.java 10 Jul 2008 14:59:52 -0000 1.5 +++ JSFGlobals.java 26 Jul 2008 12:10:49 -0000 1.6 @@ -14,11 +14,6 @@ public static final String CRUD_VALUE_OBJECT_SUFFIX = "crudValueObjectSuffix"; /** - * The default key under which the manageable action form is stored. - */ - public static final String CRUD_ACTION_FORM_KEY = "manageableActionFormKey"; - - /** * A space-separated list of types to which displaytag table are to be exported by default. */ public static final String PROPERTY_DEFAULT_TABLE_EXPORT_TYPES = "defaultTableExportTypes"; 1.16 +190 -184 cartridges/andromda-jsf2/src/main/uml/JSFMetafacadeModel.xml.zip <<Binary file>> 1.9 +0 -10 cartridges/andromda-jsf2/src/main/java/org/andromda/cartridges/jsf2/metafacades/JSFManageableEntityLogicImpl.java Index: JSFManageableEntityLogicImpl.java =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-jsf2/src/main/java/org/andromda/cartridges/jsf2/metafacades/JSFManageableEntityLogicImpl.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -w -r1.8 -r1.9 --- JSFManageableEntityLogicImpl.java 10 Jul 2008 14:59:52 -0000 1.8 +++ JSFManageableEntityLogicImpl.java 26 Jul 2008 12:10:50 -0000 1.9 @@ -368,16 +368,6 @@ } /** - * @see org.andromda.cartridges.jsf2.metafacades.JSFManageableEntity#getFormKey() - */ - protected java.lang.String handleGetFormKey() - { - final Object formKeyValue = this.findTaggedValue(JSFProfile.TAGGEDVALUE_ACTION_FORM_KEY); - return formKeyValue == null ? ObjectUtils.toString(this.getConfiguredProperty(JSFGlobals.CRUD_ACTION_FORM_KEY)) - : String.valueOf(formKeyValue); - } - - /** * @see org.andromda.cartridges.jsf2.metafacades.JSFManageableEntity#getViewFullPath() */ protected java.lang.String handleGetViewFullPath() 1.5 +1 -1 cartridges/andromda-jsf2/src/main/resources/templates/jsf2/flow/crud/ViewPopulator.java.vsl Index: ViewPopulator.java.vsl =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-jsf2/src/main/resources/templates/jsf2/flow/crud/ViewPopulator.java.vsl,v retrieving revision 1.4 retrieving revision 1.5 diff -u -w -r1.4 -r1.5 --- ViewPopulator.java.vsl 8 Apr 2008 16:29:07 -0000 1.4 +++ ViewPopulator.java.vsl 26 Jul 2008 12:10:50 -0000 1.5 @@ -68,7 +68,7 @@ org.apache.myfaces.trinidad.context.RequestContext adfContext = org.apache.myfaces.trinidad.context.RequestContext.getCurrentInstance(); final javax.faces.el.VariableResolver variableResolver = facesContext.getApplication().getVariableResolver(); - form = adfContext.getPageFlowScope().get("$manageable.formKey"); + form = adfContext.getPageFlowScope().get("$actionFormKey"); #if ($formSerialization) final javax.servlet.http.HttpSession session = ((javax.servlet.http.HttpServletRequest)request).getSession(); |