001    package org.apache.myfaces.tobago.example.reference;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one or more
005     * contributor license agreements.  See the NOTICE file distributed with
006     * this work for additional information regarding copyright ownership.
007     * The ASF licenses this file to You under the Apache License, Version 2.0
008     * (the "License"); you may not use this file except in compliance with
009     * the License.  You may obtain a copy of the License at
010     *
011     *      http://www.apache.org/licenses/LICENSE-2.0
012     *
013     * Unless required by applicable law or agreed to in writing, software
014     * distributed under the License is distributed on an "AS IS" BASIS,
015     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016     * See the License for the specific language governing permissions and
017     * limitations under the License.
018     */
019    
020    import org.apache.commons.logging.Log;
021    import org.apache.commons.logging.LogFactory;
022    
023    import org.apache.myfaces.tobago.example.demo.Navigation;
024    
025    import javax.faces.context.FacesContext;
026    import javax.faces.el.VariableResolver;
027    import java.util.Date;
028    
029    public class PartialReloadController {
030    
031      private static final Log LOG = LogFactory.getLog(PartialReloadController.class);
032    
033      private String navigateAction;
034    
035      public Date getCurrentDate() {
036        return new Date();
037      }
038    
039      public String leftAction() {
040        return logAndNavigate(null);
041      }
042    
043      public String rightAction() {
044        return logAndNavigate(null);
045      }
046    
047      public String navigateAction() {
048        FacesContext facesContext = FacesContext.getCurrentInstance();
049        VariableResolver resolver = facesContext.getApplication().getVariableResolver();
050        Navigation navigation = (Navigation) resolver.resolveVariable(facesContext, "navigation");
051        LOG.info("navigateAction = \"" + navigateAction + "\"");
052        if (navigateAction == null) {
053          return logAndNavigate(null);
054        } else if ("both".equals(navigateAction)) {
055          navigateAction = null;
056          return logAndNavigate(null);
057        } else if ("prev".equals(navigateAction)) {
058          navigateAction = null;
059          return logAndNavigate(navigation.gotoPrevious());
060        } else if ("next".equals(navigateAction)) {
061          navigateAction = null;
062          return logAndNavigate(navigation.gotoNext());
063        }
064        return logAndNavigate(null);
065      }
066    
067      private String logAndNavigate(String navValue) {
068        LOG.info("Return navigate value: " + navValue + "");
069        return navValue;
070      }
071    
072    
073      public String getNavigateAction() {
074        return navigateAction;
075      }
076    
077      public void setNavigateAction(String navigateAction) {
078        this.navigateAction = navigateAction;
079      }
080    }