You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by JeroenM <je...@hotmail.com> on 2009/07/06 08:54:39 UTC

Can someone help me with createMethodExpression

Hi, I'm new to Trinidad / JSF programming and I have some problems defining a
method binding to a composite bean.

The bean I'm developing has 2 control bindings; Topmenu and leftmenu.
Whenever a user clicks a topmenu link the left (sub)menu shows the
corresponding items. The topmenu doesn't have an action (because no
navigation is needed), only an actionListener

I create the topmenu command links by this code 

private CoreCommandNavigationItem createTopmenuLink(String linkText) {
    String id = view.createUniqueId();
    CoreCommandNavigationItem navitem = new CoreCommandNavigationItem();
    navitem.setText(linkText);
    navitem.setId(id);
				
    Class[] args = new Class[]{ActionEvent.class};
    MethodExpression binding = expressionFactory.createMethodExpression(
			 elContext, "#{menuBean.topmenuClick}", null, args);
    navitem.setActionExpression(binding);
    return navitem;
}


The method that gets called:

public void topmenuClick(ActionEvent event) {
    // do something like setting the current menu
}

The topmenu gets created and shows properly. However when I click the button
I get a IllegalArgumentException - wrong number of arguments exception. 

If I remove this method I get a method not found exception. Overloading the
function with a function who doesn't need parms doesn't help either.

Can someone help me with my problem? 
-- 
View this message in context: http://www.nabble.com/Can-someone-help-me-with-createMethodExpression-tp24350625p24350625.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: Can someone help me with createMethodExpression

Posted by JeroenM <je...@hotmail.com>.
I found out that I had to declare a MethodExpressionActionListener also...
Now the code works :)

@SuppressWarnings("unchecked")
private CoreCommandNavigationItem createTopmenuLink(String linkText) {
   String id = view.createUniqueId();
   CoreCommandNavigationItem navitem = new CoreCommandNavigationItem();
   navitem.setText(linkText);
   navitem.setId(id);

   Class[] args = new Class[] { ActionEvent.class };
   MethodExpression me = expressionFactory.createMethodExpression(
			elContext, "#{menuBean.topmenuClick}", null, args);
   MethodExpressionActionListener listener = new
MethodExpressionActionListener(me);
   navitem.addActionListener(listener);
   return navitem;
}
-- 
View this message in context: http://www.nabble.com/Can-someone-help-me-with-createMethodExpression-tp24350625p24351358.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.