Question

In my JSF 1.2 project, I have created a facelet tag file and defined an inputText that has actionListener attribute to which I need to pass the backing bean method name. I tried defining a variable actionListener="#{actionListener}" in the tag file. In my xhtml where I call the component, when I pass the value as

actionListener="#{myBean.preFillData}"

tag file treats it as a property and errors out indicating no property 'preFillData' found. If I change it to

actionListener="#{myBean.preFillData()}"

then there is a parse error in the tag file because it doesnot like parenthesis to indicate method name.

How do we pass method name to the tag file?

Thanks PT

Was it helpful?

Solution

Passing method expressions is not supported in tag files. Only since JSF 2.0 it's possible with so-called composite components.

What you can do is to separate the bean reference and the method name so that you can use the brace notation to invoke the method. I'm only not sure if that works out for an actionListener, you normally don't use that to invoke actions, but it should definitely work for an action.

E.g.

<my:tag ... bean="#{myBean}" actionMethod="preFillData" />

with inside tag.xhtml

<h:commandButton ... action="#{bean[actionMethod]}" />

Only if you happen to use JSF 2.0 on Facelets, then you can use <o:methodParam> to pass a method expression to a tag file. See also a.o. Dynamic ui include and commandButton.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top