JSF2复合cc.attrs表达式无法正确评估动作参数 [英] JSF2 composite cc.attrs expression does not evaluate action parameters correctly

查看:89
本文介绍了JSF2复合cc.attrs表达式无法正确评估动作参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JSF复合组件,该组件是可以动态添加到以下地址和从其中删除的电子邮件地址的列表:

<composite:interface shortDescription="Display party email addresses">
    <composite:attribute name="addressable" required="true"/>
</composite:interface>

<composite:implementation>  
    <h:panelGroup layout="block" id="emails">
        <h:dataTable id="emailList" value="#{cc.attrs.addressable.emailAddresses}" var="email" styleClass="data-list small-list" cellpadding="0" cellspacing="0">
            <h:column>
                <f:facet name="header">Address</f:facet>
                <h:inputText id="emailAddress" value="#{email.address}" size="30" maxlength="100" required="true" label="Email"/>
            </h:column>
            <h:column>
                <f:facet name="header">Description</f:facet>
                <h:inputText id="emailDescription" value="#{email.description}" size="20" maxlength="100"/>
            </h:column>        
            <h:column>
                <f:facet name="header">
                    <h:panelGroup styleClass="right-align" layout="block">
                        <h:commandLink id="addEmail" action="#{cc.attrs.addressable.addEmailAddress}" title="Add an email address">
                            <f:ajax execute=":#{cc.clientId}:emails" render=":#{cc.clientId}:emails"/>
                            <h:graphicImage library="images" name="add.png" id="emailAddImg"/>
                        </h:commandLink>
                    </h:panelGroup>
                </f:facet>
                <h:commandLink id="deleteEmail" action="#{cc.attrs.addressable.remove(email)}" title="Remove the email from this row">
                    <f:ajax execute=":#{cc.clientId}:emails" render=":#{cc.clientId}:emails"/>
                    <h:graphicImage library="images" name="delete.png" id="emailDeleteImg"/>
                </h:commandLink>
            </h:column>          
        </h:dataTable> 
    </h:panelGroup>
</composite:implementation>

该组件的用法如下:

<edit:emailAddresses addressable="#{personAddressable}" id="emailAddresses"/>

在调用"deleteEmail"操作的地方会导致异常:

错误[STDERR]原因:javax.el.MethodNotFoundException:/resources/edit/emailAddresses.xhtml @ 34,130 action =#{cc.attrs.addressable.remove(email)}":找不到方法:否-端点[jboss.j2ee:jar = tephra.war,name = PersonAddressable,service = EJB3]和会话3j011-mgweoj-ghfwhlvv-1-ghfy2e5j-e1.remove()的接口视图

但是,如果将操作更改为personAddressable.remove(email),它将起作用!这似乎是简单的参数替换,不应有任何区别.添加没有参数的电子邮件地址的操作正常.

我不会发布支持bean的代码,因为我已经证明它可以工作.但仅供参考,它是一个有状态会话范围的bean(CDI).

我正在使用使用el 2.2的JBoss AS6-M5.

解决方案

我可以在Tomcat 7.0.5上重现该问题,但在Glassfish 3.0.1上则不能.这意味着在EL的Tomcat实施中存在一个错误.我报告了一个错误: Tomcat错误50449 .

由于JBoss使用的是Tomcat的分叉,所以同样的错误也可能出现在JBoss中也就不足为奇了.

您可以(暂时)使用

结合Addressable bean中的email属性,至少带有一个setter.

I have a JSF composite component which is a list of email addresses that can be dynamically added to, and deleted from:

<composite:interface shortDescription="Display party email addresses">
    <composite:attribute name="addressable" required="true"/>
</composite:interface>

<composite:implementation>  
    <h:panelGroup layout="block" id="emails">
        <h:dataTable id="emailList" value="#{cc.attrs.addressable.emailAddresses}" var="email" styleClass="data-list small-list" cellpadding="0" cellspacing="0">
            <h:column>
                <f:facet name="header">Address</f:facet>
                <h:inputText id="emailAddress" value="#{email.address}" size="30" maxlength="100" required="true" label="Email"/>
            </h:column>
            <h:column>
                <f:facet name="header">Description</f:facet>
                <h:inputText id="emailDescription" value="#{email.description}" size="20" maxlength="100"/>
            </h:column>        
            <h:column>
                <f:facet name="header">
                    <h:panelGroup styleClass="right-align" layout="block">
                        <h:commandLink id="addEmail" action="#{cc.attrs.addressable.addEmailAddress}" title="Add an email address">
                            <f:ajax execute=":#{cc.clientId}:emails" render=":#{cc.clientId}:emails"/>
                            <h:graphicImage library="images" name="add.png" id="emailAddImg"/>
                        </h:commandLink>
                    </h:panelGroup>
                </f:facet>
                <h:commandLink id="deleteEmail" action="#{cc.attrs.addressable.remove(email)}" title="Remove the email from this row">
                    <f:ajax execute=":#{cc.clientId}:emails" render=":#{cc.clientId}:emails"/>
                    <h:graphicImage library="images" name="delete.png" id="emailDeleteImg"/>
                </h:commandLink>
            </h:column>          
        </h:dataTable> 
    </h:panelGroup>
</composite:implementation>

This component is used as follows:

<edit:emailAddresses addressable="#{personAddressable}" id="emailAddresses"/>

Where the 'deleteEmail' action is invoked it causes an exception:

ERROR [STDERR] Caused by: javax.el.MethodNotFoundException: /resources/edit/emailAddresses.xhtml @34,130 action="#{cc.attrs.addressable.remove(email)}": Method not found: No-Interface view for endpoint [ jboss.j2ee:jar=tephra.war,name=PersonAddressable,service=EJB3 ] and session 3j011-mgweoj-ghfwhlvv-1-ghfy2e5j-e1.remove()

However if the action is changed to personAddressable.remove(email) it works! This seems like simple parameter substitution and shouldn't make any difference. The action for adding an email address, which does not have a parameter, works fine.

I won't post the code for the backing bean as I've proved it works. But for reference it is a stateful conversation scoped bean (CDI).

I am using JBoss AS6-M5 which uses el 2.2.

解决方案

I could reproduce the problem on Tomcat 7.0.5, but not on Glassfish 3.0.1. This means that there's a bug in EL implementation of Tomcat. I've reported a bug about it: Tomcat Bug 50449.

Since JBoss is under the covers using a fork of Tomcat, it's not a surprise that the same bug could manifest in JBoss as well.

You could (temporarily) workaround this by using f:setPropertyActionListener instead.

<h:commandLink action="#{cc.attrs.addressable.remove}">
    <f:setPropertyActionListener target="#{cc.attrs.addressable.email}" value="#{email}" />

in combination with an email property in the Addressable bean, with at least a setter.

这篇关于JSF2复合cc.attrs表达式无法正确评估动作参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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