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]
>
>

Reply via email to