JSF 2.0:空运算符不能与param一起使用

Mr.*_*mes 5 java param el jsf-2

在文件中aPage.xhtml,我有以下几行:

<ui:include rendered="#{not empty param.target}" src="#{param.target}.html" />
<ui:include rendered="#{empty param.target}" src="About.html" />
Run Code Online (Sandbox Code Playgroud)

通过以上的线路,我预计,当我去http://localhost:8080/beta/aPage.xhtml时,页面About.html会因为已有的param.targetIS null.但是,GlassFish抛出了以下异常:

java.io.FileNotFoundException: http://localhost:8080/beta/.html
Run Code Online (Sandbox Code Playgroud)

不知何故,param.target不被认为是null.

此外,我确实尝试使用==!=运算符如下:

<ui:include rendered="#{param.target != null}" src="#{param.target}.html" />
<ui:include rendered="#{param.target == null}" src="About.html" />
Run Code Online (Sandbox Code Playgroud)

有趣的是,这一次,在GlassFish的控制台上,我没有看到任何异常抛出.但是,在浏览器上,仍会显示错误页面,但有例外java.io.FileNotFoundException.

如果你能告诉我为什么会这样,我应该做些什么来避免它,我将非常感激.

更新:

感谢Joop Eggen的提示,我终于用以下几行解决了这个问题:

<ui:param name="noTarget"  value="About.html" />
<ui:param name="hasTarget" value="#{param.target}.html" />
<ui:include src="#{empty param.target? noTarget : hasTarget}" />
Run Code Online (Sandbox Code Playgroud)

最好的祝福

Joo*_*gen 4

在这两种情况下都会评估 src,也许会进行文件存在测试?做

<ui:include src="#{empty param.target? 'About' : param.target}.html" />
Run Code Online (Sandbox Code Playgroud)

  • 在 EL 中不能使用 `+` 连接字符串。我修复了语法。 (2认同)
  • @Daniel:`&lt;ui:include&gt;` 的 `src` 中的 EL 在视图构建时评估,而不是在视图渲染时评估。仅当“src”指向有效路径时它才有效。 (2认同)