blob: 10f5ccb148827a087e22f5f3b4a1df0eb1f1cba3 [file] [log] [blame]
<?xml version="1.0"?>
<!--
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.
-->
<!-- This file is similar to form1_template_action.xml. They differ in group layout,
form's action attribute (to use continuations) and, this one is a dynamic form
template that changes the 'contacts' repeater layout depending on its size -->
<page xmlns:ft="http://apache.org/cocoon/forms/1.0#template"
xmlns:fi="http://apache.org/cocoon/forms/1.0#instance"
xmlns:jx="http://apache.org/cocoon/templates/jx/1.0">
<!-- Import the macros that define CForms template elements -->
<jx:import uri="resource://org/apache/cocoon/forms/generation/jx-macros.xml"/>
<title>Dynamic template</title>
<style type="text/css">
/* Additional styles for alternating row colors */
.forms-row-0 td {
padding: 5px;
background-color: #E0E0E0;
}
.forms-row-1 td {
padding: 5px;
}
</style>
<content>
<ft:form-template action="#{$cocoon/continuation/id}.continue" method="POST">
<p>This is an example of how dynamic templates (using the JX macros) allow to change the
page structure depending on the form contents. By adding or removing rows in the repeater
below you will see:</p>
<ul>
<li>when there are no contacts, only the "Add contact" button is displayed and the table isn't shown,</li>
<li>when there are some contacts, the "move up" and "move down" buttons are not shown on the first and last lines, respectively.</li>
</ul>
<jx:choose>
<jx:when test="${form.getChild('contacts').getSize() == 0}">
<p><strong><em>There are no contacts to display</em></strong></p>
</jx:when>
<jx:otherwise>
<table border="1">
<tr>
<th><ft:repeater-widget-label id="contacts" widget-id="firstname"/></th>
<th><ft:repeater-widget-label id="contacts" widget-id="lastname"/></th>
<th><ft:repeater-widget-label id="contacts" widget-id="ID"/></th>
<th><ft:repeater-widget-label id="contacts" widget-id="select"/></th>
</tr>
<!-- The contents of the repeater-widget element is a template that will
be applied to each row in the repeater. -->
<ft:repeater-widget id="contacts">
<tr class="forms-row-${repeaterLoop.index % 2}">
<td><ft:widget id="firstname"/></td>
<td><ft:widget id="lastname"/></td>
<td><ft:widget id="ID"/></td>
<td>
<!-- Don't display the "move up" button on the first row -->
<jx:choose>
<jx:when test="${repeaterLoop.first}">
<img src="resources/forms/img/blank_btn.gif"/>
</jx:when>
<jx:otherwise>
<ft:widget id="up">
<fi:styling type="image" src="resources/forms/img/move_up.gif"/>
</ft:widget>
</jx:otherwise>
</jx:choose>
<!-- Don't display the "move down" button on the first row -->
<jx:choose>
<jx:when test="${repeaterLoop.last}">
<img src="resources/forms/img/blank_btn.gif"/>
</jx:when>
<jx:otherwise>
<ft:widget id="down">
<fi:styling type="image" src="resources/forms/img/move_down.gif"/>
</ft:widget>
</jx:otherwise>
</jx:choose>
<ft:widget id="select"/>
</td>
</tr>
</ft:repeater-widget>
</table>
</jx:otherwise>
</jx:choose>
<p>
<ft:widget id="addcontact"/>
<jx:if test="${widget.getChild('contacts').getSize() > 0}">
<ft:widget id="removecontacts"/>
</jx:if>
</p>
<ft:widget id="submit"/><br/>
<a href="./do-dynaRepeater.flow">Restart this sample</a> - <a href="./">Back to samples</a>
</ft:form-template>
</content>
</page>