You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Richard Human <ta...@psychopuppy.net> on 2006/11/06 14:25:52 UTC

Tacos and form validation with custom validators

Hi all,

We've just finished migrating out app from tap 3 to tap 4 (well done  
to all involved, tap4 is great), and now we are starting to test out  
the Tacos Ajax components. (Tap 4.0.2 and Tacos 4.0.0)

We are running into some problems with integrating Ajax forms with  
client side validation. If we use tapestry standard validators  
(required, min, etc) then the tacos validation works as it does in  
the demo i.e. adds an error message next to the invalid field and  
clears the message when you add to it.

However, for one of our components we have defined a custom validator  
and translator. Our custom translator extends  
org.apache.tapestry.form.translator.NumberTranslator and also has  
Javascript component (which we build via renderContribution: we add a  
submit handler that calls a JS function that we define on our  
classpath).

The Ajax form (which contains our component with the customer  
translator) is first loaded into the page using an AjaxDirectLink.  
The problem is that when we do an ajax submit using the tacos  
components we get JS errors in the browser complaining about not  
being able to find our JS function (Tapestry.validate_currency, see  
below). Tacos then fails back to a

So the question is: what is the correct way for us to build custom  
validators and translators such that they work correctly with Tacos's  
client side validation? can someone point me to a tutorial or example  
where this is done?

Thanks
Richard

// our custom translator class

public class CurrencyTranslator extends NumberTranslator {
     @Override
     protected String defaultScript() {
         return "/js/CurrencyTranslator.js";
     }

     @Override
     protected Object parseText(
         IFormComponent field, ValidationMessages messages, String  
text) throws ValidatorException {

	// snip: biz logic removed
     }

     @Override
     public void renderContribution(IMarkupWriter writer,  
IRequestCycle cycle,
                      FormComponentContributorContext context,  
IFormComponent field) {
         String message = TapestryUtils.enquote(buildMessage(context,  
field, getMessageKey()));

         // Set the script for this component
         context.includeClasspathScript(defaultScript());
         context.addSubmitHandler("function(event)  
{ Tapestry.validate_currency(event, '"
                     + field.getClientId() + "', " + message + "); }");
     }
}

// our custom JS function located in WEB-INF/js
Tapestry.validate_currency = function(event, fieldId, message)
   var field = this.find(fieldId);
   // snip: biz logic removed
}




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Notification of stale session?

Posted by Peter Stavrinides <p....@albourne.com>.
There are many ways to do this, the most common and simplest is using a 
simple pageValidate, but if you need something more complex for whatever 
reason, you can also wire a listener using hivemind or even use your 
web.xml file

i.e.
web.xml
<listener>
    <listener-class>
        com.test.application.SessionListener
    </listener-class>
</listener>

public class SessionListener implements 
HttpSessionListener,HttpSessionAttributeListener  {

}

or using hivemind:
<implementation service-id="tapestry.error.StaleSessionExceptionPresenter">
        <invoke-factory>
            <construct class="application.StaleSessionListener"></construct>
        </invoke-factory>
 </implementation>

public class StaleSessionListener implements StaleSessionExceptionPresenter{
    public StaleSessionListener(){ 
    }
    public void presentStaleSessionException(IRequestCycle cycle, 
StaleSessionException exception) throws IOException {
        System.out.println("a stale session was detected");
    }
         
}

Regards
Peter

Kevin Whitley wrote:
> Is there some way to receive notification that a session has become 
> stale?  I'm looking for something like the javax.servlet interface 
> HttpSessionBindingListener.  I have various resources associated with 
> a session and I'd like to free them up when the session times out  not 
> waiting for somebody to hit the session (and notice it is stale).
>
> Thanks,
> Kevin Whitley
> podtech.net
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>

-- 
Peter Stavrinides
Albourne Partners (Cyprus) Ltd
Tel: +357 22 750652

If you are not an intended recipient of this e-mail, please notify the sender, delete it and do not read, act upon, print, disclose, copy, retain or redistribute it. Please visit http://www.albourne.com/email.html for important additional terms relating to this e-mail. 



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Notification of stale session?

Posted by Kevin Whitley <ke...@podtech.net>.
Is there some way to receive notification that a session has become  
stale?  I'm looking for something like the javax.servlet interface  
HttpSessionBindingListener.  I have various resources associated with  
a session and I'd like to free them up when the session times out   
not waiting for somebody to hit the session (and notice it is stale).

Thanks,
Kevin Whitley
podtech.net



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org