Facelets:ui:param默认值 [英] Facelets: ui:param default value

查看:133
本文介绍了Facelets:ui:param默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何定义Facelet模板参数的默认值? 考虑使用模板参数的以下元素:

How can one define a default value for a facelet template parameter? Consider the following element using a template parameter:

<h:outputText value="#{templParam}"></h:outputText>

上面的行将打印模板参数templParam,该参数由ui:composition中的ui:param标签使用模板传递:

The above line will print the the template parameter templParam which is passed by a ui:param tag in a ui:composition using the template:

<ui:param name="templParam" value="Hello world"></ui:param>

但是如果缺少ui:param标签,将不会打印任何内容.不过,在这种情况下,如何打印例如默认值"?

But if ui:param tag is missing nothing will be printed. Although, how can one print e.g "Default value" in this case?

推荐答案

可以使用三元运算符检查空值.

<h:outputText value="#{templParam != null ? templParam : 'Default value'}"></h:outputText>

如果参数未通过ui:param标记传递,则将打印默认值".

This will print "Default value" if the parameter was not passed by a ui:param tag.

这篇关于Facelets:ui:param默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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