You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by mi...@apache.org on 2004/01/07 02:18:24 UTC
cvs commit: jakarta-tapestry/framework/src/org/apache/tapestry/pageload PropertyInitializer.java PageLoader.java
mindbridge 2004/01/06 17:18:24
Modified: framework/src/org/apache/tapestry/pageload
PropertyInitializer.java PageLoader.java
Log:
Making property initializers to be evaluated every time (unless they are invariant)
Revision Changes Path
1.4 +69 -4 jakarta-tapestry/framework/src/org/apache/tapestry/pageload/PropertyInitializer.java
Index: PropertyInitializer.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/org/apache/tapestry/pageload/PropertyInitializer.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- PropertyInitializer.java 17 Apr 2003 21:33:56 -0000 1.3
+++ PropertyInitializer.java 7 Jan 2004 01:18:24 -0000 1.4
@@ -55,8 +55,14 @@
package org.apache.tapestry.pageload;
+import ognl.Ognl;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.tapestry.ApplicationRuntimeException;
import org.apache.tapestry.IComponent;
+import org.apache.tapestry.ILocation;
import org.apache.tapestry.IResourceResolver;
+import org.apache.tapestry.Tapestry;
import org.apache.tapestry.event.PageDetachListener;
import org.apache.tapestry.event.PageEvent;
import org.apache.tapestry.util.prop.OgnlUtils;
@@ -77,23 +83,82 @@
private IResourceResolver _resolver;
private IComponent _component;
private String _propertyName;
+ private String _expression;
+ private boolean _invariant;
private Object _value;
+ private ILocation _location;
public PropertyInitializer(
IResourceResolver resolver,
IComponent component,
String propertyName,
- Object value)
+ String expression,
+ ILocation location)
{
_resolver = resolver;
_component = component;
_propertyName = propertyName;
- _value = value;
+ _expression = expression;
+ _location = location;
+
+ prepareInvariant();
+ }
+
+ public void prepareInvariant()
+ {
+ _invariant = false;
+ try
+ {
+ // If no initial value expression is provided, then read the current
+ // property of the expression. This may be null, or may be
+ // a value set in finishLoad() (via an abstract accessor).
+
+ if (StringUtils.isEmpty(_expression))
+ {
+ _invariant = true;
+ _value = OgnlUtils.get(_propertyName, _resolver, _component);
+ }
+ else if (Ognl.isConstant(_expression))
+ {
+ // If the expression is a constant, evaluate it and remember the value
+ _invariant = true;
+ _value = OgnlUtils.get(_expression, _resolver, _component);
+ }
+ }
+ catch (Exception ex)
+ {
+ throw new ApplicationRuntimeException(
+ Tapestry.format(
+ "PageLoader.unable-to-initialize-property",
+ _propertyName,
+ _component,
+ ex.getMessage()),
+ _location,
+ ex);
+ }
}
public void pageDetached(PageEvent event)
{
- OgnlUtils.set(_propertyName, _resolver, _component, _value);
+ try {
+ if (_invariant)
+ OgnlUtils.set(_propertyName, _resolver, _component, _value);
+ else {
+ Object value = OgnlUtils.get(_expression, _resolver, _component);
+ OgnlUtils.set(_propertyName, _resolver, _component, value);
+ }
+ }
+ catch (Exception ex)
+ {
+ throw new ApplicationRuntimeException(
+ Tapestry.format(
+ "PageLoader.unable-to-initialize-property",
+ _propertyName,
+ _component,
+ ex.getMessage()),
+ _location,
+ ex);
+ }
}
}
1.20 +22 -36 jakarta-tapestry/framework/src/org/apache/tapestry/pageload/PageLoader.java
Index: PageLoader.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/org/apache/tapestry/pageload/PageLoader.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- PageLoader.java 21 Dec 2003 23:55:08 -0000 1.19
+++ PageLoader.java 7 Jan 2004 01:18:24 -0000 1.20
@@ -104,7 +104,6 @@
import org.apache.tapestry.spec.IContainedComponent;
import org.apache.tapestry.spec.IListenerBindingSpecification;
import org.apache.tapestry.spec.IPropertySpecification;
-import org.apache.tapestry.util.prop.OgnlUtils;
/**
* Runs the process of building the component hierarchy for an entire page.
@@ -129,6 +128,7 @@
private ISpecificationSource _specificationSource;
private ComponentSpecificationResolver _componentResolver;
private List _inheritedBindingQueue = new ArrayList();
+ private List _propertyInitializers = new ArrayList();
private ComponentTreeWalker _componentTreeWalker;
/**
@@ -810,12 +810,15 @@
// Walk through the complete component tree to ensure that required parameters
// are bound and to set up the default parameter values.
_componentTreeWalker.walkComponentTree(page);
+
+ establishDefaultPropertyValues();
}
finally
{
_locale = null;
_engine = null;
_inheritedBindingQueue.clear();
+ _propertyInitializers.clear();
}
if (LOG.isDebugEnabled())
@@ -845,6 +848,21 @@
queued.connect();
}
}
+
+ private void establishDefaultPropertyValues()
+ {
+ LOG.debug("Setting default property values");
+
+ int count = _propertyInitializers.size();
+
+ for (int i = 0; i < count; i++)
+ {
+ PageDetachListener initializer =
+ (PageDetachListener) _propertyInitializers.get(i);
+
+ initializer.pageDetached(null);
+ }
+ }
private void addAssets(IComponent component, IComponentSpecification specification)
{
@@ -889,44 +907,12 @@
{
String name = (String) names.get(i);
IPropertySpecification ps = spec.getPropertySpecification(name);
-
String expression = ps.getInitialValue();
- Object initialValue = null;
-
- // If no initial value expression is provided, then read the current
- // property of the expression. This may be null, or may be
- // a value set in finishLoad() (via an abstract accessor).
-
- try
- {
- if (StringUtils.isEmpty(expression))
- {
- initialValue = OgnlUtils.get(name, _resolver, component);
- }
- else
- {
- // Evaluate the expression and update the property.
-
- initialValue = OgnlUtils.get(expression, _resolver, component);
-
- OgnlUtils.set(name, _resolver, component, initialValue);
- }
- }
- catch (Exception ex)
- {
- throw new ApplicationRuntimeException(
- Tapestry.format(
- "PageLoader.unable-to-initialize-property",
- name,
- component,
- ex.getMessage()),
- ps.getLocation(),
- ex);
- }
PageDetachListener initializer =
- new PropertyInitializer(_resolver, component, name, initialValue);
+ new PropertyInitializer(_resolver, component, name, expression, ps.getLocation());
+ _propertyInitializers.add(initializer);
page.addPageDetachListener(initializer);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org