001    package org.apache.myfaces.tobago.component;
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.myfaces.tobago.ajax.api.AjaxPhaseListener;
021    import static org.apache.myfaces.tobago.TobagoConstants.FACET_RELOAD;
022    
023    import javax.faces.context.FacesContext;
024    import javax.servlet.http.HttpServletResponse;
025    
026    /**
027     * User: idus
028     * Date: 12.03.2007
029     * Time: 22:32:13
030     */
031    public class UIPanel extends UIPanelBase implements SupportsMarkup {
032    
033      public static final String COMPONENT_TYPE = "org.apache.myfaces.tobago.Panel";
034    
035      private String[] markup;
036    
037      public String[] getMarkup() {
038        if (markup != null) {
039          return markup;
040        }
041        return ComponentUtil.getMarkupBinding(getFacesContext(), this);
042      }
043    
044      public void setMarkup(String[] markup) {
045        this.markup = markup;
046      }
047    
048      @Override
049      public void restoreState(FacesContext context, Object state) {
050        Object[] values = (Object[]) state;
051        super.restoreState(context, values[0]);
052        markup = (String[]) values[1];
053      }
054    
055      @Override
056      public Object saveState(FacesContext context) {
057        Object[] values = new Object[2];
058        values[0] = super.saveState(context);
059        values[1] = markup;
060        return values;
061      }
062    
063      public void processDecodes(FacesContext context) {
064        final String ajaxId = (String) context.getExternalContext()
065            .getRequestParameterMap().get(AjaxPhaseListener.AJAX_COMPONENT_ID);
066        if (ajaxId !=null && ajaxId.equals(getClientId(context))) {
067          if (getFacet(FACET_RELOAD) != null && getFacet(FACET_RELOAD) instanceof UIReload
068              && getFacet(FACET_RELOAD).isRendered()
069              && ((UIReload) getFacet(FACET_RELOAD)).isImmediate()
070              && ajaxId.equals(ComponentUtil.findPage(context, this).getActionId())) {
071            UIReload reload = (UIReload) getFacet(FACET_RELOAD);
072            if (!reload.getUpdate()) {
073              if (context.getExternalContext().getResponse() instanceof HttpServletResponse) {
074                 ((HttpServletResponse) context.getExternalContext().getResponse())
075                     .setStatus(HttpServletResponse.SC_NOT_MODIFIED);
076              }
077              context.responseComplete();
078              return;
079            }
080          }
081        }
082        super.processDecodes(context);
083      }
084    
085    }