Jsf 复合组件的actionListener问题
我将解释一个问题,当我在模板中使用一个复合组件时,我遇到了这个问题 设想这样一个视图,它使用具有视图范围的通用托管bean。我将其作为参数传递给模板Jsf 复合组件的actionListener问题,jsf,jsf-2,composite-component,Jsf,Jsf 2,Composite Component,我将解释一个问题,当我在模板中使用一个复合组件时,我遇到了这个问题 设想这样一个视图,它使用具有视图范围的通用托管bean。我将其作为参数传递给模板 <?xml version='1.0' encoding='UTF-8' ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:trkal="http://java.sun.com/jsf/composite/trkalcomponents">
<ui:composition template="/template.xhtml">
<ui:param name="maisuBean" value="#{genericBean}" />
</ui:composition>
</html>
它似乎无法解析复合组件内部的EL表达式
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:trkal="http://java.sun.com/jsf/composite/trkalcomponents">
<h:head>
<title>Titulo</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</h:head>
<h:body>
<h:form enctype="multipart/form-data">
...
<trkal:toolbarbuttonwidget id="buttonToolbar" label="Action" iconName="toolbar.png"
buttonAction="#{maisuBean.myActionListener}"
>
</trkal:toolbarbuttonwidget>
...
<h:commandLink id="otherButton" actionListener="#{maisuBean.myActionListener}">
<h:graphicImage library="images" name="toolbar.png" />
<h:outputText value="Other Action" />
</h:commandLink>
...
</h:form>
</h:body>
</html>
怎么了?如何在一个模板中使用一个复合组件
我正在使用Mojarra 2.1.7
谢谢。很抱歉,我第一次读到时错过了这个: 您的实现没有正确地针对属性。我犯了这个错误(我敢肯定我们大家都犯了)。您需要将属性引用为->
{cc.attrs.someAttribute}
,而不是通过它们的名称。您可以对大多数元素执行此操作,但不能对actionListener
执行此操作。如果这是你的代码,它应该修复它。你的签名是正确的。您正在尝试使用我不熟悉的targetAttributeName
。我猜您需要将组件的id
设置为该名称(因此您的按钮应该是myAction
而不是actionListener
(如果我引用的是与您相同的示例)
除此之外,我会怎么做:
<composite:interface>
<composite:attribute name="id" />
<!--
<composite:attribute name="buttonAction" method-signature="void myAction(javax.faces.event.ActionEvent)" targetAttributeName="actionListener"/>
-->
<composite:attribute name="buttonAction" method-signature="void action(javax.faces.event.ActionEvent)"/>
<composite:attribute name="iconName" />
<composite:attribute name="label"/>
<composite:attribute name="title"/>
<composite:attribute name="styleClass"/>
</composite:interface>
<composite:implementation>
<h:outputStylesheet target="head" library="trkalcomponents" name="toolbarbuttonwidget.css" />
<!-- fix below -->
<h:commandLink id="buttonAction" actionListener=#{cc.attrs.buttonAction}>
<h:graphicImage library="images" name="#{cc.attrs.iconName}" />
<h:outputText value="#{cc.attrs.label}" />
</h:commandLink>
</composite:implementation>
我喜欢这种方法,因为它类似于页面标记的其他方式,而且看起来很简单。试一试。{maisuBean.myActionListener}是的,bean是注册的,正如我所说,如果我单击otherButton commandLink,它就会工作。bean注册为@ManagedBean(name=“genericBean”)和@ViewScoped。非常感谢您的帮助,但我尝试了这种方法,结果是一样的。错误消息是,它找不到托管bean genericBean的属性myActionListener。它就像尝试调用此属性的getter方法一样,在逻辑上它不存在。要确认:如果您这样做->
,以它工作的形式?您的错误听起来好像根本不起作用,并不是说它在组件内部不起作用。是的,模板的commandLink Other按钮可以正常工作,但是teamplate的Toolbar ButtonWidget按钮工具栏不起作用。一个大细节。我无法放置genericBean.myActionListener,因为模板管理bean maisuBean。模板接收我将bean的引用作为参数。有一些级别:使用页面、模板和复合组件,每个级别都管理其bean,作为参数接收或传递。在每个级别我都可以使用其引用。复合组件中给出的问题无法解决侦听器方法的EL表达式。
09-nov-2012 19:16:28 javax.faces.event.MethodExpressionActionListener processAction
GRAVE: Se ha recibido 'javax.el.PropertyNotFoundException' al invocar la escucha de acción '#{maisuBean.myActionListener}' para el componente 'buttonAction'
09-nov-2012 19:16:28 javax.faces.event.MethodExpressionActionListener processAction
GRAVE: javax.el.PropertyNotFoundException: /template.xhtml @20,6 buttonAction="#{maisuBean.myActionListener}": Propiedad 'myActionListener' no hallada en el tipo com.joxeja.test.ToolBarBean
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:111)
<composite:interface>
<composite:attribute name="id" />
<!--
<composite:attribute name="buttonAction" method-signature="void myAction(javax.faces.event.ActionEvent)" targetAttributeName="actionListener"/>
-->
<composite:attribute name="buttonAction" method-signature="void action(javax.faces.event.ActionEvent)"/>
<composite:attribute name="iconName" />
<composite:attribute name="label"/>
<composite:attribute name="title"/>
<composite:attribute name="styleClass"/>
</composite:interface>
<composite:implementation>
<h:outputStylesheet target="head" library="trkalcomponents" name="toolbarbuttonwidget.css" />
<!-- fix below -->
<h:commandLink id="buttonAction" actionListener=#{cc.attrs.buttonAction}>
<h:graphicImage library="images" name="#{cc.attrs.iconName}" />
<h:outputText value="#{cc.attrs.label}" />
</h:commandLink>
</composite:implementation>