Author: craigmcc Date: Mon Jun 5 21:58:14 2006 New Revision: 412004 URL: http://svn.apache.org/viewvc?rev=412004&view=rev Log: More convenience methods for the convenience base class for backing beans. This commit will also need to be ported to the mvn_reorg branch.
Modified: struts/shale/trunk/core-library/src/java/org/apache/shale/view/AbstractFacesBean.java struts/shale/trunk/tiger/nbproject/private/private.xml Modified: struts/shale/trunk/core-library/src/java/org/apache/shale/view/AbstractFacesBean.java URL: http://svn.apache.org/viewvc/struts/shale/trunk/core-library/src/java/org/apache/shale/view/AbstractFacesBean.java?rev=412004&r1=412003&r2=412004&view=diff ============================================================================== --- struts/shale/trunk/core-library/src/java/org/apache/shale/view/AbstractFacesBean.java (original) +++ struts/shale/trunk/core-library/src/java/org/apache/shale/view/AbstractFacesBean.java Mon Jun 5 21:58:14 2006 @@ -17,11 +17,13 @@ package org.apache.shale.view; import java.util.HashMap; +import java.util.Iterator; import java.util.Map; import javax.faces.FactoryFinder; import javax.faces.application.Application; import javax.faces.application.FacesMessage; +import javax.faces.component.EditableValueHolder; import javax.faces.component.UIComponent; import javax.faces.component.UIViewRoot; import javax.faces.context.ExternalContext; @@ -291,6 +293,48 @@ } + // -------------------------------------------------- Erase Submitted Values + + + /** + * <p>Erase submitted values on all <code>EditableValueHolder</code> + * components in the current view. This method should be called if + * you have input components bound to data values, submit the form, + * and then arbitrarily change the data that the binding points at + * without going through the <em>Update Model Values</em> phase of + * the request processing lifecycle.</p> + */ + protected void erase() { + + UIComponent view = getFacesContext().getViewRoot(); + if (view != null) { + erase(view); + } + + } + + + /** + * <p>Private helper method for <code>erase()</code> that recursively + * descends the component tree and performs the required processing.</p> + * + * @param component The component to be erased + */ + private void erase(UIComponent component) { + + // Erase the component itself (if needed) + if (component instanceof EditableValueHolder) { + ((EditableValueHolder) component).setSubmittedValue(null); + } + // Process the facets and children of this component + Iterator kids = component.getFacetsAndChildren(); + while (kids.hasNext()) { + erase((UIComponent) kids.next()); + } + + } + + // ----------------------------------------------- Request Parameter Methods @@ -333,7 +377,16 @@ */ protected void log(String message) { - getExternalContext().log(message); + FacesContext context = getFacesContext(); + ExternalContext econtext = null; + if (context != null) { + econtext = context.getExternalContext(); + } + if (econtext != null) { + econtext.log(message); + } else { + System.out.println(message); + } } @@ -346,7 +399,17 @@ */ protected void log(String message, Throwable throwable) { - getExternalContext().log(message, throwable); + FacesContext context = getFacesContext(); + ExternalContext econtext = null; + if (context != null) { + econtext = context.getExternalContext(); + } + if (econtext != null) { + econtext.log(message, throwable); + } else { + System.out.println(message); + throwable.printStackTrace(System.out); + } } Modified: struts/shale/trunk/tiger/nbproject/private/private.xml URL: http://svn.apache.org/viewvc/struts/shale/trunk/tiger/nbproject/private/private.xml?rev=412004&r1=412003&r2=412004&view=diff ============================================================================== --- struts/shale/trunk/tiger/nbproject/private/private.xml (original) +++ struts/shale/trunk/tiger/nbproject/private/private.xml Mon Jun 5 21:58:14 2006 @@ -1,4 +1,8 @@ <?xml version="1.0" encoding="UTF-8"?> <project-private xmlns="http://www.netbeans.org/ns/project-private/1"> <editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1"/> + <open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/1"> + <file>file:/C:/Apache/struts/current/shale/tiger/src/java/org/apache/shale/tiger/view/faces/LifecycleListener2.java</file> + <file>file:/C:/Apache/struts/current/shale/tiger/src/java/org/apache/shale/tiger/view/faces/ViewControllerCallbacks2.java</file> + </open-files> </project-private>