You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Aneesha Govil <po...@gmail.com> on 2006/11/07 08:49:21 UTC

Set actionlistener in java code?

Hi,

I need to associate an actionlistener with an htmlcommandbutton in java
code. I am using the following code snippet:

HtmlCommandButton addButton = new HtmlCommandButton();
addButton = new HtmlCommandButton();
MethodBinding mb = FacesContext.getCurrentInstance
().getApplication().createMethodBinding("#{filter.addFilterToSubset}", new
Class[0]);
addButton.setActionListener(mb);
addButton.setValue("Add");

The signature of addFilterToSubset method is as follows:

public void addFilterToSubset(ActionEvent event) {
     //some code here
    }

The problem is, on clicking the button, it tries to look for a method
addFilterToSubset() (no arguments). Shouldn't it be looking for one with
actionevent?

Please help. I don't know why something so simple isn't working.

Thanks a lot.
Regards,
Aneesha

Re: Set actionlistener in java code?

Posted by Aneesha Govil <po...@gmail.com>.
Hi,

It works now. Thanks.

Regards,
Aneesha

On 11/7/06, Volker Weber <we...@googlemail.com> wrote:
>
> Hi,
>
> you need to declare the method arguments on createMethodBinding.
>
> try:
> createMethodBinding("#{filter.addFilterToSubset}", new Class[]
> {ActionEvent.class});
>
> You can take a look into the tag sources for information how to set
> any tag attribute value into the UIComponent object.
>
> Regards,
>   Volker
>
>
>
> 2006/11/7, Aneesha Govil <po...@gmail.com>:
> > Hi,
> >
> > I need to associate an actionlistener with an htmlcommandbutton in java
> > code. I am using the following code snippet:
> >
> > HtmlCommandButton addButton = new HtmlCommandButton();
> > addButton = new HtmlCommandButton();
> >  MethodBinding mb =
> > FacesContext.getCurrentInstance
> ().getApplication().createMethodBinding("#{filter.addFilterToSubset}",
> > new Class[0]);
> >  addButton.setActionListener(mb);
> > addButton.setValue("Add");
> >
> > The signature of addFilterToSubset method is as follows:
> >
> > public void addFilterToSubset(ActionEvent event) {
> >       //some code here
> >     }
> >
> > The problem is, on clicking the button, it tries to look for a method
> > addFilterToSubset() (no arguments). Shouldn't it be looking for one with
> > actionevent?
> >
> > Please help. I don't know why something so simple isn't working.
> >
> > Thanks a lot.
> > Regards,
> > Aneesha
> >
> >
>

Re: Set actionlistener in java code?

Posted by Volker Weber <we...@googlemail.com>.
Hi,

you need to declare the method arguments on createMethodBinding.

try:
createMethodBinding("#{filter.addFilterToSubset}", new Class[]
{ActionEvent.class});

You can take a look into the tag sources for information how to set
any tag attribute value into the UIComponent object.

Regards,
  Volker



2006/11/7, Aneesha Govil <po...@gmail.com>:
> Hi,
>
> I need to associate an actionlistener with an htmlcommandbutton in java
> code. I am using the following code snippet:
>
> HtmlCommandButton addButton = new HtmlCommandButton();
> addButton = new HtmlCommandButton();
>  MethodBinding mb =
> FacesContext.getCurrentInstance().getApplication().createMethodBinding("#{filter.addFilterToSubset}",
> new Class[0]);
>  addButton.setActionListener(mb);
> addButton.setValue("Add");
>
> The signature of addFilterToSubset method is as follows:
>
> public void addFilterToSubset(ActionEvent event) {
>       //some code here
>     }
>
> The problem is, on clicking the button, it tries to look for a method
> addFilterToSubset() (no arguments). Shouldn't it be looking for one with
> actionevent?
>
> Please help. I don't know why something so simple isn't working.
>
> Thanks a lot.
> Regards,
> Aneesha
>
>