在JSF / JSP EL和Javascript中连接字符串

我在使用EL和javascript函数时遇到了麻烦(JSF 1.2,Facelets,Richfaces 3.3.0GA)。 我有一个包含另一个组成的页面:

  

在我的ui:composition我想将prefix附加到每个id。 例如:

  

这没问题。

但问题出现的时候我想访问函数中的组件,如oncomplete我无法让它正确地连接字符串。 例如

 oncomplete="#{rich:component('#{prefix}_examinationPanel')}.show();" 

我已尝试使用fn:join ,但它不执行该函数,因为它在发现“#”字符时会抱怨错误。 例如:

  oncomplete="#{rich:component(fn:join(#{prefix},'examinationPanel'))}.show()" 

 SEVERE: Servlet.service() for servlet Faces Servlet threw exception org.apache.el.parser.ParseException: Encountered "fn:join( #" at line 1, column 33. Encountered "fn:join( #" 

如果我用括号或#和括号括起来,会出现不同的错误。

我究竟做错了什么?

另一个问题,在条件命令中

 oncomplete="#{a}?#{b}:#{c}" 

如果真或假,我如何“分组”能够执行更多操作? 举例如下:

 oncomplete="#{a}?(#{b}#{f}):(#{c}#{d}#{e})" 

我尝试过括号,但没有正确解析它。

提前致谢。

假设您正在使用Facelets,这是一个相对较好的解决方案:

  • 在WEB-INF中创建functions.taglib.xml
  • 添加指示位置的上下文参数:

      facelets.LIBRARIES  /WEB-INF/functions.taglib.xml   
  • 在xml中放入以下内容:

        http://yournamespace.com/fnc  concat com.yourpackage.utils.Functions  java.lang.String concat(java.lang.String, java.lang.String)    
  • 在页面中使用以下内容:

     xmlns:fnc="http://yournamespace.com/fnc" .... oncomplete="#{rich:component(fnc:concat(prefix, '_examinationPanel'))}.show();" 
  • 最后,在Function类中定义简单方法:

     public static String concat(String string1, String string2) { return string1.concat(string2); } 

一个更简单的解决方案是像对象一样管理EL中的String,并使用String类中的方法concat,如下所示:

 #{rich:component('constantString'.concat(variable))}.show();