You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Erik Hatcher <er...@ehatchersolutions.com> on 2003/11/12 20:01:02 UTC

type conversion

I have a DatePicker, and want to bind it to a field that is of type 
java.sql.Timestamp.

Is there some conversion mechanism or OGNL expression trickery that can 
get this to work?  Or are there other options I should consider?

Thanks,
	Erik


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


Improvements in handling Stale link in Form component

Posted by tsvetelin <ts...@rushmore-digital.com>.
Hi All,

Last couple of days I am working on 2 things: making client side of our
application stateless and improving the stale link handling in our
application.

Problem: We have dynamic web forms module where the administrator can
add/remove the question from the application forms. So it was possible users
of our application to receive the stale link error during the filling the
form. Showing the default page that say “Stale link has been entered” or
something else isn’t appropriate because there aren't any session data on
the server(stateless application - all necessary data are in a hidden fields
in the form) and we lose the user tracking(for example selected product
category).

Solution:
The new listener can be passed to the form component which will be notify
when the Stale Link Error is couth. In the way the page or component can
decide what must be done when the stale error occur. In our case the page
clear it’s properties (except this that is related to the user actions
tracking - for example selected product category).

Here are the changes:
1. The new interface has been added:
/**
 *  Defines a listener to an {@link net.sf.tapestry.form.Form} and {@link
net.sf.tapestry.link.DirectLink} components, which is way to
 *  get behavior when the Stale Link Error occur.
 *
 *  @author Tsvetelin Saykov
 *  @version $Id: IStaleLinkErrorLister.java,v 1.0 2003/11/14 Exp $
 *
 **/
public interface IStaleLinkErrorLister {
	public void staleLinkErrorOccur(RequestCycleException e) throws
RequestCycleException;
}

2. The new binding has been added to the Form component
  <parameter name="staleLinkErrorListener"
  	java-type="net.sf.tapestry.IStaleLinkErrorLister"
  	required="no"
  	direction="in">
    <description>
  	Object invoked when the form is submitted and the stale link error occur.
    </description>
  </parameter>

3. The code in Form.java has been changed in the part where the
StaleLinkException is thrown:

I would like to commit this changes in the framework.
Any comments?

Tsvetelin


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


Re: type conversion

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
i'm taking this thread over to tapestry-dev...

On Thursday, November 13, 2003, at 10:11  AM, Erik Hatcher wrote:
> Sure enough, OGNL to the rescue.... almost....
>
> The short answer is that OGNL's type converter hook works wonderfully, 
> but to tie it in will require a change to OgnlUtils.
>
> OgnlUtils:
>
>     public static void set(Object expression, ClassResolver resolver, 
> Object target, Object value)
>             Map context = Ognl.createDefaultContext(target, resolver);
>
> --> need to inject setting the type converter here!
>
>             Ognl.setValue(expression, context, target, value);
>
> I have not cracked open OGNL's source code, but from what I gather, 
> the Ognl object is relatively stateless, so you cannot register a 
> converter that works for all contexts globally.  A converter is put 
> into the context and that is the one used.
>
> Or do I have a hook into what goes into the OGNL context in a global 
> way?  If so, I could put my type converter in as 
> OgnlContext.TYPE_CONVERTER_CONTEXT_KEY and that should work.
>
> I'll keep digging to see how to hook into the OGNL context globally so 
> no change to OgnlUtils is needed, but wanted to fire off my findings 
> so far in case others have some info to help me out.

Ok, so I've been digging and am in deep to ExpressionBinding.  I don't 
see a way to inject something into the OGNL context with a specific key.

Am I missing a capability to do this somehow?

Or what are my options?


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


Re: type conversion

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Tuesday, November 18, 2003, at 10:13  AM, Erik Hatcher wrote:
> How can I get an extension from within ExpressionBinding?

I'll answer my own question:

	_root.getPage().getEngine().getSpecification().getExtension(...)

I'm in the midst of trying this out.  The dilemma is that 
ExpressionBinding and OgnlUtils both construct an OGNL context.  I'm 
just concerned with ExpressionBinding for now, but it would be good to 
unify these things somehow.

I'm guessing the answer is HiveMind, huh?!  :)


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


Re: type conversion

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Thursday, November 13, 2003, at 10:57  AM, Erik Hatcher wrote:
> Ok, so I've been digging and am in deep to ExpressionBinding.  I don't 
> see a way to inject something into the OGNL context with a specific 
> key.  ExpressionBinding calls Ognl.setValue directly, rather than 
> going to OgnlUtils for the setting.  So I'm almost sure 
> ExpressionBinding is where I need to add something to the context, 
> which trickles down to everywhere ExpressionBinding is constructed, or 
> have it pick up some setting somehow automatically.

Ok, I want to be able to call:

	Ognl.setTypeConverter(_context, someTypeConverter)

from within ExpressionBinding.getOgnlContext

I want to get a type converter from an extension specified in the 
.application file, and of course if one is not there then don't make 
that call.

How can I get an extension from within ExpressionBinding?

Thanks,
	Erik


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


Re: type conversion

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
i'm taking this thread over to tapestry-dev...

On Thursday, November 13, 2003, at 10:11  AM, Erik Hatcher wrote:
> Sure enough, OGNL to the rescue.... almost....
>
> The short answer is that OGNL's type converter hook works wonderfully, 
> but to tie it in will require a change to OgnlUtils.
>
> OgnlUtils:
>
>     public static void set(Object expression, ClassResolver resolver, 
> Object target, Object value)
>             Map context = Ognl.createDefaultContext(target, resolver);
>
> --> need to inject setting the type converter here!
>
>             Ognl.setValue(expression, context, target, value);
>
> I have not cracked open OGNL's source code, but from what I gather, 
> the Ognl object is relatively stateless, so you cannot register a 
> converter that works for all contexts globally.  A converter is put 
> into the context and that is the one used.
>
> Or do I have a hook into what goes into the OGNL context in a global 
> way?  If so, I could put my type converter in as 
> OgnlContext.TYPE_CONVERTER_CONTEXT_KEY and that should work.
>
> I'll keep digging to see how to hook into the OGNL context globally so 
> no change to OgnlUtils is needed, but wanted to fire off my findings 
> so far in case others have some info to help me out.

Ok, so I've been digging and am in deep to ExpressionBinding.  I don't 
see a way to inject something into the OGNL context with a specific 
key.  ExpressionBinding calls Ognl.setValue directly, rather than going 
to OgnlUtils for the setting.  So I'm almost sure ExpressionBinding is 
where I need to add something to the context, which trickles down to 
everywhere ExpressionBinding is constructed, or have it pick up some 
setting somehow automatically.

Am I missing a capability to do this somehow?

Or what are my options?

Thanks,
	Erik


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


Re: type conversion

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Wednesday, November 12, 2003, at 10:50  PM, Erik Hatcher wrote:
> besides, we're just talking about a very simple type conversion.  as i 
> suspected, OGNL has the facility:
>
> 	http://www.ognl.org/2.6.3/Documentation/html/typeConversion.html
>
> i'll experiment with this and see if it does the trick.

Sure enough, OGNL to the rescue.... almost....

The short answer is that OGNL's type converter hook works wonderfully, 
but to tie it in will require a change to OgnlUtils.

Here are the gory details:

I wrote this test case to see what was going on:

 
    private Timestamp timestamp;
    public void testDateTimestampConversion() throws Exception {
        Map context = Ognl.createDefaultContext(null);

         // removing the following line causes test to fail, passes with 
it there
        Ognl.setTypeConverter(context, new OgnlTypeConverter());

        Date now = new Date();
        timestamp = null;

        Ognl.setValue("testField", context, this, now);
        assertEquals(timestamp.getTime(), now.getTime());
    }

    public void setTestField(Timestamp timestamp) {
        this.timestamp = timestamp;
    }

 
OgnlTypeConverter:
public class OgnlTypeConverter extends DefaultTypeConverter {
    public Object convertValue(Map context, Object value, Class toType) 
{
        Object result = null;

        if ((toType == Timestamp.class) && (value instanceof Date)) {
            return new Timestamp(((Date) value).getTime());
        } else {
            result = super.convertValue(context, value, toType);
        }

        return result;
    }
}

OgnlUtils:

    public static void set(Object expression, ClassResolver resolver, 
Object target, Object value)
            Map context = Ognl.createDefaultContext(target, resolver);

--> need to inject setting the type converter here!

            Ognl.setValue(expression, context, target, value);

I have not cracked open OGNL's source code, but from what I gather, the 
Ognl object is relatively stateless, so you cannot register a converter 
that works for all contexts globally.  A converter is put into the 
context and that is the one used.

Or do I have a hook into what goes into the OGNL context in a global 
way?  If so, I could put my type converter in as 
OgnlContext.TYPE_CONVERTER_CONTEXT_KEY and that should work.

I'll keep digging to see how to hook into the OGNL context globally so 
no change to OgnlUtils is needed, but wanted to fire off my findings so 
far in case others have some info to help me out.

Thanks,
	Erik


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


Re: type conversion

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Wednesday, November 12, 2003, at 10:20  PM, Kevin C. Dorff wrote:
> The source files for the Calendar component is readily available, why 
> don't you just copy it and make a SqlCalendar component that works 
> with java.sql.Timpstamps instead of java.util.Date? Should be really 
> easy to do.

'cause cut-and-paste ain't my style :)

besides, we're just talking about a very simple type conversion.  as i 
suspected, OGNL has the facility:

	http://www.ognl.org/2.6.3/Documentation/html/typeConversion.html

i'll experiment with this and see if it does the trick.


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


Re: type conversion

Posted by "Kevin C. Dorff" <kd...@dorffweb.com>.
The source files for the Calendar component is readily available, why 
don't you just copy it and make a SqlCalendar component that works with 
java.sql.Timpstamps instead of java.util.Date? Should be really easy to do.

Kevin

Erik Hatcher wrote:

> On Wednesday, November 12, 2003, at 07:17  PM, Kevin C. Dorff wrote:
>
>> I haven't looked specifically, but, I assume the problem is that the 
>> Tapestry calendar returns type (A) and you want to deal with type (B) 
>> with your business logic. Just make your getter's and setters expose 
>> a type (A) interface, but, make your local data storage work with 
>> type (B). Your getter and setter then just translates between (A) and 
>> (B) and vice versa. You can expose an alternate interface (alternate 
>> getters and setters) to work directly with type (B) (which is, I 
>> assume what you really want). Hope this helps and should keep the 
>> .page file clean.
>
>
> Kevin - thanks.  Yes, my next step was to modify our "filter" objects 
> (that correspond to the form) to have a setXXX(Date) that converts 
> internally to a Timestamp.  We use code generation to build these 
> filters, so its no big deal.  But I was hoping, and am still hoping, 
> for some way to interject some conversion in the process of populating 
> properties from form fields.
>
> Perhaps there is an OGNL way to have Date value get converted if no 
> corresponding Date parameter setter is found, but a Timestamp setter 
> is found??  Anyone done something like this?  I'll look into OGNL 
> deeper soon.
>
>     Erik
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
>




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


Re: type conversion

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Wednesday, November 12, 2003, at 07:17  PM, Kevin C. Dorff wrote:
> I haven't looked specifically, but, I assume the problem is that the 
> Tapestry calendar returns type (A) and you want to deal with type (B) 
> with your business logic. Just make your getter's and setters expose a 
> type (A) interface, but, make your local data storage work with type 
> (B). Your getter and setter then just translates between (A) and (B) 
> and vice versa. You can expose an alternate interface (alternate 
> getters and setters) to work directly with type (B) (which is, I 
> assume what you really want). Hope this helps and should keep the 
> .page file clean.

Kevin - thanks.  Yes, my next step was to modify our "filter" objects 
(that correspond to the form) to have a setXXX(Date) that converts 
internally to a Timestamp.  We use code generation to build these 
filters, so its no big deal.  But I was hoping, and am still hoping, 
for some way to interject some conversion in the process of populating 
properties from form fields.

Perhaps there is an OGNL way to have Date value get converted if no 
corresponding Date parameter setter is found, but a Timestamp setter is 
found??  Anyone done something like this?  I'll look into OGNL deeper 
soon.

	Erik


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


Re: type conversion

Posted by "Kevin C. Dorff" <kd...@dorffweb.com>.
I haven't looked specifically, but, I assume the problem is that the 
Tapestry calendar returns type (A) and you want to deal with type (B) 
with your business logic. Just make your getter's and setters expose a 
type (A) interface, but, make your local data storage work with type 
(B). Your getter and setter then just translates between (A) and (B) and 
vice versa. You can expose an alternate interface (alternate getters and 
setters) to work directly with type (B) (which is, I assume what you 
really want). Hope this helps and should keep the .page file clean.

Erik Hatcher wrote:

> Paul,
>
> Thanks for the idea.  I'm still hoping for something much more elegant 
> though, so that I can expose richer objects directly to Tapestry pages 
> without having to code "glue" in the Page file itself.
>
>     Erik
>
>
> On Wednesday, November 12, 2003, at 02:40  PM, Paul Ferraro wrote:
>
>> rather than bind the value directly to your object's 
>> java.sql.Timestamp property:
>>
>> <input jwcid="@DatePicker" value="ognl:myObject.timestamp"/>
>>
>> ... you'll need to bind it indirectly ...
>>
>> <input jwcid="@DatePicker" value="ognl:myObjectDate"/>
>>
>> public Date getMyObjectDate()
>> {
>>    this.getMyObject().getTimestamp();
>> }
>>
>> public void setMyObjectDate(Date date)
>> {
>>    this.getMyObject().setTimestamp(new Timestamp(date.getTime()));
>> }
>>
>> Hope this helps,
>>
>> Paul Ferraro
>>
>> Erik Hatcher wrote:
>>
>>> I have a DatePicker, and want to bind it to a field that is of type 
>>> java.sql.Timestamp.
>>>
>>> Is there some conversion mechanism or OGNL expression trickery that 
>>> can get this to work?  Or are there other options I should consider?
>>>
>>> Thanks,
>>>     Erik
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
>




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


Re: type conversion

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
Paul,

Thanks for the idea.  I'm still hoping for something much more elegant 
though, so that I can expose richer objects directly to Tapestry pages 
without having to code "glue" in the Page file itself.

	Erik


On Wednesday, November 12, 2003, at 02:40  PM, Paul Ferraro wrote:

> rather than bind the value directly to your object's 
> java.sql.Timestamp property:
>
> <input jwcid="@DatePicker" value="ognl:myObject.timestamp"/>
>
> ... you'll need to bind it indirectly ...
>
> <input jwcid="@DatePicker" value="ognl:myObjectDate"/>
>
> public Date getMyObjectDate()
> {
>    this.getMyObject().getTimestamp();
> }
>
> public void setMyObjectDate(Date date)
> {
>    this.getMyObject().setTimestamp(new Timestamp(date.getTime()));
> }
>
> Hope this helps,
>
> Paul Ferraro
>
> Erik Hatcher wrote:
>
>> I have a DatePicker, and want to bind it to a field that is of type 
>> java.sql.Timestamp.
>>
>> Is there some conversion mechanism or OGNL expression trickery that 
>> can get this to work?  Or are there other options I should consider?
>>
>> Thanks,
>>     Erik
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


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


Re: type conversion

Posted by Paul Ferraro <pm...@columbia.edu>.
rather than bind the value directly to your object's java.sql.Timestamp 
property:

<input jwcid="@DatePicker" value="ognl:myObject.timestamp"/>

... you'll need to bind it indirectly ...

<input jwcid="@DatePicker" value="ognl:myObjectDate"/>

public Date getMyObjectDate()
{
    this.getMyObject().getTimestamp();
}

public void setMyObjectDate(Date date)
{
    this.getMyObject().setTimestamp(new Timestamp(date.getTime()));
}

Hope this helps,

Paul Ferraro

Erik Hatcher wrote:

> I have a DatePicker, and want to bind it to a field that is of type 
> java.sql.Timestamp.
>
> Is there some conversion mechanism or OGNL expression trickery that 
> can get this to work?  Or are there other options I should consider?
>
> Thanks,
>     Erik
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>



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