Front: ui: default parameter value

How to determine default value for facelet template parameter? Consider the following element using a template parameter:

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

The line above will print the templParam template templParam , which is passed by the ui:param tag to ui:composition using the template:

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

But if the ui:param tag is missing, nothing will be printed. Although, how can I print, for example, "Default value" in this case?

+7
source share
3 answers

The default value can be determined using the ternary operator to check for a null value.

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

This will print “Default Value” if the parameter has not been passed with the ui:param tag.

+8
source

You can use the following:

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

Hope this helps.

+13
source

After the composition tag, to determine the beginning of the template, the template parameter can be set to the default value (if it is empty), so that all subsequent use of it does not require checking zero every time (and its default value is in the same place in the code).

 <html xmlns:c="http://java.sun.com/jsp/jstl/core" > <ui:composition> <c:set var="templParam" value="#{empty templParam ? 'Default value' : templParam}" scope="request" /> <h:outputText value="Use 1: #{templParam}" /> <h:outputText value="Use 2: #{templParam}" /> 
0
source

All Articles