将后备bean操作传递给Facelet标记文件 [英] Passing backing bean action to Facelet tag file

查看:127
本文介绍了将后备bean操作传递给Facelet标记文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的JSF 1.2项目中,我创建了一个facelet标记文件,并定义了一个具有actionListener属性的inputText,我需要将其传递给后备bean方法名称. 我尝试在标记文件中定义变量actionListener =#{actionListener}".在我调用组件的xhtml中,当我将值传递为

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}"

标记文件将其视为属性,并且错误指出没有找到属性'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?

谢谢 PT

推荐答案

标记文件中不支持传递方法表达式.只有从JSF 2.0开始,所谓的复合组件才有可能.

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

您可以做的是将bean引用和方法名称分开,以便您可以使用花括号表示法来调用该方法.我只是不确定这是否适用于actionListener,您通常不使用它来调用动作,但它肯定适用于action.

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.

例如

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

内部带有tag.xhtml

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

仅当您碰巧在Facelets上使用JSF 2.0时,才可以使用<o:methodParam>将方法表达式传递给标记文件.另请参阅动态ui包含和commandButton .

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.

这篇关于将后备bean操作传递给Facelet标记文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆