In the file aPage.xhtml, I have the following lines:
<ui:include rendered="#{not empty param.target}" src="#{param.target}.html" />
<ui:include rendered="#{empty param.target}" src="About.html" />
With the above lines, I expected that when I go to http://localhost:8080/beta/aPage.xhtml, the page About.html would be included since the param.target is null. However, GlassFish threw me the following exception:
java.io.FileNotFoundException: http://localhost:8080/beta/.html
Somehow, param.target was not considered to be null.
Besides, I did try to use == and != operators as following:
<ui:include rendered="#{param.target != null}" src="#{param.target}.html" />
<ui:include rendered="#{param.target == null}" src="About.html" />
Interestingly, this time, on the console of GlassFish, I didn't see any exception thrown. However, on the browser, an error page still appears with the exception java.io.FileNotFoundException.
I'd be very grateful if you could tell me why this happened and what I should do to avoid it.
UPDATE:
Thanks to the hint from Joop Eggen, I finally solved the problem with the following lines:
<ui:param name="noTarget" value="About.html" />
<ui:param name="hasTarget" value="#{param.target}.html" />
<ui:include src="#{empty param.target? noTarget : hasTarget}" />
Best regards
The src is evaluated in both cases, maybe with a file existence test? Do
<ui:include src="#{empty param.target? 'About' : param.target}.html" />
ui:include got no rendered attribute... wrap it with <h:panelGroup
like this
<h:panelGroup rendered="#{not empty param.target}">
<ui:include src="#{param.target}.html" />
</h:panelGroup>
<h:panelGroup rendered="#{empty param.target}" >
<ui:include src="About.html" />
</h:panelGroup>
Edit
Unfortunately this will work only when EL in src of points a valid path ,
cause
EL in src of
<ui:include>is evaluated during view build time, not during view render time
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With