Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
860 views
in Technique[技术] by (71.8m points)

jsf - Passing backing bean action to Facelet tag file

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...