You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@click.apache.org by Andrei <gm...@gmail.com> on 2010/06/09 22:58:44 UTC

listener not invoked for ArrayList

I need to show links, which i need to populate dynamically

@Bindable protected List<ActionLink> scripts = new ArrayList<ActionLink>();

I fill ArrayList with links, which i create in onInit() and then show
them in Velocity using #foreach

For each link i set listener

link.setActionListener(new ActionListener() {
            public boolean onAction(Control control) {
             return true;
}

But onAction never get called when i click on links

What do i do wrong here?
Thanks

Re: listener not invoked for ArrayList

Posted by Andrei <gm...@gmail.com>.
That worked
Thanks

On Wed, Jun 9, 2010 at 7:27 PM, Bob Schellink <sa...@gmail.com> wrote:
> Hi Andrei,
>
> Controls need to be reachable from the Page itself. You can do this by either adding the link to the
> Page or by adding the link to a Container.
>
> From what you describe I think you are only adding the links to the ArrayList itself so the Page is
> not aware of the links and can't process them. Here is a short example:
>
>  public MyPage...
>
>  public void onInit() {
>    for(int i = 0; i < 10; i++) {
>      String name = "link" + i;
>      ActionLink link = new ActionLink(name);
>
>      link.setActionListener(new ActionListener() {
>        public boolean onAction(Control control) {
>          return true;
>        }
>      });
>
>      addControl(link);
>      list.add(link);
>    }
>  }
>
> Hope this helps.
>
> Kind regards
>
> Bob
>
> On 10/06/2010 06:58, Andrei wrote:
>> I need to show links, which i need to populate dynamically
>>
>> @Bindable protected List<ActionLink> scripts = new ArrayList<ActionLink>();
>>
>> I fill ArrayList with links, which i create in onInit() and then show
>> them in Velocity using #foreach
>>
>> For each link i set listener
>>
>> link.setActionListener(new ActionListener() {
>>             public boolean onAction(Control control) {
>>              return true;
>> }
>>
>> But onAction never get called when i click on links
>>
>> What do i do wrong here?
>> Thanks
>>
>
>

Re: listener not invoked for ArrayList

Posted by Bob Schellink <sa...@gmail.com>.
Hi Andrei,

Controls need to be reachable from the Page itself. You can do this by either adding the link to the
Page or by adding the link to a Container.

>From what you describe I think you are only adding the links to the ArrayList itself so the Page is
not aware of the links and can't process them. Here is a short example:

  public MyPage...

  public void onInit() {
    for(int i = 0; i < 10; i++) {
      String name = "link" + i;
      ActionLink link = new ActionLink(name);

      link.setActionListener(new ActionListener() {
        public boolean onAction(Control control) {
          return true;
        }
      });

      addControl(link);
      list.add(link);
    }
  }

Hope this helps.

Kind regards

Bob

On 10/06/2010 06:58, Andrei wrote:
> I need to show links, which i need to populate dynamically
> 
> @Bindable protected List<ActionLink> scripts = new ArrayList<ActionLink>();
> 
> I fill ArrayList with links, which i create in onInit() and then show
> them in Velocity using #foreach
> 
> For each link i set listener
> 
> link.setActionListener(new ActionListener() {
>             public boolean onAction(Control control) {
>              return true;
> }
> 
> But onAction never get called when i click on links
> 
> What do i do wrong here?
> Thanks
>