Content Box <tc:box>

On this page the collapsible concept is explained for a Content Box.

Simple Collapsible Box

This is a simple collapsible box which open and close the content via a controller.

<tc:button label="show" immediate="true"
        action="#{collapsibleBoxController.showCollapsed1}"/>

Box

Content

Full Server Request

In this example, the operaction tag is used to change the state of the boxes.

<tc:box id="box1" label="Full Request Box 1" collapsedMode="absent">
  <f:facet name="bar">
    <tc:buttons>
      <tc:button label="show">
        <tc:operation name="show" for="box1"/>
      ...

Full Request Box 1

Content

Full Request Box 2

Content

Client Side

This example show a content box which could be opened and closed without a server request.
To render the hidden content of the box, collapsedMode="hidden" must be set. The content is hidden by CSS display property.

Also the content contain a required inputfield. This field will be also validated if the content is hidden.
To demonstrate that, leave the inputfield blank, hide the content and press the 'Submit'-button.

Notice the omit attribute of the buttons is set to avoid server request.

<tc:box id="noRequestBox" label="No Request Box"
        collapsed="true" collapsedMode="hidden">
  <tc:button label="show" omit="true">
    <tc:operation name="show" for="noRequestBox"/>
  ...

No Request Box

Ajax

Here we have the transitions show and hide with AJAX request. The buttons have set omit="false" which is the default. Also the attribute immediate="true" is set to execute the transition without validation.

The mode is set to collapsedMode="absent" (default), so the hidden content won't be rendered and therefor not validated.

You can press the 'Submit'-button after hiding the blank inputfield. The submit will be executed without validation. If the content is shown and the field is empty, a violation occurs after hitting 'Submit'.

<tc:box id="ajaxBox" label="Collapsible Box (AJAX)" collapsedMode="absent">
  ...
    <tc:button label="show" immediate="true">
      <f:ajax execute="ajaxBox" render="ajaxBox"/>
      <tc:operation name="show" for="ajaxBox"/>
    ...

Ajax Box

<?xml version="1.0" encoding="UTF-8"?> <!-- * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. --> <ui:composition template="/main.xhtml" xmlns="http://www.w3.org/1999/xhtml" xmlns:tc="http://myfaces.apache.org/tobago/component" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core"> <ui:param name="title" value="#{demoBundle.collapsible_box} &lt;tc:box>"/> <p>On this page the collapsible concept is explained for a <tc:link label="#{demoBundle.box}" outcome="/content/20-component/050-container/10-box/box.xhtml"/>.</p> <tc:section label="Simple Collapsible Box"> <tc:form id="controller"> <p>This is a simple collapsible box which open and close the content via a controller.</p> <pre><code class="language-markup">&lt;tc:button label="show" immediate="true" action="\#{collapsibleBoxController.showCollapsed1}"/></code></pre> <tc:box label="Box" collapsed="#{collapsibleBoxController.collapsed}" collapsedMode="absent"> <f:facet name="bar"> <tc:buttons> <tc:button id="show" label="show" immediate="true" action="#{collapsibleBoxController.show}"/> <tc:button id="hide" label="hide" immediate="true" action="#{collapsibleBoxController.hide}"/> </tc:buttons> </f:facet> <tc:out id="content" value="Content"/> </tc:box> </tc:form> </tc:section> <tc:section label="Full Server Request"> <tc:form id="server"> <p>In this example, the operaction tag is used to change the state of the boxes.</p> <pre><code class="language-markup">&lt;tc:box id="box1" label="Full Request Box 1" collapsedMode="absent"> &lt;f:facet name="bar"> &lt;tc:buttons> &lt;tc:button label="show"> &lt;tc:operation name="show" for="box1"/> ...</code></pre> <tc:box id="box1" label="Full Request Box 1" collapsedMode="absent"> <f:facet name="bar"> <tc:buttons> <tc:button id="show1" label="show"> <tc:operation name="show" for="box1"/> </tc:button> <tc:button id="hide1" label="hide"> <tc:operation name="hide" for="box1"/> </tc:button> </tc:buttons> </f:facet> <tc:out id="content1" value="Content"/> </tc:box> <tc:box id="box2" label="Full Request Box 2" collapsedMode="absent"> <f:facet name="bar"> <tc:buttons> <tc:button id="show2" label="show"> <tc:operation name="show" for="box2"/> </tc:button> <tc:button id="hide2" label="hide"> <tc:operation name="hide" for="box2"/> </tc:button> </tc:buttons> </f:facet> <tc:out id="content2" value="Content"/> </tc:box> </tc:form> </tc:section> <tc:section label="Client Side"> <tc:form id="client"> <p>This example show a content box which could be opened and closed without a server request.<br/> To render the hidden content of the box, <code>collapsedMode="hidden"</code> must be set. The content is hidden by CSS display property.</p> <p>Also the content contain a required inputfield. This field will be also validated if the content is hidden.<br/> To demonstrate that, leave the inputfield blank, hide the content and press the 'Submit'-button.</p> <p>Notice the <code>omit</code> attribute of the buttons is set to avoid server request.</p> <pre><code class="language-markup">&lt;tc:box id="noRequestBox" label="No Request Box" collapsed="true" collapsedMode="hidden"> &lt;tc:button label="show" omit="true"> &lt;tc:operation name="show" for="noRequestBox"/> ...</code></pre> <tc:box id="noRequestBox" label="No Request Box" collapsed="true" collapsedMode="hidden"> <f:facet name="bar"> <tc:buttons> <tc:button id="showNoRequestBox" label="show" omit="true"> <tc:operation name="show" for="noRequestBox"/> </tc:button> <tc:button id="hideNoRequestBox" label="hide" omit="true"> <tc:operation name="hide" for="noRequestBox"/> </tc:button> </tc:buttons> </f:facet> <tc:in id="inNoRequestBox" label="Required" required="true"/> </tc:box> <tc:button id="submitNoRequestBox" label="Submit"/> </tc:form> </tc:section> <tc:section label="Ajax"> <tc:form id="ajax"> <p>Here we have the transitions <code>show</code> and <code>hide</code> with AJAX request. The buttons have set <code>omit="false"</code> which is the default. Also the attribute <code>immediate="true"</code> is set to execute the transition without validation.</p> <p>The mode is set to <code>collapsedMode="absent"</code> (default), so the hidden content won't be rendered and therefor not validated.</p> <p>You can press the 'Submit'-button after hiding the blank inputfield. The submit will be executed without validation. If the content is shown and the field is empty, a violation occurs after hitting 'Submit'.</p> <pre><code class="language-markup">&lt;tc:box id="ajaxBox" label="Collapsible Box (AJAX)" collapsedMode="absent"> ... &lt;tc:button label="show" immediate="true"> &lt;f:ajax execute="ajaxBox" render="ajaxBox"/> &lt;tc:operation name="show" for="ajaxBox"/> ...</code></pre> <tc:box id="ajaxBox" label="Ajax Box" collapsedMode="absent"> <f:facet name="bar"> <tc:buttons> <tc:button id="showAjaxBox" label="show" immediate="true"> <f:ajax execute="ajaxBox" render="ajaxBox"/> <tc:operation name="show" for="ajaxBox"/> </tc:button> <tc:button id="hideAjaxBox" label="hide" immediate="true"> <f:ajax execute="ajaxBox" render="ajaxBox"/> <tc:operation name="hide" for="ajaxBox"/> </tc:button> </tc:buttons> </f:facet> <tc:in id="inAjaxBox" label="Required" required="true"/> </tc:box> <tc:button id="submitAjaxBox" label="Submit"/> </tc:form> </tc:section> </ui:composition>