View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.example.demo;
21  
22  import org.slf4j.Logger;
23  import org.slf4j.LoggerFactory;
24  
25  import javax.enterprise.context.SessionScoped;
26  import javax.faces.event.ActionEvent;
27  import javax.faces.event.AjaxBehaviorEvent;
28  import javax.inject.Named;
29  import java.io.Serializable;
30  import java.lang.invoke.MethodHandles;
31  
32  @SessionScoped
33  @Named
34  public class BehaviorController implements Serializable {
35  
36    private static final Logger LOG = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
37  
38    private String ajax;
39    private String event;
40    private String output;
41    private int counter;
42  
43    public String getAjax() {
44      return ajax;
45    }
46  
47    public void setAjax(final String ajax) {
48      this.ajax = ajax;
49    }
50  
51    public String getEvent() {
52      return event;
53    }
54  
55    public void setEvent(final String event) {
56      this.event = event;
57    }
58  
59    public int getCounter() {
60      return counter;
61    }
62  
63    public String getOutput() {
64      return output;
65    }
66  
67    public void setOutput(String output) {
68      this.output = output;
69    }
70  
71    public void countUp(final AjaxBehaviorEvent ajaxBehaviorEvent) {
72      LOG.info("ajaxBehaviorEvent=" + ajaxBehaviorEvent);
73      counter++;
74    }
75  
76    public void countUp(final ActionEvent actionEvent) {
77      LOG.info("actionEvent=" + actionEvent);
78      counter++;
79    }
80  
81    public void eventOutput(final AjaxBehaviorEvent ajaxBehaviorEvent) {
82      LOG.info("ajaxBehaviorEvent=" + ajaxBehaviorEvent);
83      this.output = "Ajax";
84    }
85  
86    public void eventOutput(final ActionEvent actionEvent) {
87      LOG.info("actionEvent=" + actionEvent);
88      this.output = "Event";
89    }
90  }