You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ma...@apache.org on 2010/04/01 14:51:56 UTC
svn commit: r929948 - in /myfaces/trinidad/branches/trinidad-1.2.x:
trinidad-build/src/main/resources/META-INF/maven-faces-plugin/components/trinidad/core/
trinidad-examples/trinidad-demo/src/main/webapp/
trinidad-impl/src/main/java/org/apache/myfaces/...
Author: matzew
Date: Thu Apr 1 12:51:55 2010
New Revision: 929948
URL: http://svn.apache.org/viewvc?rev=929948&view=rev
Log:
TRINIDAD-1772 - Allow per page state saving settings
Modified:
myfaces/trinidad/branches/trinidad-1.2.x/trinidad-build/src/main/resources/META-INF/maven-faces-plugin/components/trinidad/core/CoreDocument.xml
myfaces/trinidad/branches/trinidad-1.2.x/trinidad-examples/trinidad-demo/src/main/webapp/index.jspx
myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/application/StateManagerImpl.java
myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/DocumentRenderer.java
Modified: myfaces/trinidad/branches/trinidad-1.2.x/trinidad-build/src/main/resources/META-INF/maven-faces-plugin/components/trinidad/core/CoreDocument.xml
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-1.2.x/trinidad-build/src/main/resources/META-INF/maven-faces-plugin/components/trinidad/core/CoreDocument.xml?rev=929948&r1=929947&r2=929948&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-1.2.x/trinidad-build/src/main/resources/META-INF/maven-faces-plugin/components/trinidad/core/CoreDocument.xml (original)
+++ myfaces/trinidad/branches/trinidad-1.2.x/trinidad-build/src/main/resources/META-INF/maven-faces-plugin/components/trinidad/core/CoreDocument.xml Thu Apr 1 12:51:55 2010
@@ -51,6 +51,21 @@
</property-extension>
</property>
+ <property>
+ <description><![CDATA[Specify the state saving behavior for this page. client=force to be (full) client;
+ server=force to be server-side; default=follows the settings of the web.xml]]></description>
+ <property-name>stateSaving</property-name>
+ <property-class>java.lang.String</property-class>
+ <default-value>default</default-value>
+ <property-extension>
+ <mfp:property-metadata/>
+ <fmd:property-metadata>
+ <fmd:required>false</fmd:required>
+ <fmd:property-values>default client server</fmd:property-values>
+ </fmd:property-metadata>
+ </property-extension>
+ </property>
+
<xi:include href="includes/CommonDocumentAttrs.xml" xpointer="/faces-config/component/*"/>
<xi:include href="includes/CommonAttrs.xml" xpointer="/faces-config/component/*"/>
<xi:include href="includes/CoreJSEvents.xml" xpointer="/faces-config/component/*"/>
Modified: myfaces/trinidad/branches/trinidad-1.2.x/trinidad-examples/trinidad-demo/src/main/webapp/index.jspx
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-1.2.x/trinidad-examples/trinidad-demo/src/main/webapp/index.jspx?rev=929948&r1=929947&r2=929948&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-1.2.x/trinidad-examples/trinidad-demo/src/main/webapp/index.jspx (original)
+++ myfaces/trinidad/branches/trinidad-1.2.x/trinidad-examples/trinidad-demo/src/main/webapp/index.jspx Thu Apr 1 12:51:55 2010
@@ -23,7 +23,7 @@
xmlns:tr="http://myfaces.apache.org/trinidad" >
<jsp:directive.page contentType="text/html;charset=utf-8"/>
<f:view>
- <tr:document title="Apache Trinidad Demo Index">
+ <tr:document title="Apache Trinidad Demo Index" stateSaving="client">
<tr:form>
<tr:panelPage>
Modified: myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/application/StateManagerImpl.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/application/StateManagerImpl.java?rev=929948&r1=929947&r2=929948&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/application/StateManagerImpl.java (original)
+++ myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/application/StateManagerImpl.java Thu Apr 1 12:51:55 2010
@@ -39,6 +39,7 @@ import javax.faces.render.RenderKitFacto
import javax.faces.render.ResponseStateManager;
import org.apache.myfaces.trinidad.component.UIXComponentBase;
+import org.apache.myfaces.trinidad.component.core.CoreDocument;
import org.apache.myfaces.trinidad.context.RequestContext;
import org.apache.myfaces.trinidad.logging.TrinidadLogger;
import org.apache.myfaces.trinidad.util.ExternalContextUtils;
@@ -676,6 +677,26 @@ public class StateManagerImpl extends St
return null;
}
+ /**
+ * The given parameter (<code>perViewStateSaving</code>) indicates
+ * if we need to enable client- OR server-side state-saving
+ * for the current VIEW.
+ *
+ * <p>
+ * <b>This is an internal method, that is ONLY called by the
+ * Trinidad Document</b>
+ * </p>
+ *
+ * @param perViewStateSaving <code>default</code>, <code>server</code> or <code>client</code> for stateSaving
+ */
+ public void setPerViewStateSaving(String perViewStateSaving)
+ {
+ // tweak the given value into one of the three possible enums
+ // TODO: catch wrong/invalid values (aka baby sitting)
+ Map<String, Object> attrs = FacesContext.getCurrentInstance().getExternalContext().getRequestMap();
+ attrs.put(_PER_PAGE_STATE_SAVING, StateSaving.valueOf(perViewStateSaving.toUpperCase()));
+ }
+
@Override
public boolean isSavingStateInClient(FacesContext context)
{
@@ -829,13 +850,74 @@ public class StateManagerImpl extends St
*/
private boolean _saveAsToken(FacesContext context)
{
+ // the setPerViewStateSaving() method stores the PER_PAGE_STATE_SAVING value on the
+ // request attribute map, during rendering
+ Map<String, Object> attrMap = FacesContext.getCurrentInstance().getExternalContext().getRequestMap();
+ StateSaving stateSaving = (StateSaving) attrMap.get(_PER_PAGE_STATE_SAVING);
+
+ // if the <document> 'stateSaving' attribute said "client" we need to return FALSE
+ // in order to do "full" client-side-state saving.
+ Boolean forceStateSavingPerView = null;
+
+ if (StateSaving.CLIENT.equals(stateSaving))
+ {
+ forceStateSavingPerView = Boolean.FALSE;
+ }
+ // for "server" we return TRUE here, as we want client-side
+ // state-saving to be turned OFF, regardless of the configuration
+ // settings.
+ else if (StateSaving.SERVER.equals(stateSaving))
+ {
+ forceStateSavingPerView = Boolean.TRUE;
+ }
+
+ // for the stateSaving "defaul" we just let go and do what it
+ // normally would do...
+ if (forceStateSavingPerView != null)
+ {
+ return forceStateSavingPerView.booleanValue();
+ }
+
ExternalContext external = context.getExternalContext();
+ Object stateSavingMethod =
+ external.getInitParameterMap().get(StateManager.STATE_SAVING_METHOD_PARAM_NAME);
+
+ // on "SERVER" state-saving we return TRUE, since we want send down a token string.
+ if ((stateSavingMethod == null) ||
+ StateManager.STATE_SAVING_METHOD_SERVER.equalsIgnoreCase((String) stateSavingMethod))
+ {
+ return true;
+ }
+
+ // if the user set state-saving to "CLIENT" *and* the client-state-method to "ALL"
+ // we return FALSE, since we want to save the ENTIRE state on the client...
Object clientMethod =
external.getInitParameterMap().get(CLIENT_STATE_METHOD_PARAM_NAME);
if ((clientMethod != null) &&
CLIENT_STATE_METHOD_ALL.equalsIgnoreCase((String) clientMethod))
+ {
return false;
+ }
+ // if the user has used the <document> 'stateSaving' attribute to specify
+ // client, we force the state mananger (see above) to render the entire
+ // state on the client. The indicator is stashed on the FacesContext and
+ // is therefore NOT visible during "restoreView" phase. So if we reach this point
+ // here AND we are using "full" client-side-state-saving, this has been tweaked
+ // on the previous page rendering phase...
+ // In this case we return FALSE to indicate to restore the entire (serialized)
+ // state from the client!
+ //
+ // @see setPerViewStateSaving()
+ String viewStateValue =
+ external.getRequestParameterMap().get(ResponseStateManager.VIEW_STATE_PARAM);
+ if (viewStateValue != null && !viewStateValue.startsWith("!"))
+ {
+ return false;
+ }
+
+ // Last missing option: state-saving is "CLIENT" and the client-state-method uses
+ // its default (token), so we return TRUE to send down a token string.
return true;
}
@@ -1221,6 +1303,24 @@ public class StateManagerImpl extends St
}
}
+ /**
+ * Static ENUM to capture the values of the <document>'s
+ * 'stateSaving' attribute
+ */
+ static private enum StateSaving
+ {
+ DEFAULT(CoreDocument.STATE_SAVING_DEFAULT),
+ CLIENT(CoreDocument.STATE_SAVING_CLIENT),
+ SERVER(CoreDocument.STATE_SAVING_SERVER);
+ StateSaving(String stateSaving)
+ {
+ _stateSaving = stateSaving;
+ }
+
+ private String _stateSaving;
+ }
+
+
private final StateManager _delegate;
private Boolean _useViewRootCache;
private Boolean _useApplicationViewCache;
@@ -1239,6 +1339,10 @@ public class StateManagerImpl extends St
private static final String _APPLICATION_VIEW_CACHE_KEY =
"org.apache.myfaces.trinidadinternal.application.APPLICATION_VIEW_CACHE";
+ // key to stash the per_page_state_saving during rendering
+ private static final String _PER_PAGE_STATE_SAVING =
+ "org.apache.myfaces.trinidadimpl.PER_PAGE_STATE_SAVING";
+
private static final String _CACHED_SERIALIZED_VIEW =
"org.apache.myfaces.trinidadinternal.application.CachedSerializedView";
Modified: myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/DocumentRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/DocumentRenderer.java?rev=929948&r1=929947&r2=929948&view=diff
==============================================================================
--- myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/DocumentRenderer.java (original)
+++ myfaces/trinidad/branches/trinidad-1.2.x/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/xhtml/DocumentRenderer.java Thu Apr 1 12:51:55 2010
@@ -20,14 +20,18 @@ package org.apache.myfaces.trinidadinter
import java.io.IOException;
+import javax.faces.application.StateManager;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import org.apache.myfaces.trinidad.bean.FacesBean;
+import org.apache.myfaces.trinidad.bean.PropertyKey;
import org.apache.myfaces.trinidad.component.core.CoreDocument;
import org.apache.myfaces.trinidad.context.RenderingContext;
+import org.apache.myfaces.trinidad.logging.TrinidadLogger;
import org.apache.myfaces.trinidad.render.CoreRenderer;
+import org.apache.myfaces.trinidadinternal.application.StateManagerImpl;
/**
@@ -51,6 +55,7 @@ public class DocumentRenderer extends Xh
protected void findTypeConstants(FacesBean.Type type)
{
super.findTypeConstants(type);
+ _stateSavingKey = type.findKey("stateSaving");
_html = new HtmlRenderer(type);
_head = new Head(type);
_body = new BodyRenderer(type);
@@ -69,6 +74,27 @@ public class DocumentRenderer extends Xh
UIComponent component,
FacesBean bean) throws IOException
{
+ // Value of the 'stateSaving' attribute on <document> component
+ String stateSaving = getStateSaving(component, bean);
+
+ // let's make sure the Trinidad StateManagerImpl is used.
+ // Otherwise tweaking the stateSaving per <document> does
+ // NOT work...
+ StateManager sm = context.getApplication().getStateManager();
+
+ if (sm instanceof StateManagerImpl)
+ {
+ StateManagerImpl smi = (StateManagerImpl) sm;
+
+ // value is "client", "server" or "default"
+ smi.setPerViewStateSaving(stateSaving);
+ }
+ else
+ {
+ //TODO: We may want this to be i18n...
+ _LOG.warning("The 'stateSaving' attribute is only supported with the Trinidad internal StateManager");
+ }
+
delegateRendererBegin(context, arc, component, bean, _html);
delegateRendererBegin(context, arc, component, bean, _head);
@@ -81,6 +107,17 @@ public class DocumentRenderer extends Xh
delegateRendererEnd(context, arc, component, bean, _html);
}
+ protected String getStateSaving(
+ UIComponent component,
+ FacesBean bean)
+ {
+ Object o = bean.getProperty(_stateSavingKey);
+ if (o == null)
+ o = _stateSavingKey.getDefault();
+
+ return toString(o);
+ }
+
static private class Head extends HeadRenderer
{
public Head(FacesBean.Type type)
@@ -103,4 +140,7 @@ public class DocumentRenderer extends Xh
private CoreRenderer _html;
private CoreRenderer _head;
private CoreRenderer _body;
+ private PropertyKey _stateSavingKey;
+
+ private static final TrinidadLogger _LOG = TrinidadLogger.createTrinidadLogger(DocumentRenderer.class);
}