From: Walter M. <wal...@us...> - 2007-01-11 17:35:55
|
User: walterim Date: 07/01/11 09:35:53 Modified: andromda-jsf2/src/main/resources/templates/jsf2/flow/crud ViewPopulator.java.vsl andromda-jsf2/src/main/resources/templates/jsf2/views/facelets/crud view.xhtml.vsl andromda-jsf2/src/main/resources/templates/jsf2/controllers/crud Controller.java.vsl Log: Bug fixes Revision Changes Path 1.2 +9 -35 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.1 retrieving revision 1.2 diff -u -w -r1.1 -r1.2 --- ViewPopulator.java.vsl 11 Dec 2006 13:43:57 -0000 1.1 +++ ViewPopulator.java.vsl 11 Jan 2007 17:35:53 -0000 1.2 @@ -67,47 +67,22 @@ org.apache.myfaces.trinidad.context.RequestContext adfContext = org.apache.myfaces.trinidad.context.RequestContext.getCurrentInstance(); final javax.faces.el.VariableResolver variableResolver = facesContext.getApplication().getVariableResolver(); - final javax.servlet.http.HttpSession session = ((javax.servlet.http.HttpServletRequest)request).getSession(); - if (form == null) - { - // - first try getting the form from the ADF PageFlowScope + form = adfContext.getPageFlowScope().get("$manageable.formKey"); - // - if the form is null, try getting the current adfContext from the session (and then remove it from the session) - if (form == null) - { - final ${managedBeansPackage}.AdfFacesContextWrapper contextWrapper = - (${managedBeansPackage}.AdfFacesContextWrapper)session.getAttribute("$adfContextAttributeName"); - adfContext = contextWrapper != null ? contextWrapper.getCurrentInstance() : null; - form = adfContext != null ? adfContext.getPageFlowScope().get("$manageable.formKey") : null; + #if ($formSerialization) + final javax.servlet.http.HttpSession session = ((javax.servlet.http.HttpServletRequest)request).getSession(); + // - if the form is still null, see if we can get it from a serialized state if (form == null) { form = ${managedBeansPackage}.JsfUtils.getSerializedForm(session); } #end - if (form != null) - { - // - add the form to the current process scope since it wasn't in the current one to begin with - org.apache.myfaces.trinidad.context.RequestContext.getCurrentInstance().getPageFlowScope().put("$manageable.formKey", form); - } - } - else - { - // - remove the ADF context in the event that its present - session.removeAttribute("AndroMDAADFContext"); - } - } - else - { - // - since the form argument is not null, set it as the "$manageable.formKey" in the PageFlowScope - // (to replace the existing "$manageable.formKey" attribute) - adfContext.getPageFlowScope().put("$manageable.formKey", form); - } try { // - populate the forms - if (form != null) + if (form != null && form instanceof $manageable.formBeanType) { $manageable.formBeanType $manageable.formBeanName = (${manageable.formBeanType})variableResolver.resolveVariable( @@ -115,7 +90,6 @@ "$manageable.formBeanName"); // - populate the $manageable.formBeanName with any parameters from the previous form ${managedBeansPackage}.${formPopulatorName}.populateForm(form, $manageable.formBeanName); - request.setAttribute("$manageable.formBeanName", $manageable.formBeanName); } #if ($formSerialization) // - serialize the form 1.3 +10 -16 cartridges/andromda-jsf2/src/main/resources/templates/jsf2/views/facelets/crud/view.xhtml.vsl Index: view.xhtml.vsl =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-jsf2/src/main/resources/templates/jsf2/views/facelets/crud/view.xhtml.vsl,v retrieving revision 1.2 retrieving revision 1.3 diff -u -w -r1.2 -r1.3 --- view.xhtml.vsl 12 Dec 2006 18:46:32 -0000 1.2 +++ view.xhtml.vsl 11 Jan 2007 17:35:53 -0000 1.3 @@ -89,8 +89,7 @@ ## deixei false em função da discrepância com o uso do \ no javascript#set ($clientValidation = $clientValidation && $manageable.validationRequired) #set ($clientValidation = false) #set ($formValidateName = "validate$stringUtils.capitalize($formName)") - <c:if test="#{!${formName}.editState}"> - <tr:subform id="${formName}_search" enctype="multipart/form-data"> + <tr:subform id="${formName}_search" rendered="#{!${formName}.editState}"> <tr:panelFormLayout> #foreach ($field in $manageable.manageableSearchAttributes) #renderSearchInput($field) @@ -113,16 +112,14 @@ #end <f:facet name="footer"> <tr:panelButtonBar> - <tr:commandButton text="#{messages['action.search']}" action="#{${manageable.controllerBeanName}.search}" accessKey="#{messages['action.search.access.key']}"/> + <tr:commandButton id="searchButton" text="#{messages['action.search']}" action="#{${manageable.controllerBeanName}.search}" accessKey="#{messages['action.search.access.key']}"/> #if ($manageable.create) - <tr:commandButton text="#{messages['action.new']}" action="#{${manageable.controllerBeanName}.startNew}" accessKey="#{messages['action.new.access.key']}"/> + <tr:commandButton id="newButton" text="#{messages['action.new']}" action="#{${manageable.controllerBeanName}.startNew}" accessKey="#{messages['action.new.access.key']}"/> #end </tr:panelButtonBar> </f:facet> </tr:panelFormLayout> - </tr:subform> - <tr:subform> - <tr:table allDetailsEnabled="true" var="row" bandingInterval="1" banding="row" value="#{${formName}.${manageable.listName}}" rows="#{${preferencesBeanName}.maxTableRows}" width="90%"> + <tr:table allDetailsEnabled="true" var="row" bandingInterval="1" banding="row" value="#{${formName}.${manageable.listName}}" rows="#{${preferencesBeanName}.maxTableRows}" width="90%" rendered="#{!empty ${formName}.${manageable.listName}}"> <tr:column width="46px"> <f:facet name="header"> <h:panelGroup><t:graphicImage url="/images/space.gif"/></h:panelGroup> @@ -162,14 +159,11 @@ #end </tr:table> </tr:subform> - </c:if> - <c:if test="#{${formName}.editState}"> - <tr:subform> + <tr:group rendered="#{${formName}.editState}"> <tr:commandLink action="#{${manageable.controllerBeanName}.back}" accessKey="#{messages['action.back.access.key']}"> <t:graphicImage url="/skins/#{${preferencesBeanName}.skin}/images/back.gif" title="#{messages['action.back']}" border="0" /> </tr:commandLink> - </tr:subform> - <tr:subform id="$formName"#if($clientValidation) onsubmit="return $formValidateName(this);"#end enctype="multipart/form-data"> + <tr:subform id="${formName}_edit" #if($clientValidation) onsubmit="return $formValidateName(this);"#end> <tr:panelFormLayout> #foreach ($field in $manageable.manageableAttributes) #if($field.hidden) @@ -204,7 +198,7 @@ </tr:panelFormLayout> <a:validator#if(!$clientValidation) client="false"#end/> </tr:subform> - </c:if> + </tr:group> </ui:define> </ui:composition> 1.2 +52 -185 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.1 retrieving revision 1.2 diff -u -w -r1.1 -r1.2 --- Controller.java.vsl 11 Dec 2006 13:43:58 -0000 1.1 +++ Controller.java.vsl 11 Jan 2007 17:35:53 -0000 1.2 @@ -12,24 +12,21 @@ public String init(){ final org.andromda.presentation.jsf2.AdfFacesContextWrapper contextWrapper = new org.andromda.presentation.jsf2.AdfFacesContextWrapper(); - final Object currentForm = this.resolveVariable("form"); try { final ${manageable.formBeanType} form = this.getForm(); - // - populate the form with any request parameters that may match - this.populateFormFromRequestParameters(form, form.getDateTimeFormatters()); try { contextWrapper.getCurrentInstance().getPageFlowScope().put("form", form); - // - add this temporary ADF context to the session so that we can retrieve from a view populator if required - this.getSession(false).setAttribute("AndroMDAADFContext", contextWrapper); + + // - populate the form with any request parameters that may match + this.populateFormFromRequestParameters(form, form.getDateTimeFormatters()); this.doInit(form); } catch (final Throwable throwable) { - contextWrapper.getCurrentInstance().getPageFlowScope().put("form", currentForm); final String message = org.andromda.presentation.jsf2.Messages.get( org.andromda.presentation.jsf2.PatternMatchingExceptionHandler.instance().handleException(throwable), null); throwable.printStackTrace(); @@ -38,55 +35,51 @@ } catch (final Throwable throwable) { - contextWrapper.getCurrentInstance().getPageFlowScope().put("form", currentForm); this.addExceptionMessage(throwable); } - return "${manageable.viewFullPath}"; } public void doInit(${manageable.formBeanType} form) throws Exception { -#if ($manageable.preload) - final java.util.List list = ${manageable.manageableServiceAccessorCall}.readAll(); - - form.${manageable.listSetterName}(list); - -#if ($manageable.maximumListSize > 0) - if (list.size() >= $manageable.maximumListSize) - saveMaxResultsWarning(); - -#end -#if (!$manageable.manageableAssociationEnds.empty) - final java.util.Map backingLists = ${manageable.manageableServiceAccessorCall}.readBackingLists(); -#foreach ($member in $manageable.manageableAssociationEnds) - form.${member.setterName}BackingList((java.util.Collection)backingLists.get("${member.name}")); -#end - -#end +## does not preload the data anymore... testing. +###if ($manageable.preload) +## final java.util.List list = ${manageable.manageableServiceAccessorCall}.readAll(); +## +## form.${manageable.listSetterName}(list); +## +###if ($manageable.maximumListSize > 0) +## if (list.size() >= $manageable.maximumListSize) +## saveMaxResultsWarning(); +## +###end +###if (!$manageable.manageableAssociationEnds.empty) +## final java.util.Map backingLists = ${manageable.manageableServiceAccessorCall}.readBackingLists(); +###foreach ($member in $manageable.manageableAssociationEnds) +## form.${member.setterName}BackingList((java.util.Collection)backingLists.get("${member.name}")); +###end +## +###end +###end form.setEditState(false); -#end } public String load(){ final org.andromda.presentation.jsf2.AdfFacesContextWrapper contextWrapper = new org.andromda.presentation.jsf2.AdfFacesContextWrapper(); - final Object currentForm = this.resolveVariable("form"); try { final ${manageable.formBeanType} form = this.getForm(); - // - populate the form with any request parameters that may match - this.populateFormFromRequestParameters(form, form.getDateTimeFormatters()); try { contextWrapper.getCurrentInstance().getPageFlowScope().put("form", form); - // - add this temporary ADF context to the session so that we can retrieve from a view populator if required - this.getSession(false).setAttribute("AndroMDAADFContext", contextWrapper); + + // - populate the form with any request parameters that may match + this.populateFormFromRequestParameters(form, form.getDateTimeFormatters()); this.doLoad(form); } catch (final Throwable throwable) { - contextWrapper.getCurrentInstance().getPageFlowScope().put("form", currentForm); final String message = org.andromda.presentation.jsf2.Messages.get( org.andromda.presentation.jsf2.PatternMatchingExceptionHandler.instance().handleException(throwable), null); this.addErrorMessage(message); @@ -94,15 +87,14 @@ } catch (final Throwable throwable) { - contextWrapper.getCurrentInstance().getPageFlowScope().put("form", currentForm); this.addExceptionMessage(throwable); } - return null; + return "${manageable.viewFullPath}"; } public void doLoad(${manageable.formBeanType} form) throws Exception { final Object vo= - ${manageable.manageableServiceAccessorCall}.load(form.${manageable.manageableIdentifier.getterName}()); + ${manageable.manageableServiceAccessorCall}.readById(form.${manageable.manageableIdentifier.getterName}()); ## fazer via members org.apache.commons.beanutils.BeanUtils.copyProperties(form,vo); @@ -112,24 +104,21 @@ public String back(){ final org.andromda.presentation.jsf2.AdfFacesContextWrapper contextWrapper = new org.andromda.presentation.jsf2.AdfFacesContextWrapper(); - final Object currentForm = this.resolveVariable("form"); try { final ${manageable.formBeanType} form = this.getForm(); - // - populate the form with any request parameters that may match - this.populateFormFromRequestParameters(form, form.getDateTimeFormatters()); try { contextWrapper.getCurrentInstance().getPageFlowScope().put("form", form); - // - add this temporary ADF context to the session so that we can retrieve from a view populator if required - this.getSession(false).setAttribute("AndroMDAADFContext", contextWrapper); + + // - populate the form with any request parameters that may match + this.populateFormFromRequestParameters(form, form.getDateTimeFormatters()); this.doBack(form); } catch (final Throwable throwable) { - contextWrapper.getCurrentInstance().getPageFlowScope().put("form", currentForm); final String message = org.andromda.presentation.jsf2.Messages.get( org.andromda.presentation.jsf2.PatternMatchingExceptionHandler.instance().handleException(throwable), null); this.addErrorMessage(message); @@ -137,10 +126,9 @@ } catch (final Throwable throwable) { - contextWrapper.getCurrentInstance().getPageFlowScope().put("form", currentForm); this.addExceptionMessage(throwable); } - return null; + return "${manageable.viewFullPath}"; } public void doBack(${manageable.formBeanType} form) throws Exception { @@ -150,24 +138,21 @@ #if ($manageable.create) public String startNew(){ final org.andromda.presentation.jsf2.AdfFacesContextWrapper contextWrapper = new org.andromda.presentation.jsf2.AdfFacesContextWrapper(); - final Object currentForm = this.resolveVariable("form"); try { final ${manageable.formBeanType} form = this.getForm(); - // - populate the form with any request parameters that may match - this.populateFormFromRequestParameters(form, form.getDateTimeFormatters()); try { contextWrapper.getCurrentInstance().getPageFlowScope().put("form", form); - // - add this temporary ADF context to the session so that we can retrieve from a view populator if required - this.getSession(false).setAttribute("AndroMDAADFContext", contextWrapper); + + // - populate the form with any request parameters that may match + this.populateFormFromRequestParameters(form, form.getDateTimeFormatters()); this.doStartNew(form); } catch (final Throwable throwable) { - contextWrapper.getCurrentInstance().getPageFlowScope().put("form", currentForm); final String message = org.andromda.presentation.jsf2.Messages.get( org.andromda.presentation.jsf2.PatternMatchingExceptionHandler.instance().handleException(throwable), null); this.addErrorMessage(message); @@ -175,10 +160,9 @@ } catch (final Throwable throwable) { - contextWrapper.getCurrentInstance().getPageFlowScope().put("form", currentForm); this.addExceptionMessage(throwable); } - return null; + return "${manageable.viewFullPath}"; } public void doStartNew(${manageable.formBeanType} form) throws Exception { @@ -233,24 +217,21 @@ #if ($manageable.create || $manageable.update) public String save(){ final org.andromda.presentation.jsf2.AdfFacesContextWrapper contextWrapper = new org.andromda.presentation.jsf2.AdfFacesContextWrapper(); - final Object currentForm = this.resolveVariable("form"); try { final ${manageable.formBeanType} form = this.getForm(); - // - populate the form with any request parameters that may match - this.populateFormFromRequestParameters(form, form.getDateTimeFormatters()); try { contextWrapper.getCurrentInstance().getPageFlowScope().put("form", form); - // - add this temporary ADF context to the session so that we can retrieve from a view populator if required - this.getSession(false).setAttribute("AndroMDAADFContext", contextWrapper); + + // - populate the form with any request parameters that may match + this.populateFormFromRequestParameters(form, form.getDateTimeFormatters()); this.doSave(form); } catch (final Throwable throwable) { - contextWrapper.getCurrentInstance().getPageFlowScope().put("form", currentForm); final String message = org.andromda.presentation.jsf2.Messages.get( org.andromda.presentation.jsf2.PatternMatchingExceptionHandler.instance().handleException(throwable), null); this.addErrorMessage(message); @@ -258,10 +239,9 @@ } catch (final Throwable throwable) { - contextWrapper.getCurrentInstance().getPageFlowScope().put("form", currentForm); this.addExceptionMessage(throwable); } - return null; + return "${manageable.viewFullPath}"; } public void doSave(${manageable.formBeanType} form) throws Exception { @@ -285,29 +265,27 @@ ); } - doSearch(form); + if(form.${manageable.listGetterName}() != null) //only searches again if there was an old search + doSearch(form); //search again to show the updated item (if it fits the search criteria) } #end public String search(){ final org.andromda.presentation.jsf2.AdfFacesContextWrapper contextWrapper = new org.andromda.presentation.jsf2.AdfFacesContextWrapper(); - final Object currentForm = this.resolveVariable("form"); try { final ${manageable.formBeanType} form = this.getForm(); - // - populate the form with any request parameters that may match - this.populateFormFromRequestParameters(form, form.getDateTimeFormatters()); try { contextWrapper.getCurrentInstance().getPageFlowScope().put("form", form); - // - add this temporary ADF context to the session so that we can retrieve from a view populator if required - this.getSession(false).setAttribute("AndroMDAADFContext", contextWrapper); + + // - populate the form with any request parameters that may match + this.populateFormFromRequestParameters(form, form.getDateTimeFormatters()); this.doSearch(form); } catch (final Throwable throwable) { - contextWrapper.getCurrentInstance().getPageFlowScope().put("form", currentForm); final String message = org.andromda.presentation.jsf2.Messages.get( org.andromda.presentation.jsf2.PatternMatchingExceptionHandler.instance().handleException(throwable), null); this.addErrorMessage(message); @@ -315,7 +293,6 @@ } catch (final Throwable throwable) { - contextWrapper.getCurrentInstance().getPageFlowScope().put("form", currentForm); this.addExceptionMessage(throwable); } return null; @@ -336,6 +313,9 @@ form.${manageable.listSetterName}(list); + if(list.size() == 0) + addWarningMessage(org.andromda.presentation.jsf2.Messages.get("no.entity.found", new Object[]{org.andromda.presentation.jsf2.Messages.get("$manageable.messageKey",null)})); + #if ($manageable.maximumListSize > 0) if (list.size() >= $manageable.maximumListSize) saveMaxResultsWarning(); @@ -354,24 +334,21 @@ #if ($manageable.delete) public String delete(){ final org.andromda.presentation.jsf2.AdfFacesContextWrapper contextWrapper = new org.andromda.presentation.jsf2.AdfFacesContextWrapper(); - final Object currentForm = this.resolveVariable("form"); try { final ${manageable.formBeanType} form = this.getForm(); - // - populate the form with any request parameters that may match - this.populateFormFromRequestParameters(form, form.getDateTimeFormatters()); try { contextWrapper.getCurrentInstance().getPageFlowScope().put("form", form); - // - add this temporary ADF context to the session so that we can retrieve from a view populator if required - this.getSession(false).setAttribute("AndroMDAADFContext", contextWrapper); + + // - populate the form with any request parameters that may match + this.populateFormFromRequestParameters(form, form.getDateTimeFormatters()); this.doDelete(form); } catch (final Throwable throwable) { - contextWrapper.getCurrentInstance().getPageFlowScope().put("form", currentForm); final String message = org.andromda.presentation.jsf2.Messages.get( org.andromda.presentation.jsf2.PatternMatchingExceptionHandler.instance().handleException(throwable), null); this.addErrorMessage(message); @@ -379,7 +356,6 @@ } catch (final Throwable throwable) { - contextWrapper.getCurrentInstance().getPageFlowScope().put("form", currentForm); this.addExceptionMessage(throwable); } return null; @@ -402,10 +378,6 @@ protected ${manageable.formBeanType} getForm() { - // - we do this in the case a button that submitted the form was set to immediate (this should be removed - // when we found a better way to handle this). - final javax.faces.component.UIForm uiForm = this.findForm(this.getContext().getViewRoot(), "${manageable.formBeanName}"); - this.populateComponentInputs(uiForm); return (${manageable.formBeanType})this.resolveVariable("${manageable.formBeanName}"); } @@ -465,28 +437,8 @@ */ 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 ${managedBeansPackage}.AdfFacesContextWrapper contextWrapper = - (${managedBeansPackage}.AdfFacesContextWrapper)session.getAttribute("$adfContextAttributeName"); - 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(); - variable = context != null ? context.getApplication().getVariableResolver().resolveVariable(context, name) : null; - } - return variable; + return context.getApplication().getVariableResolver().resolveVariable(context, name); } /** @@ -580,15 +532,6 @@ } /** - * Copies all matching properties from the <code>fromForm</code> to the given - * <code>toForm</code> overridding any previously set values. - */ - protected void copyForm(final Object fromForm, final Object toForm) - { - ${managedBeansPackage}.${formPopulatorName}.populateForm(fromForm, toForm, true); - } - - /** * Populates the form from the given parameters. If the request parameter is null or an empty * string, then null is placed on the form. * @@ -645,80 +588,4 @@ } } - /** - * Finds the form (if one is present) on the given <code>component</code> having the given - * <code>id</code>. - * - * @param component the component to search. - * @param id the id of the form. - * @return the form or null if none was found. - */ - private javax.faces.component.UIForm findForm(javax.faces.component.UIComponent component, String id) - { - javax.faces.component.UIForm foundForm = null; - if (component != null) - { - for (final java.util.Iterator iterator = component.getFacetsAndChildren(); iterator.hasNext();) - { - final Object object = iterator.next(); - if (object instanceof javax.faces.component.UIComponent) - { - final javax.faces.component.UIComponent uiComponent = (javax.faces.component.UIComponent)object; - if (uiComponent instanceof javax.faces.component.UIForm) - { - final javax.faces.component.UIForm form = (javax.faces.component.UIForm)uiComponent; - if (form.getId().equals(id)) - { - foundForm = form; - break; - } - } - foundForm = this.findForm(uiComponent, id); - if (foundForm != null) - { - break; - } - } - } - } - return foundForm; - } - - /** - * If the given <code>component</code> has an child input elements, this method findds - * them all and populates them. This is to get around the fact that when immediate is set to true - * on a button that submits the form that the form isn't populated. - * - * @param component the component to populate. - */ - private void populateComponentInputs(javax.faces.component.UIComponent component) - { - if (component != null) - { - for (final java.util.Iterator iterator = component.getFacetsAndChildren(); iterator.hasNext();) - { - final javax.faces.component.UIComponent uiComponent = (javax.faces.component.UIComponent)iterator.next(); - if (uiComponent instanceof javax.faces.component.UIInput) - { - try - { - final javax.faces.component.UIInput input = (javax.faces.component.UIInput)uiComponent; - input.validate(this.getContext()); - input.updateModel(this.getContext()); - } - catch (javax.faces.validator.ValidatorException exception) - { - // - ignore, no value is set (validate will be called by the regular - // JSF lifecycle processing anyway, this is just called to populate the - // local value - } - } - else - { - this.populateComponentInputs(uiComponent); - } - } - } - } - } \ No newline at end of file |