1

I'm trying to include <f:viewParam> and <f:viewAction> tags conditionally in my JSF pages with JSTLs <c:if> as I don't want to manually specify the viewParams in every single JSF page. Unfortunately it is not working...

metadata_include.xhtml

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://xmlns.jcp.org/jsf/core"
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
    xmlns:c="http://xmlns.jcp.org/jsp/jstl/core">
    <f:metadata>
        <f:viewParam name="from" value="#{loginBean.from}" />
        <c:if test="#{detailsId eq 'true'}">
            <f:viewParam id="detailsid" name="detailsid" value="#{detailsBean.detailsId}" />
            <f:viewAction action="#{detailsBean.onload}" />
        </c:if>
    </f:metadata>
</ui:composition>

details.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:f="http://xmlns.jcp.org/jsf/core"
    xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<h:head>
    <ui:include src="/WEB-INF/metadata_include.xhtml">
        <ui:param name="detailsId" value="true" />
    </ui:include>
</h:head>
<h:body>
</h:body>
</html>

Anybody knows what I'm doing wrong or knows a different way how to achieve this kind of behavior?

I also tried it with <h:panelGroup rendered="#{detailsId eq 'true'}"> without success.

jansohn
  • 1,864
  • 2
  • 21
  • 37
  • hy, why you put metadata_include.xhtml in WEB-INF folder? – sghaier ali Oct 30 '15 at 14:03
  • see http://stackoverflow.com/questions/3915716/how-to-check-a-boolean-condition-in-el – sghaier ali Oct 30 '15 at 14:08
  • @BalusC care to explain why the question is a duplicate? So far I don't use templates and I don't see how I could conditionally specify viewParams with it. – jansohn Oct 30 '15 at 14:20
  • But I'm neither using the template attribute nor a `` tag? How would I include the conditional viewParams? – jansohn Oct 30 '15 at 14:25
  • 1
    Really? So either I define static viewParams (same on every page) or I need to specify the viewParams in every single JSF page?! What a major letdown... Still don't see why the question is a duplicate though as the linked answer does not provide a solution where you can keep the viewParams dynamic! – jansohn Oct 30 '15 at 14:41

0 Answers0