You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by hn...@apache.org on 2020/04/15 10:19:00 UTC

[myfaces-tobago] branch master updated: create demo for f:ajax and tc:event

This is an automated email from the ASF dual-hosted git repository.

hnoeth pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git


The following commit(s) were added to refs/heads/master by this push:
     new bf541c3  create demo for f:ajax and tc:event
bf541c3 is described below

commit bf541c3256c7e71bae17436bd8b3fe25d14e3b95
Author: JasminKroeger <ja...@web.de>
AuthorDate: Wed Apr 15 12:18:52 2020 +0200

    create demo for f:ajax and tc:event
    
    * this example show how to use f:ajax and tc:event together inside a button
    * the ajax event is called with a click and the event with a double click
    
    Issue: TOBAGO-1695
    
    Co-authored-by: Jasmin Kroeger <ja...@irian.eu>
---
 .../tobago/example/demo/BehaviorController.java       | 19 +++++++++++++++++++
 .../content/30-concept/30-behavior/Behavior.xhtml     | 16 ++++++++++++++++
 2 files changed, 35 insertions(+)

diff --git a/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/BehaviorController.java b/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/BehaviorController.java
index f581886..94bf065 100644
--- a/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/BehaviorController.java
+++ b/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/BehaviorController.java
@@ -37,6 +37,7 @@ public class BehaviorController implements Serializable {
 
   private String ajax;
   private String event;
+  private String output;
   private int counter;
 
   public String getAjax() {
@@ -59,6 +60,14 @@ public class BehaviorController implements Serializable {
     return counter;
   }
 
+  public String getOutput() {
+    return output;
+  }
+
+  public void setOutput(String output) {
+    this.output = output;
+  }
+
   public void countUp(final AjaxBehaviorEvent ajaxBehaviorEvent) {
     LOG.info("ajaxBehaviorEvent=" + ajaxBehaviorEvent);
     counter++;
@@ -68,4 +77,14 @@ public class BehaviorController implements Serializable {
     LOG.info("actionEvent=" + actionEvent);
     counter++;
   }
+
+  public void eventOutput(final AjaxBehaviorEvent ajaxBehaviorEvent) {
+    LOG.info("ajaxBehaviorEvent=" + ajaxBehaviorEvent);
+    this.output = "Ajax";
+  }
+
+  public void eventOutput(final ActionEvent actionEvent) {
+    LOG.info("actionEvent=" + actionEvent);
+    this.output = "Event";
+  }
 }
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/30-concept/30-behavior/Behavior.xhtml b/tobago-example/tobago-example-demo/src/main/webapp/content/30-concept/30-behavior/Behavior.xhtml
index 41318fd..41efee3 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/content/30-concept/30-behavior/Behavior.xhtml
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/30-concept/30-behavior/Behavior.xhtml
@@ -96,5 +96,21 @@
   &lt;/tc:event>
 &lt;/tc:row></code></pre>
     </tc:section>
+
+    <tc:section label="f:ajax and tc:event">
+      <p>This is an example to show how <code class="language-markup">&lt;f:ajax/></code> and <code
+              class="language-markup">&lt;tc:event/></code> can be used together.
+        The ajax event is called with a click and the event with a double click.</p>
+      <pre><code class="language-markup">&lt;tc:button id="btnAjaxEvent" label="Submit" type="submit">
+  &lt;f:ajax event="click" render="out" listener="\#{behaviorController.eventOutput}"/>
+  &lt;tc:event event="dblclick" actionListener="\#{behaviorController.eventOutput}"/>
+&lt;/tc:button>
+&lt;tc:out id="out" label="Output:" value="\#{behaviorController.output}"/></code></pre>
+      <tc:button id="btnAjaxEvent" label="Submit" type="submit">
+        <f:ajax event="click" render="out" listener="#{behaviorController.eventOutput}"/>
+        <tc:event event="dblclick" actionListener="#{behaviorController.eventOutput}"/>
+      </tc:button>
+      <tc:out id="out" label="Output:" value="#{behaviorController.output}"/>
+    </tc:section>
   </tc:section>
 </ui:composition>