Behavior

There are two kinds of behaviors:

  • <f:ajax/> send an ajax request
  • <tc:event/> do a full page reload

Tag Library Documentation: <f:ajax/> | <tc:event/>

Basic examples

Type a text into the input field. After leaving the input field, the given text is shown in the output field.

f:ajax

<tc:in label="Ajax Input" value="#{behaviorController.ajax}">
  <f:ajax render="outAjax"/>
</tc:in>

tc:event

<tc:in label="Event Input" value="#{behaviorController.event}">
  <tc:event/>
</tc:in>

Change the event name

It's possible to change the event name. For example if you want a double click event, change the event name to dblclick. This is done for the following two buttons.

<tc:button label="Ajax Double Click">
  <f:ajax event="dblclick" render="outCounter" listener="..."/>
</tc:button>
<tc:button label="Event Double Click">
  <tc:event event="dblclick" actionListener="..."/>
</tc:button>
0

Advanced

<tc:event> may contain <f:ajax> and <tc:operation> tags.

This is helpfull if the parent component cannot handle operations by itself.

Important The event attribute of the ajax children will be ignored.

Example

An example can be found for <tc:row> Option: 'open popup on click with AJAX'.

<tc:row>
  <tc:event>
    <f:ajax execute=":::popup" render=":::popup" listener="..."/>
    <tc:operation name="show" for=":::popup"/>
  </tc:event>
</tc:row>
<?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:f="http://java.sun.com/jsf/core" xmlns:tc="http://myfaces.apache.org/tobago/component" xmlns:ui="http://java.sun.com/jsf/facelets"> <ui:param name="title" value="#{demoBundle.behavior}"/> <p>There are two kinds of behaviors: </p> <ul> <li><code class="language-markup">&lt;f:ajax/></code> send an ajax request</li> <li><code class="language-markup">&lt;tc:event/></code> do a full page reload</li> </ul> <p>Tag Library Documentation: <tc:link label="&lt;f:ajax/>" image="#{request.contextPath}/image/feather-leaf.png" link="http://docs.oracle.com/javaee/6/javaserverfaces/2.1/docs/vdldocs/facelets/f/ajax.html"/> | <tc:link label="&lt;tc:event/>" image="#{request.contextPath}/image/feather-leaf.png" link="#{demoBundle.tagDocUrl}/#{apiController.currentRelease}/tld/tc/event.html"/></p> <tc:section label="Basic examples"> <p>Type a text into the input field. After leaving the input field, the given text is shown in the output field.</p> <tc:section label="f:ajax"> <pre><code class="language-markup">&lt;tc:in label="Ajax Input" value="\#{behaviorController.ajax}"> &lt;f:ajax render="outAjax"/> &lt;/tc:in></code></pre> <tc:in label="Ajax Input" value="#{behaviorController.ajax}"> <f:ajax render="outAjax"/> </tc:in> <tc:out id="outAjax" label="Ajax Output" value="#{behaviorController.ajax}"/> </tc:section> <tc:section label="tc:event"> <pre><code class="language-markup">&lt;tc:in label="Event Input" value="\#{behaviorController.event}"> &lt;tc:event/> &lt;/tc:in></code></pre> <tc:in label="Event Input" value="#{behaviorController.event}"> <tc:event/> </tc:in> <tc:out label="Event Output" value="#{behaviorController.event}"/> </tc:section> </tc:section> <tc:section label="Change the event name"> <p>It's possible to change the event name. For example if you want a double click event, change the event name to <code>dblclick</code>. This is done for the following two buttons.</p> <pre><code class="language-markup">&lt;tc:button label="Ajax Double Click"> &lt;f:ajax event="dblclick" render="outCounter" listener="..."/> &lt;/tc:button> &lt;tc:button label="Event Double Click"> &lt;tc:event event="dblclick" actionListener="..."/> &lt;/tc:button></code></pre> <tc:button label="Ajax Double Click"> <f:ajax event="dblclick" render="outCounter" listener="#{behaviorController.countUp}"/> </tc:button> <tc:button label="Event Double Click"> <tc:event event="dblclick" actionListener="#{behaviorController.countUp}"/> </tc:button> <tc:out id="outCounter" label="Counter" value="#{behaviorController.counter}"/> </tc:section> <tc:section label="Advanced"> <p><code class="language-markup">&lt;tc:event></code> may contain <code class="language-markup">&lt;f:ajax></code> and <code class="language-markup">&lt;tc:operation></code> tags.</p> <p>This is helpfull if the parent component cannot handle operations by itself.</p> <p><tc:badge value="Important" markup="danger"/> The <code>event</code> attribute of the ajax children will be ignored.</p> <tc:section label="Example"> <p>An example can be found for <tc:link label="&lt;tc:row>" outcome="/content/20-component/080-sheet/30-event/sheet-event.xhtml"/> Option: 'open popup on click with AJAX'.</p> <pre><code class="language-markup">&lt;tc:row> &lt;tc:event> &lt;f:ajax execute=":::popup" render=":::popup" listener="..."/> &lt;tc:operation name="show" for=":::popup"/> &lt;/tc:event> &lt;/tc:row></code></pre> </tc:section> </tc:section> </ui:composition>