001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019 020 package org.apache.myfaces.tobago.component; 021 022 import org.apache.myfaces.tobago.ajax.api.AjaxPhaseListener; 023 import static org.apache.myfaces.tobago.TobagoConstants.FACET_RELOAD; 024 025 import javax.faces.context.FacesContext; 026 import javax.servlet.http.HttpServletResponse; 027 028 /** 029 * User: idus 030 * Date: 12.03.2007 031 * Time: 22:32:13 032 */ 033 public class UIPanel extends UIPanelBase implements SupportsMarkup { 034 035 public static final String COMPONENT_TYPE = "org.apache.myfaces.tobago.Panel"; 036 037 private String[] markup; 038 039 public String[] getMarkup() { 040 if (markup != null) { 041 return markup; 042 } 043 return ComponentUtil.getMarkupBinding(getFacesContext(), this); 044 } 045 046 public void setMarkup(String[] markup) { 047 this.markup = markup; 048 } 049 050 @Override 051 public void restoreState(FacesContext context, Object state) { 052 Object[] values = (Object[]) state; 053 super.restoreState(context, values[0]); 054 markup = (String[]) values[1]; 055 } 056 057 @Override 058 public Object saveState(FacesContext context) { 059 Object[] values = new Object[2]; 060 values[0] = super.saveState(context); 061 values[1] = markup; 062 return values; 063 } 064 065 public void processDecodes(FacesContext context) { 066 final String ajaxId = (String) context.getExternalContext() 067 .getRequestParameterMap().get(AjaxPhaseListener.AJAX_COMPONENT_ID); 068 if (ajaxId !=null && ajaxId.equals(getClientId(context))) { 069 if (getFacet(FACET_RELOAD) != null && getFacet(FACET_RELOAD) instanceof UIReload 070 && getFacet(FACET_RELOAD).isRendered() 071 && ((UIReload) getFacet(FACET_RELOAD)).isImmediate() 072 && ajaxId.equals(ComponentUtil.findPage(context, this).getActionId())) { 073 UIReload reload = (UIReload) getFacet(FACET_RELOAD); 074 if (!reload.getUpdate()) { 075 if (context.getExternalContext().getResponse() instanceof HttpServletResponse) { 076 ((HttpServletResponse) context.getExternalContext().getResponse()) 077 .setStatus(HttpServletResponse.SC_NOT_MODIFIED); 078 } 079 context.responseComplete(); 080 return; 081 } 082 } 083 } 084 super.processDecodes(context); 085 } 086 087 }