You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by js...@apache.org on 2002/10/21 13:12:42 UTC
cvs commit: jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core SetPropertiesTag.java
jstrachan 2002/10/21 04:12:42
Modified: jelly/src/test/org/apache/commons/jelly suite.jelly
jelly/src/java/org/apache/commons/jelly/tags/core
SetPropertiesTag.java
Log:
Patch so that the <setProperties> tag can be nested within a <useBean> or JellySwing tag. This can help to conditionally set properties on some bean tag
Revision Changes Path
1.9 +24 -0 jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/suite.jelly
Index: suite.jelly
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/suite.jelly,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- suite.jelly 16 Oct 2002 18:17:58 -0000 1.8
+++ suite.jelly 21 Oct 2002 11:12:42 -0000 1.9
@@ -133,6 +133,30 @@
actual="${customer.class.name}"/>
</test:case>
+ <test:case name="testUseBeanWithSetProperties">
+ <j:useBean var="customer" class="org.apache.commons.jelly.bean.Customer" name="James">
+
+ <!-- typically the following tag might be nested inside some conditional logic -->
+ <j:setProperties name="Bob" city="Atlanta"/>
+ </j:useBean>
+
+ <log:info>Created a new bean: ${customer}</log:info>
+
+ <test:assert test="${customer != null}">Created a customer bean</test:assert>
+
+ <test:assertEquals
+ expected="Bob"
+ actual="${customer.name}"/>
+
+ <test:assertEquals
+ expected="Atlanta"
+ actual="${customer.city}"/>
+
+ <test:assertEquals
+ expected="org.apache.commons.jelly.bean.Customer"
+ actual="${customer.class.name}"/>
+ </test:case>
+
<test:case name="testSetWithNoEncoding">
<j:set var="foo" encode="false">
<foo x="1">hello</foo>
1.2 +13 -1 jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/SetPropertiesTag.java
Index: SetPropertiesTag.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/SetPropertiesTag.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SetPropertiesTag.java 24 Sep 2002 10:55:59 -0000 1.1
+++ SetPropertiesTag.java 21 Oct 2002 11:12:42 -0000 1.2
@@ -63,6 +63,7 @@
import org.apache.commons.jelly.MissingAttributeException;
import org.apache.commons.jelly.MapTagSupport;
import org.apache.commons.jelly.XMLOutput;
+import org.apache.commons.jelly.impl.BeanSource;
/**
* A tag which sets the bean properties on the given bean.
@@ -73,6 +74,10 @@
* </pre>
* Then it would set the name and location properties on the bean denoted by
* the expression ${person}.
+ * <p>
+ * This tag can also be nested inside a bean tag such as the <useBean> tag
+ * or a JellySwing tag to set one or more properties, maybe inside some conditional
+ * logic.
*
* @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
* @version $Revision$
@@ -88,7 +93,14 @@
Map attributes = getAttributes();
Object bean = attributes.remove( "object" );
if ( bean == null ) {
- throw new MissingAttributeException("bean");
+ // lets try find a parent bean
+ BeanSource tag = (BeanSource) findAncestorWithClass(BeanSource.class);
+ if (tag != null) {
+ bean = tag.getBean();
+ }
+ if (bean == null) {
+ throw new MissingAttributeException("bean");
+ }
}
setBeanProperties(bean, attributes);
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>