You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Angelo Chen <an...@yahoo.com.hk> on 2007/08/31 09:59:10 UTC

T5: Loop and ArrayList

Hi,

I searched list for a while and can't find solution to this, so will just
post it here:

I have an ArrayList of a class and I need to access it from the loop, here
is the code in java:

 public class Member {
        private String name;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public Member() {
            this.name = "member";
        }
    }

    private ArrayList newMembers = new ArrayList();


 public ArrayList getNewMembers()
    {
        return newMembers;
    }

  public Member getCurrentMember(int index)
    {
        return (Member)newMembers.get(index);

    }

here is the template, it seems not right:
<t:loop source="NewMembers" value = "CurrentMember" index="i" >
    // how to display the name of each member here ?
</t:loop>

-- 
View this message in context: http://www.nabble.com/T5%3A-Loop-and-ArrayList-tf4358642.html#a12421788
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


Re: [T5] Get Action

Posted by Robin Helgelin <lo...@gmail.com>.
On 9/1/07, John <mm...@web.de> wrote:
> Thank you Robin,
> well of course I can return the index of the array and then find out the
> correct Object.
> Is this not so trivial and done in every Grid/Table/ For loop?
> I thought, this could be done automatically by T5 itself.

It can, but as T5 doesn't know anything about your Product object you
have to learn T5 how to convert from String to your Product, hence you
need to write your own Type Coercion, see the link in the previous
mail.

-- 
        regards,
        Robin

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


Re: [T5] Get Action

Posted by Josh Canfield <jo...@thedailytube.com>.
On 9/1/07, John <mm...@web.de> wrote:
>
> Thank you Robin,
> well of course I can return the index of the array and then find out the
> correct Object.
> Is this not so trivial and done in every Grid/Table/ For loop?
> I thought, this could be done automatically by T5 itself.
>
> Regards.
> John


Hmm... I guess I'm not familiar enough with all the UI frameworks out there
to expect what you are asking to work out of the box with no wiring up
front.

I would return the id of the object and not the index of the array. Getting
your object from it's id shouldn't be too hard.

It's possible to get this to work automatically as Robin said, it just
requires setting up the wiring.

Josh

----- Original Message -----
> From: "Robin Helgelin" <lo...@gmail.com>
> To: "Tapestry users" <us...@tapestry.apache.org>
> Sent: Saturday, September 01, 2007 8:03 AM
> Subject: Re: [T5] Get Action
>
>
> > On 8/31/07, John <mm...@web.de> wrote:
> >> I get an execption, which I know what does it mean.
> >>
> >> Exception in method
> >> org.apache.tapestry.tutorial.pages.Start.onActionFromCurrentProduct(
> org.apache.tapestry.tutorial.others.Product)
> >> (at Start.java:84), parameter #1: Could not find a coercion from type
> >> java.lang.String to type org.apache.tapestry.tutorial.others.Product.
> >>
> >> My question is: how should my method or my HTML looks like to be able
> to
> >> receive the Product object and not an integer.
> >>
> >> It is possible, isnt it?
> >
> > Either let your method receive an String or Integer or something that
> > Tapestry understands, or, you could create a type ceorcion of you own
> > that takes a String and produces a Product object.
> >
> > http://tapestry.apache.org/tapestry5/tapestry-ioc/coerce.html
> >
> > --
> >        regards,
> >        Robin
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
--
TheDailyTube.com. Sign up and get the best new videos on the internet
delivered fresh to your inbox.

Re: [T5] Get Action

Posted by John <mm...@web.de>.
Thank you Robin,
well of course I can return the index of the array and then find out the 
correct Object.
Is this not so trivial and done in every Grid/Table/ For loop?
I thought, this could be done automatically by T5 itself.

Regards.
John


----- Original Message ----- 
From: "Robin Helgelin" <lo...@gmail.com>
To: "Tapestry users" <us...@tapestry.apache.org>
Sent: Saturday, September 01, 2007 8:03 AM
Subject: Re: [T5] Get Action


> On 8/31/07, John <mm...@web.de> wrote:
>> I get an execption, which I know what does it mean.
>>
>> Exception in method
>> org.apache.tapestry.tutorial.pages.Start.onActionFromCurrentProduct(org.apache.tapestry.tutorial.others.Product)
>> (at Start.java:84), parameter #1: Could not find a coercion from type
>> java.lang.String to type org.apache.tapestry.tutorial.others.Product.
>>
>> My question is: how should my method or my HTML looks like to be able to
>> receive the Product object and not an integer.
>>
>> It is possible, isnt it?
>
> Either let your method receive an String or Integer or something that
> Tapestry understands, or, you could create a type ceorcion of you own
> that takes a String and produces a Product object.
>
> http://tapestry.apache.org/tapestry5/tapestry-ioc/coerce.html
>
> -- 
>        regards,
>        Robin
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
> 


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


Re: [T5] Get Action

Posted by Robin Helgelin <lo...@gmail.com>.
On 8/31/07, John <mm...@web.de> wrote:
> I get an execption, which I know what does it mean.
>
> Exception in method
> org.apache.tapestry.tutorial.pages.Start.onActionFromCurrentProduct(org.apache.tapestry.tutorial.others.Product)
> (at Start.java:84), parameter #1: Could not find a coercion from type
> java.lang.String to type org.apache.tapestry.tutorial.others.Product.
>
> My question is: how should my method or my HTML looks like to be able to
> receive the Product object and not an integer.
>
> It is possible, isnt it?

Either let your method receive an String or Integer or something that
Tapestry understands, or, you could create a type ceorcion of you own
that takes a String and produces a Product object.

http://tapestry.apache.org/tapestry5/tapestry-ioc/coerce.html

-- 
        regards,
        Robin

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


[T5] Get Action

Posted by John <mm...@web.de>.
Hello,

I have the following Table in my html file



<table border="2" width="100%">

      <tr t:type="loop" source="products" value="currentProduct">

            <td> <a t:id="select" t:type="actionlink" 
context="currentProduct"> ${currentProduct.id}</a></td>

            <td>${currentProduct.id}</td>

            <td>${currentProduct.name}</td>

            <td>${currentProduct.description}</td>

      </tr>

</table>



 in my Java file i have all required data/Getters/Setters and I can disply 
the data.

I hava a method in my java file like this:



@OnEvent(component = "select")

String whenUserClicks( Product currentProduct)

{

      System.out.println("ok");

      return null;

}





I get an execption, which I know what does it mean.

Exception in method 
org.apache.tapestry.tutorial.pages.Start.onActionFromCurrentProduct(org.apache.tapestry.tutorial.others.Product) 
(at Start.java:84), parameter #1: Could not find a coercion from type 
java.lang.String to type org.apache.tapestry.tutorial.others.Product.



My question is: how should my method or my HTML looks like to be able to 
receive the Product object and not an integer.

It is possible, isnt it?

Thanks in advance

John


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


Re: T5: Loop and ArrayList

Posted by Angelo Chen <an...@yahoo.com.hk>.
Hi Nick,

Thanks, got it working, your explanation clarifies points that I can't get
from the doc.


Nick Westgate wrote:
> 
> The loop assigns each successive item to the value you give.
> So for each iteration (item in the list) it will try to call:
> setCurrentMember(Member member)
> 
> You need to provide such a member and set/get methods in Java:
> private currentMember;
> 
> Then inside the loop you can refer to it using prop notation:
> ${currentMember.name}
> 
> Cheers,
> Nick.
> 
> 

-- 
View this message in context: http://www.nabble.com/T5%3A-Loop-and-ArrayList-tf4358642.html#a12423049
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


Re: T5: Loop and ArrayList

Posted by Nick Westgate <ni...@key-planning.co.jp>.
The loop assigns each successive item to the value you give.
So for each iteration (item in the list) it will try to call:
setCurrentMember(Member member)

You need to provide such a member and set/get methods in Java:
private currentMember;

Then inside the loop you can refer to it using prop notation:
${currentMember.name}

Cheers,
Nick.


Angelo Chen wrote:
> Hi,
> 
> I searched list for a while and can't find solution to this, so will just
> post it here:
> 
> I have an ArrayList of a class and I need to access it from the loop, here
> is the code in java:
> 
>  public class Member {
>         private String name;
> 
>         public String getName() {
>             return name;
>         }
> 
>         public void setName(String name) {
>             this.name = name;
>         }
> 
>         public Member() {
>             this.name = "member";
>         }
>     }
> 
>     private ArrayList newMembers = new ArrayList();
> 
> 
>  public ArrayList getNewMembers()
>     {
>         return newMembers;
>     }
> 
>   public Member getCurrentMember(int index)
>     {
>         return (Member)newMembers.get(index);
> 
>     }
> 
> here is the template, it seems not right:
> <t:loop source="NewMembers" value = "CurrentMember" index="i" >
>     // how to display the name of each member here ?
> </t:loop>
> 

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