You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2016/08/15 13:37:23 UTC

svn commit: r1756384 - in /myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main: java/org/apache/myfaces/tobago/example/demo/GroupController.java webapp/content/20-component/010-input/50-input-group/group.xhtml

Author: lofwyr
Date: Mon Aug 15 13:37:23 2016
New Revision: 1756384

URL: http://svn.apache.org/viewvc?rev=1756384&view=rev
Log:
TOBAGO-1574: AJAX not working from change-facet-command 
* test

Modified:
    myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/GroupController.java
    myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/010-input/50-input-group/group.xhtml

Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/GroupController.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/GroupController.java?rev=1756384&r1=1756383&r2=1756384&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/GroupController.java (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/GroupController.java Mon Aug 15 13:37:23 2016
@@ -20,24 +20,43 @@
 package org.apache.myfaces.tobago.example.demo;
 
 import org.apache.myfaces.tobago.component.UICommand;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import javax.enterprise.context.SessionScoped;
-import javax.faces.event.ActionEvent;
+import javax.faces.event.AjaxBehaviorEvent;
 import javax.inject.Named;
 import java.io.Serializable;
+import java.util.Currency;
 
 @SessionScoped
 @Named
 public class GroupController implements Serializable {
 
+  private static final Logger LOG = LoggerFactory.getLogger(GroupController.class);
+
   private String chatlog;
   private String newMessage;
   private String sendTo;
+  private double value;
+  private double valueInEuro;
+  private Currency currency;
+  private static final Currency[] currencies;
+
+  static {
+    currencies = new Currency[]{
+        Currency.getInstance("JPY"),
+        Currency.getInstance("TTD"),
+        Currency.getInstance("USD"),
+        Currency.getInstance("EUR")};
+  }
 
   public GroupController() {
     chatlog = "Peter: Hi, how are you?";
     newMessage = "I'm fine.";
     sendTo = "";
+    value = 1000.0;
+    currency = Currency.getInstance("EUR");
   }
 
   public String getChatlog() {
@@ -65,10 +84,58 @@ public class GroupController implements
     this.sendTo = sendTo;
   }
 
-  public void sendToListener(ActionEvent actionEvent) {
-    if (actionEvent != null && actionEvent.getComponent() instanceof UICommand) {
-      UICommand command = (UICommand) actionEvent.getComponent();
+  public void sendToListener(AjaxBehaviorEvent event) {
+
+    LOG.info("AjaxBehaviorEvent called.");
+
+    if (event != null && event.getComponent() instanceof UICommand) {
+      UICommand command = (UICommand) event.getComponent();
       sendTo = command.getLabel();
+      LOG.info("AjaxBehaviorEvent called. Current label: '{}'", sendTo);
+    }
+  }
+
+  public void compute(AjaxBehaviorEvent event) {
+    LOG.info("AjaxBehaviorEvent called.");
+    compute();
+  }
+
+  private void compute() {
+    if (currency.getCurrencyCode().equals("JPY")) {
+      valueInEuro = value * 0.00884806667;
+    } else if (currency.getCurrencyCode().equals("TTD")) {
+      valueInEuro = value * 0.133748824;
+    } else if (currency.getCurrencyCode().equals("USD")) {
+      valueInEuro = value * 0.896097495;
+    } else if (currency.getCurrencyCode().equals("EUR")) {
+      valueInEuro = value;
+    } else {
+      valueInEuro = 0;
     }
+    LOG.info("euro value: '{}', value: '{}', currency: '{}'", valueInEuro, value, currency.getCurrencyCode());
+  }
+
+  public double getValue() {
+    return value;
+  }
+
+  public void setValue(double value) {
+    this.value = value;
+  }
+
+  public double getValueInEuro() {
+    return valueInEuro;
+  }
+
+  public Currency getCurrency() {
+    return currency;
+  }
+
+  public void setCurrency(Currency currency) {
+    this.currency = currency;
+  }
+
+  public Currency[] getCurrencies() {
+    return currencies;
   }
 }

Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/010-input/50-input-group/group.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/010-input/50-input-group/group.xhtml?rev=1756384&r1=1756383&r2=1756384&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/010-input/50-input-group/group.xhtml (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/010-input/50-input-group/group.xhtml Mon Aug 15 13:37:23 2016
@@ -66,7 +66,7 @@
       <f:facet name="before">User Two</f:facet>
       <f:facet name="after">
         <tc:button label="Send" action="#{groupController.sendChat}">
-          <f:ajax execute="inewmessage" render="tachatlog"/>
+          <f:ajax execute="inewmessage" render="tachatlog inewmessage"/>
         </tc:button>
       </f:facet>
     </tc:in>
@@ -92,14 +92,14 @@
       <tc:in id="isendtoc" placeholder="type a message">
         <f:facet name="before">
           <tc:button id="lsendtoc" label="#{groupController.sendTo}" omit="true">
-            <tc:command label="SendTo: Peter" actionListener="#{groupController.sendToListener}">
-              <f:ajax render="isendtoc" execute="isendtoc"/>
+            <tc:command label="SendTo: Peter">
+              <f:ajax render="isendtoc" execute="isendtoc" listener="#{groupController.sendToListener}"/>
             </tc:command>
-            <tc:command label="SendTo: Bob" actionListener="#{groupController.sendToListener}">
-              <f:ajax render="isendtoc" execute="isendtoc"/>
+            <tc:command label="SendTo: Bob">
+              <f:ajax render="isendtoc" execute="isendtoc" listener="#{groupController.sendToListener}"/>
             </tc:command>
-            <tc:command label="SendTo: All" actionListener="#{groupController.sendToListener}">
-              <f:ajax render="isendtoc" execute="isendtoc"/>
+            <tc:command label="SendTo: All">
+              <f:ajax render="isendtoc" execute="isendtoc" listener="#{groupController.sendToListener}"/>
             </tc:command>
           </tc:button>
         </f:facet>
@@ -109,8 +109,8 @@
     <tc:section label="Radio Buttons">
       <pre><code class="language-markup">&lt;tc:in id="isendtorb" placeholder="type a message">
   &lt;f:facet name="before">
-    &lt;tc:button id="lsendtorb" label="#{groupController.sendTo}" omit="true">
-      &lt;tc:selectOneRadio value="#{groupController.sendTo}">
+    &lt;tc:button id="lsendtorb" label="\#{groupController.sendTo}" omit="true">
+      &lt;tc:selectOneRadio value="\#{groupController.sendTo}">
         &lt;tc:selectItem itemValue="SendTo: Peter"/>
         ...
         &lt;f:ajax render="isendtorb"/>
@@ -132,5 +132,22 @@
         </f:facet>
       </tc:in>
     </tc:section>
+
+    <tc:section label="Choice">
+      <tc:in id="value" placeholder="type an amount" value="#{groupController.value}">
+        <f:convertNumber maxFractionDigits="2" minFractionDigits="2"/>
+        <f:facet name="after">
+          <tc:selectOneChoice value="#{groupController.currency}">
+            <f:selectItems value="#{groupController.currencies}" var="currency"
+                           itemValue="#{currency}" itemLabel="#{currency.displayName}"/>
+            <f:ajax listener="#{groupController.compute}" render="valueInEuro" execute="value"/>
+          </tc:selectOneChoice>
+        </f:facet>
+      </tc:in>
+      <tc:out id="valueInEuro" label="Demo value in €" value="#{groupController.valueInEuro}">
+        <f:convertNumber maxFractionDigits="2" minFractionDigits="2" currencySymbol="€"/>
+      </tc:out>
+    </tc:section>
+
   </tc:section>
 </ui:composition>