I've parsed your code Marcus and i don't understand what the "hidden" component is ?
Could you briefly explain ?

Schulte Marcus wrote:

Here you go, it's for Tap4 btw:

Usage example:

<span jwcid="[EMAIL PROTECTED]" value="ognl:fahrzeug.reserviertBis" listener="listener:onReservierung"/>

value is the property to watch, listener will be called at the end of the
rewind
cycle, if the prop did change.

___________ file Watch.java ____________________
/*
* Erstellt am 23.05.2005 von schultma
* copyright, 2005 BMW (Schweiz) AG
* * $Id: Watch.java,v 1.1 2006/04/13 07:43:55 emeadecentral#schultma Exp $
*/
package com.javaforge.honeycomb.tapestry.components;

import org.apache.tapestry.IActionListener;
import org.apache.tapestry.IMarkupWriter;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.event.PageBeginRenderListener;
import org.apache.tapestry.event.PageEvent;
import org.apache.tapestry.form.AbstractFormComponent;
import org.apache.tapestry.listener.ListenerInvoker;

/**
*  Renders a hidden field for a given value and registers a listener
*  to be called on the end of the rewind if the property changed in this
*  request.
*
* @author schultma
*/
public abstract class Watch extends AbstractFormComponent implements
PageBeginRenderListener {

        public abstract IActionListener getListener();
        
        public abstract Object getValue();
        
        public abstract Object getOldValue();
        public abstract void setOldValue( Object t );
        
        public abstract ListenerInvoker getListenerInvoker();

        

        @Override
        protected void renderFormComponent(IMarkupWriter writer,
IRequestCycle cycle) {
                setOldValue( getValue() );
                getComponent("hidden").render( writer, cycle );
        }

        @Override
        protected void rewindFormComponent(IMarkupWriter writer, final
IRequestCycle cycle) {
                getComponent("hidden").render( writer, cycle );
                 {
                        getForm().addDeferredRunnable( new Runnable() {
                                                public void run() {
                                                        if ( valueChanged()
) { getListenerInvoker().invokeListener( getListener(),
Watch.this, cycle );
                                                        }
                                                };});
                }
                
        }

        private boolean valueChanged() {
                if ( getOldValue() == getValue() )
                        return false;

                if ( getOldValue() == null || getValue() == null)
                        return true;
                
                return !getValue().equals(getOldValue());
        }

        @Override
        protected void prepareForRender(IRequestCycle cycle) {
                        
                super.prepareForRender(cycle);          
        }

        public void pageBeginRender(PageEvent arg0) {
                                
        }
}


______________ file Watch.jwc
_______________________________________________________

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE component-specification PUBLIC
 "-//Apache Software Foundation//Tapestry Specification 4.0//EN"
 "http://jakarta.apache.org/tapestry/dtd/Tapestry_4_0.dtd";>
<!-- generated by Spindle, http://spindle.sourceforge.net -->

<component-specification
class="com.javaforge.honeycomb.tapestry.components.Watch"
   allow-body="no"
   allow-informal-parameters="no">
<description>Watches a property</description>
        
        <parameter name="listener" required="yes" />
        <parameter name="value" required="yes" />
        
        <property name="oldValue"  />
        
        <component id="hidden" type="Hidden" >
                <binding name="value" value="ognl:oldValue"/>
        </component>
        
   <inject property="listenerInvoker"
object="infrastructure:listenerInvoker"/>

</component-specification>

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


--
Stéphane Decleire

05 56 57 99 20
06 63 78 69 06

Reply via email to