polx        2005/01/26 14:46:28

  Modified:    
jelly/jelly-tags/swing/src/java/org/apache/commons/jelly/tags/swing
                        ComponentTag.java
  Log:
  First stab at rerunnable tags.
  Using <panel tagName="myTag">DO SOMETHING${x}</panel>
  One can invoke, later, e.g. in an action-tag, ${myTag.rerun()} which should
  repopulate the panel by removing first then re-running the body
  ot this tag.
  paul
  
  Revision  Changes    Path
  1.24      +49 -1     
jakarta-commons/jelly/jelly-tags/swing/src/java/org/apache/commons/jelly/tags/swing/ComponentTag.java
  
  Index: ComponentTag.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/jelly/jelly-tags/swing/src/java/org/apache/commons/jelly/tags/swing/ComponentTag.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- ComponentTag.java 12 Jan 2005 08:59:16 -0000      1.23
  +++ ComponentTag.java 26 Jan 2005 22:46:28 -0000      1.24
  @@ -168,6 +168,40 @@
               }
           }
       }
  +     
  +    
  +     private String tagName = null;
  +     
  +     private XMLOutput currentOutput = null;
  +     
  +     /** Puts this tag into the context under the given name
  +      * allowing later calls to [EMAIL PROTECTED] #rerun()}.
  +      * For example, it makes sense to use ${myTag.rerun()} as a child
  +      * of an <code>action</code> element.
  +      *
  +      * @param the name to be used
  +      */
  +     public void setTagName(String name) {
  +             this.tagName = name;
  +     }
  +     
  +     /** Runs the body of this script again after clearing the content
  +      * of this component.
  +      * This is useful to use jelly-logic and "re-populate" a part of the 
user-interface
  +      * after having updated a model part (e.g. an XML-document).
  +      * @throws JellyTagException if anything
  +      */
  +     public void rerun() throws JellyTagException {
  +             Component comp = getComponent();
  +             if(comp instanceof java.awt.Container) {
  +                     ((java.awt.Container) comp).removeAll();
  +             }
  +             this.doTag(currentOutput,false);
  +             if ( comp instanceof javax.swing.JComponent ) {
  +                     ((javax.swing.JComponent) comp).revalidate();
  +             }
  +     }
  +     
   
       /**
        * Adds a WindowListener to this component
  @@ -290,6 +324,14 @@
        * A class may be specified otherwise the Factory will be used.
        */
       protected Object newInstance(Class theClass, Map attributes, XMLOutput 
output) throws JellyTagException {
  +             if (attributes.containsKey("tagName")) {
  +                     this.setTagName((String)attributes.get("tagName"));
  +                     addIgnoreProperty("tagName");
  +             }
  +             if(tagName!=null) {
  +                     context.setVariable(tagName,this);
  +                     currentOutput = output;
  +             }
           try {
               if (theClass != null ) {
                   return theClass.newInstance();
  @@ -363,6 +405,7 @@
                       component.setSize(d);
                       addIgnoreProperty("size");
                   }
  +                             
                   
                   if (attributes.containsKey("debugGraphicsOptions")) {
                       try {
  @@ -398,8 +441,13 @@
        * @see 
org.apache.commons.jelly.Tag#doTag(org.apache.commons.jelly.XMLOutput)
        */
       public void doTag(XMLOutput output) throws JellyTagException {
  +        this.doTag(output,true);
  +    }
  +    
  +    public void doTag(XMLOutput output, boolean resetBean) throws 
JellyTagException {
  +        if(resetBean) clearBean();
           super.doTag(output);
  -        clearBean();
  +        //clearBean();
       }
   
       /** Sets the bean to null, to prevent it from
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to