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.servlet.http.HttpServletResponse;
33  
34  public class ApplyRequestValuesCallback implements TobagoCallback {
35  
36    @SuppressWarnings("UnusedDeclaration")
37    private static final Logger LOG = LoggerFactory.getLogger(ApplyRequestValuesCallback.class);
38  
39    public void invokeContextCallback(FacesContext context, UIComponent component) {
40      if (FacesContextUtils.isAjax(context)) {
41        final String ajaxId = FacesContextUtils.getAjaxComponentId(context);
42        UIComponent reload = component.getFacet(Facets.RELOAD);
43        if (ajaxId != null && ajaxId.equals(component.getClientId(context)) && reload != null && reload.isRendered()
44            && ajaxId.equals(FacesContextUtils.getActionId(context))) {
45          Boolean immediate = (Boolean) reload.getAttributes().get(Attributes.IMMEDIATE);
46          if (immediate != null && immediate) {
47            Boolean update = (Boolean) reload.getAttributes().get(Attributes.UPDATE);
48            if (update != null && !update) {
49              if (context.getExternalContext().getResponse() instanceof HttpServletResponse) {
50                ((HttpServletResponse) context.getExternalContext().getResponse())
51                    .setStatus(HttpServletResponse.SC_NOT_MODIFIED);
52              }
53              context.responseComplete();
54              return;
55            }
56          }
57        }
58      }
59      component.processDecodes(context);
60    }
61  
62    public PhaseId getPhaseId() {
63      return PhaseId.APPLY_REQUEST_VALUES;
64    }
65  }