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.util;
21  
22  
23  import org.apache.myfaces.tobago.component.Attributes;
24  import org.apache.myfaces.tobago.component.Facets;
25  import org.apache.myfaces.tobago.internal.util.FacesContextUtils;
26  import org.slf4j.Logger;
27  import org.slf4j.LoggerFactory;
28  
29  import javax.faces.component.UIComponent;
30  import javax.faces.context.FacesContext;
31  import javax.faces.event.PhaseId;
32  import javax.portlet.PortletResponse;
33  import javax.servlet.http.HttpServletResponse;
34  
35  public class ApplyRequestValuesCallback implements TobagoCallback {
36  
37    @SuppressWarnings("UnusedDeclaration")
38    private static final Logger LOG = LoggerFactory.getLogger(ApplyRequestValuesCallback.class);
39  
40    public void invokeContextCallback(final FacesContext context, final UIComponent component) {
41      if (FacesContextUtils.isAjax(context)) {
42        final String ajaxId = FacesContextUtils.getAjaxComponentId(context);
43        final UIComponent reload = component.getFacet(Facets.RELOAD);
44        if (ajaxId != null && ajaxId.equals(component.getClientId(context)) && reload != null && reload.isRendered()
45            && ajaxId.equals(FacesContextUtils.getActionId(context))) {
46          final Boolean immediate = (Boolean) reload.getAttributes().get(Attributes.IMMEDIATE);
47          if (immediate != null && immediate) {
48            final Boolean update = (Boolean) reload.getAttributes().get(Attributes.UPDATE);
49            if (update != null && !update) {
50              final Object response = context.getExternalContext().getResponse();
51              if (response instanceof HttpServletResponse) {
52                ((HttpServletResponse) response).setStatus(HttpServletResponse.SC_NOT_MODIFIED);
53              } else if (response instanceof PortletResponse) {
54                // TBD: Portlet: what is to do here?
55              }
56              context.responseComplete();
57              return;
58            }
59          }
60        }
61      }
62      component.processDecodes(context);
63    }
64  
65    public PhaseId getPhaseId() {
66      return PhaseId.APPLY_REQUEST_VALUES;
67    }
68  }