primefaces - Why are validations from my JSF composite facet being done when the facet is not rendered -


i have problem validations composite's facet being fired when not render composite.

i stripped problem down following barebones code.

here composite entitydetailpanel:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"             xmlns:ui="http://java.sun.com/jsf/facelets"             xmlns:h="http://java.sun.com/jsf/html"             xmlns:composite="http://java.sun.com/jsf/composite"             xmlns:p="http://primefaces.org/ui"             xmlns:common="http://java.sun.com/jsf/composite/common">  <composite:interface>     <composite:attribute name="prefix" required="true" />     <composite:facet name="lowerpanel"/> </composite:interface>  <composite:implementation>      <h:form id="#{cc.attrs.prefix}entitydetailform2"              styleclass="#{cc.attrs.prefix}entitydetailpanelform #{cc.attrs.prefix}listener" >          <p:messages id="#{cc.attrs.prefix}messages" autoupdate="true" closable="true"/>          <p:commandbutton              value="save"              update="@(.#{cc.attrs.prefix}listener), @(.#{cc.attrs.prefix}entitydetailpanelform}"/>          <composite:renderfacet name="lowerpanel" rendered="false"/>     </h:form>  </composite:implementation> </ui:composition> 

and here invocation:

<?xml version="1.0" encoding="utf-8"?> <ui:composition xmlns="http://www.w3.org/1999/xhtml"             xmlns:ui="http://java.sun.com/jsf/facelets"             xmlns:f="http://java.sun.com/jsf/core"             xmlns:p="http://primefaces.org/ui"             xmlns:common="http://xmlns.jcp.org/jsf/composite/common">      <common:entitydetailpanel id="foo" prefix="instruments">          <f:facet name="lowerpanel">             <!--  <p:inputtext id="assetclassprompt" required="true"  requiredmessage="why message?"/>-->              <p:selectonemenu id="assetclassprompt" required="true"  requiredmessage="why message?"                              value="#{instrumentcontroller.selecteddata.assetclass}">                  <f:selectitem itemlabel="foo" itemvalue="foo"/>                  <f:selectitem itemlabel="bar" itemvalue="bar"/>             </p:selectonemenu>         </f:facet>     </common:entitydetailpanel>  </ui:composition> 

the combobox not show on screen (because it's not rendered), why getting validation that's not rendered?

this see when click save button:

enter image description here

stranger yet, see validation error on other invocations of composite not have combobox.

i noticed if not include unique id on <messages> tag, message 1 use of composite show in other uses of composite.

is primefaces or jsf bug, or missing something?

you might notice have commented out <inputtext> tag. it's worth mentioning when replace <selectonemenu> , replace <inputtext> no longer see problem.


i thought might elucidate bit on larger problem i'm trying solve.

i want create akin <p:layout> has both fixed elements (for uses of composite) , non-fixed elements/panels passed in parametrically (for each use of component).

here screenshot items indicated in read things vary each invocation of composite. else present in invocations of composite.

as can see, parameters are:

  1. a button panel (buttons vary depending on context)
  2. some additional fields add end of form (which might contain validations
  3. an entire lower panel (which might contain validations)

sample of composite

it's worth mentioning these things validated (for "save" buttons), it's desirable have <form> tag within composite output (which includes panels passed in parameters).

this problem two-fold.

first, <cc:renderfacet> never designed work way. does not support rendered attribute. somehow works because facet internally re-interpreted uipanel component , attributes (incorrectly) automatically inherited tag. should not rely on that. rendered attribute incorrectly considered during render response, causing confusing behavior "works". technically bug in jsf implementation. attributes (correctly) not inherited during postback, causing trouble observed. components still decoded , validated "in spite of" not rendered.

second, <p:inputtext> extends uiinput checks before validation if there's any submitted value. submitted value of null interpreted complete absence of input field in form, it's skipped. submitted value of empty string interpeted empty value, it's validated. <p:selectonemenu>, however, has overriden standard uiinput behavior , considers null same way empty string. when submitted value null (which means input field wasn't in form @ all), it's still being validated. technically bug in primefaces side.

your intent @ least clear: conditionally render facet. <cc:xxx> tags evaluated during facelets compile time (which step before view build time), conditionally building <cc:renderfacet> using jstl <c:if> not ever work.

your best bet redefining "render lower panel" composite attribute, , create backing component explicitly copy attribute facet after it's being added view.

<cc:interface componenttype="entitydetailpanelcomposite">     ...     <cc:facet name="lowerpanel" />     <cc:attribute name="renderlowerpanel" type="java.lang.boolean" default="false" /> </cc:interface> <cc:implementation>     <f:event type="postaddtoview" listener="#{cc.init}" />     ...     <cc:renderfacet name="lowerpanel" />     ... </cc:implementation> 

@facescomponent("entitydetailpanelcomposite") public class entitydetailpanelcomposite extends uinamingcontainer {      public void init() {         uicomponent lowerpanel = getfacets().get("lowerpanel");         valueexpression renderlowerpanel = getvalueexpression("renderlowerpanel");          if (renderlowerpanel != null) {             lowerpanel.setvalueexpression("rendered", renderlowerpanel); // it's el expression.         } else {             lowerpanel.getattributes().put("rendered", getattributes().get("renderlowerpanel")); // it's literal value, or default value.         }     }  } 

this has additional benefit can specify client on.

<my:entitydetailpanel ... renderlowerpanel="true" /> 

Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -