1

I need your help in passing the proper method to the button actionListner. I am having a button in a datatable. The button code is below:

<h:commandButton id="submitButton" value="View" actionListener="#{bcd.showDatailDialog}" >
<f:setPropertyActionListener value="#{c}" target="#{bcd.selectedRequest}"/>
</h:commandButton>

Based on the value of the #{c.documentType} which is displayed in the datatable, it will decide which method to be used in the actionListner.

The showDatailDialog method code is:

public String showDatailDialog(String sdoc) {

private String methodName; 

try {

if (sdoc.equalsIgnoreCase("CE")) {

mthodName="#{bcd.BCESS}";

}
else
{
mthodName="#{bcd.BSSES}";   
}

        } catch (Exception e) {
            System.err.print(e);
            e.printStackTrace();
        }
return methodName;
    }

Now when I click on the button, it showed me an error:

<ActionListenerImpl> <processAction> javax.el.MethodNotFoundException: //C:/../JDeveloper/../XXX.war/jsf/Search.jsf @91,89 action="#{bcd.showDetailDialog}": Method not found: rfc.Bean3@355f70.showDetailDialog() 
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
99maas
  • 1,239
  • 12
  • 34
  • 59

2 Answers2

3

You're approaching this problem wrongly. The actionListener (and action) attributes must represent a method expression, not a value expression. Right now you're treating it as if it were a value expression returning a method expression. This isn't going to work.

Just let it invoke a real method which in turn delegates further to the desired method.

<h:dataTable ... var="item">
   ...
   <h:commandButton ... action="#{bean.action(item)}" />
public void action(Item item) {
    if (item.getType() == Type.FOO) { // It's of course an enum.
        oneMethod(item);
    } else {
        otherMethod(item);
    }
}

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
0

showDatailDialog method in your code expects one String parameter, so just use it like this

actionListener="#{bcd.showDatailDialog(c.documentType)}"
Predrag Maric
  • 23,938
  • 5
  • 52
  • 68