Actually, the conversion of parameters is based on ValueEncoders. For example, using tapestry-hibernate, Hibernate entities are expressed in URLs as their primary key (usually a number). They are converted back from strings to numbers to entities when the event handler method is invoked.
The same approach can be applied to other domains. The tapestry-hibernate code will give you an idea of how to do this. Serializing POJOs into the URL is not a great idea; there's issues with serialzing object graphs when you just want the object. T4 used this approach, which led to endless discussions about how to get Tapestry to *not* do that. On Sun, Mar 23, 2008 at 2:40 PM, Yura Tkachenko <[EMAIL PROTECTED]> wrote: > Yes, I agree that for <a> tags Tapestry should pass data via URL. But in my > example I'm using form component. > <t:form t:id="userInputForm"> > <input type="text" t:id="theTextBox"/> > <input type="submit" value="Submit"/> > </t:form> > As the result my form will be rendered into <form > ...method=""POST>...</form> But even with that component when I'm passing > some data during onSubmit event for form I'm getting such URL which contains > encoded page activation context. I'm saying it not because I don't like long > URLs. But if form already has an HTTP POST why not pass activation context > as some parameter in this post request. In that case you won't have any > limitation to the size of page activation context. > > Another concern is about type coercion. > After trying to pass some object let's call it PageDataWrapper via > activation context and implementing TypeCoercer for that particular object I > realized that in big systems or big enterprise applications I might want to > use different objects (different POJOs) as the result I should implement for > each of this POJO TypeCoercer. But really POJO it's simply a Java Bean which > eventually will be serialized/deserialized in TypeCoercer. So my question is > why not have a rule in Typestry that each POJO which you wanna pass via Page > Activation Context should implement Serializable interface and that's it. > After that Typestry automatically will do coercion for serialized objects. > Of course, some one can argue that you shouldn't pass big POJOs via > activation context. But sometimes we need to pass data between pages using > http request context, not http session. > > Thanks, > Yura. > > On Sun, Mar 23, 2008 at 12:15 PM, Howard Lewis Ship <[EMAIL PROTECTED]> > wrote: > > > > > Because the designers of HTML haven't figure out yet that an <a> tag > > should have a method attribute, like a <form>. > > > > Also, the URLs should not be particularly long, as you should be > > putting in just the ids of objects. If objects are showing up a long > > MIME encoded serialized strings, you may want to rethink your > > strategy. > > > > On Sun, Mar 23, 2008 at 11:24 AM, Yura Tkachenko > > <[EMAIL PROTECTED]> wrote: > > > Thank you Anton. Both solutions are works good for me. But still I have > > a > > > question why Tapestry 5 is generating long URL for activation context > > > instead of sending these data using HTTP POST? > > > > > > > > > > > > > > > On Sun, Mar 23, 2008 at 12:54 AM, Anton Litvinenko < > > > [EMAIL PROTECTED]> wrote: > > > > > > > To pass more than parameter, a) from onPassivate method you should > > > > return an object array: > > > > > > > > Object[] onPassivate() { > > > > return new Object[] {getProductId(), "some string", true}; > > > > } > > > > > > > > b) Then you either define onActivate method as > > > > > > > > void onActivate(long productId, String xxx, Boolean yyy) { > > > > setProductId(productId); > > > > loadProduct(); > > > > } > > > > > > > > or > > > > > > > > void onActivate(Object[] context) { > > > > Long projectId = Long.parseLong(((String) context[0])); > > > > .... > > > > } > > > > > > > > In case you decide to use the latter, then you should be aware that > > > > context contains String representations of objects returned by > > > > onPassivate. > > > > > > > > The second question: to pass your own value objects as context > > > > parameters you should specify the strategy for converting your object > > > > to string and restoring its state from the string (i.e. coercer) in > > > > you AppModule. For instance to specify Date-to-String and > > > > String-to-Date coercing you'd have to do the following: > > > > > > > > public static void > > > > contributeTypeCoercer(Configuration<CoercionTuple> configuration) { > > > > Coercion<Date, String> dateToString = new Coercion<Date, > > String>() > > > > { > > > > public String coerce(Date date) { > > > > return (new > > > > SimpleDateFormat(DATETIME_PATTERN)).format(date); > > > > } > > > > }; > > > > > > > > Coercion<String, Date> stringToDate = new Coercion<String, > > Date>() > > > > { > > > > public Date coerce(String date) { > > > > try { > > > > return (new > > > > SimpleDateFormat(DATETIME_PATTERN)).parse(date); > > > > } catch (ParseException e) { > > > > throw new RuntimeException("Coercion failed!", e); > > > > } > > > > } > > > > }; > > > > > > > > configuration.add(new CoercionTuple<Date, String>(Date.class, > > > > String.class, dateToString)); > > > > configuration.add(new CoercionTuple<String, > > > > Date>(String.class, Date.class, stringToDate)); > > > > } > > > > > > > > Check this for more: > > > > http://tapestry.apache.org/tapestry5/tapestry-ioc/coerce.html > > > > > > > > Good luck! > > > > Anton > > > > > > > > On Sun, Mar 23, 2008 at 8:32 AM, Yura Tkachenko > > > > <[EMAIL PROTECTED]> wrote: > > > > > And how I can pass more than one parameter? Or did you mean "I > > cannot > > > > pass > > > > > more than one parameter"? > > > > > > > > > > Thanks, > > > > > Yura. > > > > > > > > > > > > > > > > > > > > On Sat, Mar 22, 2008 at 10:46 PM, SergeEby <[EMAIL PROTECTED]> > > wrote: > > > > > > > > > > > > > > > > > Hi, > > > > > > > > > > > > You can pass more than one parameter. > > > > > > > > > > > > /Serge > > > > > > > > > > > > > > > > > > Yura Tkachenko wrote: > > > > > > > > > > > > > > Hi All, > > > > > > > > > > > > > > I've been reading chapter about "Page Activation Context" > > here: > > > > > > > > > > > http://tapestry.apache.org/tapestry5/tapestry-core/guide/pagenav.html > > . > > > > > > And > > > > > > > I > > > > > > > have a question: can I pass using activation context more than > > one > > > > > > > parameter? > > > > > > > > > > > > > > For example in help we have an example: > > > > > > > > > > > > > > void onActivate(long productId) { > > > > > > > setProductId(productId); > > > > > > > loadProduct(); > > > > > > > } > > > > > > > > > > > > > > long onPassivate() { > > > > > > > return getProductId(); > > > > > > > } > > > > > > > > > > > > > > Also it was mentioned onPassivate method should be like a > > mirror of > > > > > > > onActivate. Does it means I can't pass more than one > > parameter? > > > > > > > Another approach I tried is it create another Java Bean > > (wrapper > > > > object) > > > > > > > and > > > > > > > simple try to pass this bean via activation context. In that > > case > > > > my > > > > > > > onActivate and onPassivate were: > > > > > > > > > > > > > > void onActivate(PageWrapper wrappedData) { > > > > > > > System.out.println("Activated with message: " + > > > > wrappedData); > > > > > > > setWrapper(wrappedData); > > > > > > > } > > > > > > > > > > > > > > PageWrapper onPassivate() { > > > > > > > System.out.println("Page is passivated."); > > > > > > > return getWrapper(); > > > > > > > } > > > > > > > > > > > > > > As the result I got exception. From URL I understood that > > Typestry > > > > > > during > > > > > > > passing parameter via activation context is converting it to > > get > > > > > > request. > > > > > > > In > > > > > > > my case for wrapped object URL was: > > > > > > > > > > > > > > > > > > > > http://localhost:8080/t5first/second/com.packtpub.t5first.utils.PageWrapper%40307efc > > > > > > > After looking to that URL I realized that T5 just call > > toString of > > > > > > passed > > > > > > > object :-) > > > > > > > So my additional questions: > > > > > > > 1) Why not allow to user pass his own objects (POJO)? > > > > > > > 2) Why not pass data via HTTP POST? Because as far as I know > > HTTP > > > > (at > > > > > > > least > > > > > > > some browsers and http servers) has some limitations to the > > length > > > > of > > > > > > > URLs. > > > > > > > Besides sooner or later some smart users will pass string with > > a > > > > few > > > > > > > Kbytes > > > > > > > and the page will get wrong data (truncated). > > > > > > > > > > > > > > > > > > > > > > > > > > -- > > > > > > View this message in context: > > > > > > > > > > > > > http://www.nabble.com/Page-activation-context-question-tp16231642p16231791.html > > > > > > Sent from the Tapestry - User mailing list archive at Nabble.com > > . > > > > > > > > > > > > > > > > > > > > --------------------------------------------------------------------- > > > > > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > > > > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -- > > > > http://www.sourcekibitzer.org > > > > > > > > --------------------------------------------------------------------- > > > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > > > > > > > > > > > > > > > -- > > Howard M. Lewis Ship > > > > Creator Apache Tapestry and Apache HiveMind > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > -- Howard M. Lewis Ship Creator Apache Tapestry and Apache HiveMind --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]