Dear Onur,
That was a great help, and makes it much more simple.
Yesterday i have give up and wrote a decode methode to get the id of the
submited component, but with ActionListener its much more elegant.
Thanks
Hanspeter
For other beginers, here the code:
---------------------------------------------
import javax.faces.event.ActionEvent;
public void doAction (ActionEvent e) {
UIComponent component = e.getComponent();
FacesContext context = FacesContext.getCurrentInstance();
String nodeId = component.getClientId(context);
}
MethodBinding:
MethodBinding mb =
context.getApplication().createMethodBinding("#{DummyBean.doAction }", new
Class[]{ActionEvent.class});
linkItem.setActionListener(mb);
-----Ursprüngliche Nachricht-----
Von: Onur Tokan [mailto:[EMAIL PROTECTED]
Gesendet: Dienstag, 31. Januar 2006 07:53
An: MyFaces Discussion
Betreff: Re: cerateMethodeBinding
Hi,
Change doAction method to action listener type, and change in your code
linkItem.setAction(mb); ---> linkItem.setActionListener(mb);
Now You got an ActionEvent object in your actionListener,
Hope it helps,
Regards,
Onur
On 1/30/06, Marti Hanspeter <[EMAIL PROTECTED]> wrote:
> hi,
>
> i am new in myfaces and beans and try to find out how i can pass
> arguments with cerateMethodeBinding. my bean adds some commandLink
> commponents to the view and each action of the commandLink commponent
> points back to the bean. So far it works, but i would like to detect
> with commandLink commponent was clicked. I tried with arrays like...
>
> DummyModel.getDummyItems()[1].doSomeThing(); --> #{DummyBean.???}
>
> Does that works or are i total wrong?
>
> Is there another workaround to solve this problem?
>
> Thanks!
> regards,
> Hanspeter
>
> Ex.:
>
> public class DummyModel {
>
> private List _listItems;
>
> public DummyModel() {
> _listItems = new ArrayList();
> _listItems.add(new MenuNode("Node 1", 0));
> _listItems.add(new MenuNode("Node 2", 1));
> _listItems.add(new MenuNode("Node 3", 2));
> _listItems.add(new MenuNode("Node 4", 3));
>
> }
>
> public MenuNode[] getDummyItems()
> {
> if (_listItems == null) return new MenuNode[0];
> return (MenuNode[]) _listItems.toArray(new
> MenuNode[_listItems.size()]);
> }
>
> public void doAction() {
> System.out.println("ok");
> }
> }
>
> public class DummyNode {
>
> private HtmlCommandLink linkItem;
>
> public HtmlCommandLink getHtmlCommandLink() {
> return linkItem;
> }
>
> public void doSomeThing() {
> System.out.println("doSomeThing in DummyNode ");
> }
>
> public DummyNode(String text, int index) {
> linkItem = new HtmlCommandLink();
> HtmlOutputText textItem = new HtmlOutputText();
> textItem.setValue(text);
> linkItem.getChildren().add(textItem);
> FacesContext context =
> FacesContext.getCurrentInstance();
>
> MethodBinding mb =
> context.getApplication().createMethodBinding("#{DummyBean.doAction}",
null);
> linkItem.setAction(mb);
> }
> }
>
>
>