<f:ajax> Parent is not composite component or of type ClientBehaviorHolder on a selection one menu

雨燕双飞 提交于 2019-12-13 06:19:09

问题


I am trying to get a second selection method to show up depending on what was selected for the first value. Now i need to do this over 38 times for a form i am making but i want to see if i can get it working for one question first. Here is the code i have so far cut on the jsf page. The values are all the same for the other 38 questions. I just recreated the project and so far the bean is currently empty but i know i should be able to atleast see the form first which is what i am hoping to do for now before i add the values and code.

    <!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://java.sun.com/jsf/core" >

    <h:head>
    <title>QC-Form</title>

    </h:head>
    <h:body>
    <h1 class="title">QC Form</h1>
    <br/> <br/>

      <font face="comic sans MS" size="2" color="#33CCFF">
      <p><b>Enter the information below: </b> </p>
      </font>

    <h:form>

     <font face="comic sans MS" size="2"> 

     <b>Your initials: </b>  
        <h:inputText value="#{qcFormBean.techNameValue}"/><br/>
    <br/>

     <b>Model #: </b>  
    <h:selectOneMenu value="#{qcFormBean.modelValue}">
      <f:selectItem itemValue="3600" itemLabel="3600" />
      <f:selectItem itemValue="7200" itemLabel="7200" />
      <f:selectItem itemValue="8300" itemLabel="8300" />
      <f:selectItem itemValue="8400" itemLabel="8400" />
      <f:selectItem itemValue="8500p" itemLabel="8500p" />
      <f:selectItem itemValue="8800" itemLabel="8800" />
      <f:selectItem itemValue="9000" itemLabel="9000" />
      <f:selectItem itemValue="9008" itemLabel="9008" />
      <f:selectItem itemValue="9200" itemLabel="9200" />
      <f:selectItem itemValue="9300" itemLabel="9300" />
    </h:selectOneMenu><br/>
     <br/>

    <b>Date : </b>
     <h:outputText  value="#{currentDate}"/>
    <br/> <br/>


    <b>Serial #: </b>  
        <h:inputText value="#{qcFormBean.serialValue}"/><br/>
    <br/>

    <b>Customer Name: </b>  
        <h:inputText value="#{qcFormBean.customerNameValue}"/><br/>
    <br/>

    <b>Special Instructions: </b>  
        <h:inputText value="#{qcFormBean.specialInstructionsValue}"/><br/>    

    </font>

      <font face="comic sans MS" size="2" color="#33CCFF">
      <p><b>QC Process</b> </p>
      </font>

     <font face="comic sans MS" size="2"> 


     <b>1.Unit Serial number has been applied: </b>
     <h:selectOneMenu value="#{qcFormBean.unitSerialValue}">
      <f:selectItem itemValue="P" itemLabel="Pass or Not Applicable" />
      <f:selectItem itemValue="A" itemLabel="FAIL-Nonfunctional" />
      <f:selectItem itemValue="B" itemLabel="FAIL-Intermittent" />
      <f:selectItem itemValue="C" itemLabel="FAIL-Incorrect" />
      <f:selectItem itemValue="D" itemLabel="FAIL-DLI Standard" />
      <f:selectItem itemValue="F" itemLabel="FAIL-Special Standard" />
      <f:selectItem itemValue="G" itemLabel="FAIL-Physical" />
    </h:selectOneMenu>
    <br/>

    <br/>
    <b>2.Screen Protector has been applied: </b>
    <h:panelGroup id="dliSticker">
        <h:selectOneMenu value="#{qcFormBean.dlitcStickerValue}">
          <f:selectItem itemValue="P" itemLabel="Pass or Not applicable" />
          <f:selectItem itemValue="M" itemLabel="FAIL-Mechanical" />
          <f:selectItem itemValue="E" itemLabel="FAIL-Electrical" />
          <f:selectItem itemValue="C" itemLabel="FAIL-Cosmetic" />
          <f:selectItem itemValue="S" itemLabel="FAIL-Software" />
          <f:ajax event="change" execute="@this" render="perfbyDlitcSticker" />
        </h:selectOneMenu>
    </h:panelGroup>

    <h:panelGroup id="perfbyDlitcSticker">
        <h:selectOneMenu value="#{qcFormBean.stickerFreq}"
        rendered="#{!qcFormBean.dliStickerValue eq  'P'}">
            <f:selectItem itemValue="A" itemLabel="Always" />                
            <f:selectItem itemValue="O" itemLabel="Often" />
            <f:selectItem itemValue="S" itemLabel="Seldom" />                
        </h:selectOneMenu>
    </h:panelGroup>


    <br/>
    </font>

    </h:form>

    </h:body>
    </html>

Here is the error code i am getting with this code:

/indexv2.xhtml at line 88 and column 76 Parent is not composite component or of type ClientBehaviorHolder, type is: javax.faces.component.UIViewRoot@13fcf10

Caused by: javax.faces.view.facelets.TagException - /indexv2.xhtml at line 88 and column 76 Parent is not composite component or of type ClientBehaviorHolder, type is: javax.faces.component.UIViewRoot@13fcf10


回答1:


Remove the f:ajaxs outside of the h:selectOneMenu. h:form is no ClientBehaviourHolder so you can not place a f:ajax there. You just can put them into the h:selectOneMenu.


EDIT: Just remove the f:ajax without the parameters, those which wrap the panelGroups and keep the selectOneMenues:
<h:selectOneMenu value="#{qcFormBean.dlitcStickerValue}">
    <f:selectItem itemValue="P" itemLabel="Pass or Not applicable" />
    <f:selectItem itemValue="M" itemLabel="FAIL-Mechanical" />
    <f:selectItem itemValue="E" itemLabel="FAIL-Electrical" />
    <f:selectItem itemValue="C" itemLabel="FAIL-Cosmetic" />
    <f:selectItem itemValue="S" itemLabel="FAIL-Software" />
    <f:ajax event="change" execute="@this" render="perfbyDlitcSticker" />
</h:selectOneMenu>


EDIT2: Replace the code between </b> and the <br/> before the commandButton with the following code:
<h:panelGroup id="dliSticker">
    <h:selectOneMenu value="#{qcFormBean.dlitcStickerValue}">
      <f:selectItem itemValue="P" itemLabel="Pass or Not applicable" />
      <f:selectItem itemValue="M" itemLabel="FAIL-Mechanical" />
      <f:selectItem itemValue="E" itemLabel="FAIL-Electrical" />
      <f:selectItem itemValue="C" itemLabel="FAIL-Cosmetic" />
      <f:selectItem itemValue="S" itemLabel="FAIL-Software" />
      <f:ajax event="change" execute="@this" render="perfbyDlitcSticker" />
    </h:selectOneMenu>
</h:panelGroup>

<h:panelGroup id="perfbyDlitcSticker">
    <h:selectOneMenu value="#{qcFormBean.stickerFreq}"
    rendered="#{!qcFormBean.dliStickerValue eq  'P'}">
        <f:selectItem itemValue="A" itemLabel="Always" />                
        <f:selectItem itemValue="O" itemLabel="Often" />
        <f:selectItem itemValue="S" itemLabel="Seldom" />                
    </h:selectOneMenu>
</h:panelGroup>



回答2:


instead of using 'f:ajax' i used instead richfaces 'a4j:ajax' parameter for the xhtml and while now i have a different issue "The web page with the tags wont show up only text." so i can't really tell if i converted to richfaces correctly but here is what i change let me know if i am right or not thank you.

    <!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://java.sun.com/jsf/core" 
          xmlns:a4j="http://richfaces.org/a4j"   >

    <h:head>
    <title>QC-Form</title>
    <link href="./css/styles.css" 
          rel="stylesheet" type="text/css"/>
    </h:head>

    <f:view>

    <h:body>
    <h1 class="title">QC Form</h1>
    <br/> <br/>

      <font face="comic sans MS" size="2" color="#33CCFF">
      <p><b>Enter the information below: </b> </p>
      </font>

    <h:form>

     <font face="comic sans MS" size="2"> 

     <h:panelGroup id="initialInfo">

        <b>Your initials: </b>  
            <h:inputText value="#{qcFormBean.techNameValue}"/><br/>
        <br/>

        <b>Model #: </b>  
        <h:selectOneMenu value="#{qcFormBean.modelValue}">
          <f:selectItem itemValue="3600" itemLabel="3600" />
          <f:selectItem itemValue="7200" itemLabel="7200" />
          <f:selectItem itemValue="8300" itemLabel="8300" />
          <f:selectItem itemValue="8400" itemLabel="8400" />
          <f:selectItem itemValue="8500p" itemLabel="8500p" />
          <f:selectItem itemValue="8800" itemLabel="8800" />
          <f:selectItem itemValue="9000" itemLabel="9000" />
          <f:selectItem itemValue="9008" itemLabel="9008" />
          <f:selectItem itemValue="9200" itemLabel="9200" />
          <f:selectItem itemValue="9300" itemLabel="9300" />
        </h:selectOneMenu><br/>
         <br/>

        <b>Date : </b>
         <h:outputText  value="#{currentDate}"/>
        <br/> <br/>


        <b>Serial #: </b>  
            <h:inputText value="#{qcFormBean.serialValue}"/><br/>
        <br/>

        <b>Customer Name: </b>  
            <h:inputText value="#{qcFormBean.customerNameValue}"/><br/>
        <br/>

        <b>Special Instructions: </b>  
            <h:inputText value="#{qcFormBean.specialInstructionsValue}"/><br/>    

     </h:panelGroup>
    </font>

      <font face="comic sans MS" size="2" color="#33CCFF">
      <p><b>QC Process</b> </p>
      </font>

     <font face="comic sans MS" size="2"> 

    <h:panelGroup id="dliSerial">
     <b>1.Unit Serial number has been applied: </b>
     <h:selectOneMenu value="#{qcFormBean.unitSerialValue}">
    <f:selectItems value="#{qcFormBean.valueQcValue}"/>
    </h:selectOneMenu>
    <br/>

    </h:panelGroup>

    <br/>
    <b>2.Screen Protector has been applied: </b>
    <h:panelGroup id="dliSticker">
        <h:selectOneMenu value="#{qcFormBean.dliStickerValue}">
          <f:selectItem itemValue="P" itemLabel="Pass or Not applicable" />
          <f:selectItem itemValue="M" itemLabel="FAIL-Mechanical" />
          <f:selectItem itemValue="E" itemLabel="FAIL-Electrical" />
          <f:selectItem itemValue="C" itemLabel="FAIL-Cosmetic" />
          <f:selectItem itemValue="S" itemLabel="FAIL-Software" />
          <a4j:ajax event="change" execute="@this" render="perfbyDliSticker"  limitRender="true" />
        </h:selectOneMenu>
    </h:panelGroup>

    <h:panelGroup id="perfbyDlitcSticker">
        <h:selectOneMenu value="#{qcFormBean.stickerFreq}"
        rendered="#{!qcFormBean.dliStickerValue eq  'P'}">
            <f:selectItem itemValue="A" itemLabel="Always" />                
            <f:selectItem itemValue="O" itemLabel="Often" />
            <f:selectItem itemValue="S" itemLabel="Seldom" />                
        </h:selectOneMenu>
    </h:panelGroup>


    <br/>
    </font>



    </h:form>

    </h:body>
    </f:view>
    </html>


来源:https://stackoverflow.com/questions/21606597/fajax-parent-is-not-composite-component-or-of-type-clientbehaviorholder-on-a

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!