Function Can';是否将#{cc}参数传递给EL函数?
我已经定义了一个JSF复合组件,相关部分如下所示更新:改进了示例,使用Kukeltje推荐的JSF2.2命名空间声明,尽管问题仍然存在 /resources/functiontest/functiontest.xhtmlFunction Can';是否将#{cc}参数传递给EL函数?,function,jsf,parameter-passing,el,composite-component,Function,Jsf,Parameter Passing,El,Composite Component,我已经定义了一个JSF复合组件,相关部分如下所示更新:改进了示例,使用Kukeltje推荐的JSF2.2命名空间声明,尽管问题仍然存在 /resources/functiontest/functiontest.xhtml <?xml version="1.0" encoding="ISO-8859-1" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:composite="http://xmlns.jcp.org/jsf/composite"
xmlns:fn="http://xmlns.jcp.org/jsp/jstl/functions"
>
<composite:interface>
<composite:attribute name="value" type="java.util.Date"/>
<composite:attribute name="timeZone" type="java.util.TimeZone"/>
<composite:attribute name="update" type="java.lang.String"/>
</composite:interface>
<composite:implementation>
<div id="#{cc.clientId}">
clientId class=#{cc.clientId['class'].name}<br/>
clientId=#{cc.clientId}<br/>
value=#{cc.attrs.value}<br/>
timeZone=#{cc.attrs.timeZone}<br/>
update=#{cc.attrs.update}<br/>
<br/>
WORKS - fn:toLowerCase - #{fn:toLowerCase("hellOOOOOO")}<br/>
WORKS - whoName = #{myBean.user}<br/>
WORKS - fn:toUpperCase1 = #{fn:toUpperCase(myBean.user)}<br/>
WORKS - fn:toUpperCase2 = #{fn:toUpperCase(myBean.toString())}<br/>
WORKS - fn:toUpperCase3 = #{fn:toUpperCase(myBean['class'].simpleName)}<br/>
FAILS - fn:toUpperCase4 = #{fn:toUpperCase(cc.clientId['class'].name)}<br/>
FAILS - fn:toUpperCase5 = #{fn:toUpperCase(cc.clientId)}<br/>
FAILS - fn:toUpperCase6 = #{fn:toUpperCase(cc.attrs.value.toString())}<br/>
FAILS - fn:toUpperCase7 = #{fn:toUpperCase(cc.attrs.update)}<br/>
</div>
</composite:implementation>
</html>
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<h:head>
</h:head>
<h:body>
<div style="padding-left:5%; padding-right:5%;">
<ui:insert name="body">DEFAULT BODY!</ui:insert>
</div>
</h:body>
</html>
/testFunctionPage.xhtml(使用模板-从JSF2.2.5开始不起作用)
我最好的猜测是,使用cc有一些局限性,我还没有学会,我希望有人能说明他们是什么以及正在发生什么。这似乎是在JSF2.2.5中引入的;所有变体都适用于JSF2.2.1到2.2.4
下面是一些额外的奇怪行为。如果我先加载testFunctionPage.xhtml
,它就会失败。如果我加载testFunctionPageWithHBody.xhtml
,它将成功(如预期的那样)。然后,如果我加载testFunctionPage.xhtml
,它现在将成功,并将继续这样做,直到web服务器(Tomcat)重新启动
编辑:
我运行的环境是Windows 7、Java 1.7.080、Tomcat 7.0.68及其EL版本、JSF Mojarra 2.2.8-14、jstl 1.2、Eclipse Mars.2(4.5.2)。首先使用所有JSF 2.2命名空间声明:。不确定它是否起到了作用,但它从来都不是错误的捕获/更正,@Kukeltje,我肯定应该为jsf2.2使用这些新的名称空间声明。然而,这似乎不是问题的原因。我仍然在页面加载时得到“Function'fn:toUpperCase'notfound”
ELException
。如果先对“cc”执行一些空字符串的“字符串连接”会怎么样?那么它能工作吗?或者你得到空字符串吗?如果我传入”
,“abc”
,cc
,cc['class'].simpleName
,或者“abc.concat(cc)
,我就会得到期望的字符串。如果传入cc.toString()
,cc.attrs
,cc.attrs.value
,cc.attrs.value
,cc.attrs.timeZone
,,”,则未找到函数“fn:toUpperCase”。concat(cc.attrs.timeZone)
el没有强类型,也没有(可能?)自动转换为字符串。因此cc.attrs(返回列表?)使其成为函数的错误签名。cc.attrs.timeZone(时区)也适用于“concat”示例)。我不清楚cc.toString()失败的原因。而cc.attrs.value可能会返回“object”而不是字符串。。。至少对jstl函数的调用是这样的。通过使用所有jsf 2.2命名空间声明,您现在可能有了更多的信息可供调查启动:。不确定它是否起到了作用,但它从来都不是错误的捕获/更正,@Kukeltje,我肯定应该为jsf2.2使用这些新的名称空间声明。然而,这似乎不是问题的原因。我仍然在页面加载时得到“Function'fn:toUpperCase'notfound”ELException
。如果先对“cc”执行一些空字符串的“字符串连接”会怎么样?那么它能工作吗?或者你得到空字符串吗?如果我传入”
,“abc”
,cc
,cc['class'].simpleName
,或者“abc.concat(cc)
,我就会得到期望的字符串。如果传入cc.toString()
,cc.attrs
,cc.attrs.value
,cc.attrs.value
,cc.attrs.timeZone
,,”,则未找到函数“fn:toUpperCase”。concat(cc.attrs.timeZone)
el没有强类型,也没有(可能?)自动转换为字符串。因此cc.attrs(返回列表?)使其成为函数的错误签名。cc.attrs.timeZone(时区)也适用于“concat”示例)。我不清楚cc.toString()失败的原因。而cc.attrs.value可能会返回“object”而不是字符串。。。至少对jstl函数的调用是这样的。也许你现在有更多的信息要调查
<!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://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:composite="http://xmlns.jcp.org/jsf/composite"
xmlns:fn="http://xmlns.jcp.org/jsp/jstl/functions"
xmlns:fntest="http://xmlns.jcp.org/jsf/composite/functiontest"
>
<ui:composition template="/template/PublicPageTemplate.xhtml">
<ui:define name="body">
Function test:<br/>
<ui:repeat var="loopVar" value='#{"a,b,c".split(",")}'>
LoopVar=#{loopVar}<br/>
<fntest:functiontest id="tst2" value="#{myBean.now}" timeZone="#{myBean.timeZone}" update="UpdateOrDontUpdate"/>
</ui:repeat>
</ui:define>
</ui:composition>
</html>
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<h:head>
</h:head>
<h:body>
<div style="padding-left:5%; padding-right:5%;">
<ui:insert name="body">DEFAULT BODY!</ui:insert>
</div>
</h:body>
</html>
<!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://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:composite="http://xmlns.jcp.org/jsf/composite"
xmlns:fn="http://xmlns.jcp.org/jsp/jstl/functions"
xmlns:fntest="http://xmlns.jcp.org/jsf/composite/functiontest"
>
<h:head>
</h:head>
<h:body>
Function test:<br/>
<ui:repeat var="loopVar" value='#{"a,b,c".split(",")}'>
LoopVar=#{loopVar}<br/>
<fntest:functiontest id="tst2" value="#{myBean.now}" timeZone="#{myBean.timeZone}" update="UpdateOrDontUpdate"/>
</ui:repeat>
</h:body>
</html>
javax.el.ELException: Function 'fn:toUpperCase' not found