Author: craigmcc Date: Tue Jun 13 16:58:34 2006 New Revision: 414008 URL: http://svn.apache.org/viewvc?rev=414008&view=rev Log: More convenience methods for the convience base class for backing beans. This integration mirrors r412004 on the trunk, which was committed after the "mvn_reorg" branch was created.
Modified: struts/shale/branches/mvn_reorg/shale-core/src/main/java/org/apache/shale/view/AbstractFacesBean.java Modified: struts/shale/branches/mvn_reorg/shale-core/src/main/java/org/apache/shale/view/AbstractFacesBean.java URL: http://svn.apache.org/viewvc/struts/shale/branches/mvn_reorg/shale-core/src/main/java/org/apache/shale/view/AbstractFacesBean.java?rev=414008&r1=414007&r2=414008&view=diff ============================================================================== --- struts/shale/branches/mvn_reorg/shale-core/src/main/java/org/apache/shale/view/AbstractFacesBean.java (original) +++ struts/shale/branches/mvn_reorg/shale-core/src/main/java/org/apache/shale/view/AbstractFacesBean.java Tue Jun 13 16:58:34 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); + } }