You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Norman Franke <No...@myASD.com> on 2012/02/09 19:20:23 UTC

T5 Context and Arrays/Lists

I want to pass several values an event link and then get those values  
back via the event listener.

If I specify the context to be an array (even an array of Hibernate  
objects), the context seems to work right. The url has each element of  
the array / list as a separate path component. That works great.

However, how do I get it working on the listener? I thought I could  
just put an array as the context parameter argument. All I seem to get  
is a coercion error. Is this not supported or am I doing it wrong?

This is using Tapestry 5.2.5:

URL:
http://my.web.site:8000/url.../start:test/1/2?t:ac=$N/$N

.tml:

<t:eventlink t:event="test" t:context="ids">Test</t:eventlink>

.java:

     public Long[] getIds() {
         Long res[] = new Long[2];
         res[0] = 1l;
         res[1] = 2l;
         return res;
     }

     public void onTest(Long [] ids) {
         for (Long id : ids)
             System.out.println(id);
     }

Error:

Exception in method  
com.myasd.billing.pages.Start.onTest(java.lang.Long[]) (at Start.java: 
412), parameter #1: Could not find a coercion from type  
java.lang.String to type [Ljava.lang.Long;.
context
1
2
eventType
test

Norman Franke
Answering Service for Directors, Inc.
www.myasd.com




Re: T5 Context and Arrays/Lists

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Thu, 09 Feb 2012 16:20:23 -0200, Norman Franke <No...@myasd.com> wrote:

> I want to pass several values an event link and then get those values
> back via the event listener.
>
> If I specify the context to be an array (even an array of Hibernate
> objects), the context seems to work right. The url has each element of
> the array / list as a separate path component. That works great.
>
> However, how do I get it working on the listener? I thought I could
> just put an array as the context parameter argument. All I seem to get
> is a coercion error. Is this not supported or am I doing it wrong?

Use EventContext instead:

public void onTest(EventContext context) {
     for (int i = 0; i < context.getCount(); i++) {
          Long id = context.get(Long.class, i);
          ...
     }
}

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

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