001 package org.apache.myfaces.tobago.taglib.extension; 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.TobagoConstants; 021 import org.apache.myfaces.tobago.apt.annotation.ExtensionTag; 022 import org.apache.myfaces.tobago.apt.annotation.Tag; 023 import org.apache.myfaces.tobago.component.ComponentUtil; 024 import org.apache.myfaces.tobago.component.UICommand; 025 import org.apache.myfaces.tobago.taglib.component.AbstractCommandTagDeclaration; 026 import org.apache.myfaces.tobago.taglib.component.MenuCommandTag; 027 import org.apache.myfaces.tobago.taglib.component.SelectOneRadioTag; 028 import org.apache.myfaces.tobago.taglib.decl.HasConverter; 029 import org.apache.myfaces.tobago.taglib.decl.HasIdBindingAndRendered; 030 import org.apache.myfaces.tobago.taglib.decl.HasLabel; 031 import org.apache.myfaces.tobago.taglib.decl.HasValue; 032 import org.apache.myfaces.tobago.taglib.decl.IsDisabled; 033 034 import javax.faces.component.UIComponent; 035 import javax.faces.el.ValueBinding; 036 import javax.faces.webapp.FacetTag; 037 import javax.servlet.jsp.JspException; 038 import javax.servlet.jsp.tagext.BodyTagSupport; 039 040 /* 041 * Date: 09.05.2006 042 * Time: 17:41:39 043 */ 044 045 /** 046 * Renders a submenu with select one items (like a radio button). 047 */ 048 049 @Tag(name = "menuRadio", tagExtraInfoClassName = "org.apache.myfaces.tobago.taglib.component.CommandTagExtraInfo") 050 @ExtensionTag(baseClassName = "org.apache.myfaces.tobago.taglib.component.MenuRadioTag") 051 public class MenuRadioExtensionTag extends BodyTagSupport implements AbstractCommandTagDeclaration, 052 HasIdBindingAndRendered, HasLabel, IsDisabled, HasValue, HasConverter { 053 054 private String rendered; 055 private String value; 056 057 private MenuCommandTag menuCommandTag; 058 private SelectOneRadioTag selectOneRadio; 059 private FacetTag facetTag; 060 private String action; 061 private String actionListener; 062 private String onclick; 063 private String link; 064 private String resource; 065 private String jsfResource; 066 private String disabled; 067 private String binding; 068 private String label; 069 private String immediate; 070 private String transition; 071 private String converter; 072 073 @Override 074 public int doStartTag() throws JspException { 075 076 menuCommandTag = new MenuCommandTag(); 077 menuCommandTag.setPageContext(pageContext); 078 menuCommandTag.setParent(getParent()); 079 080 if (rendered != null) { 081 menuCommandTag.setRendered(rendered); 082 } 083 if (action != null) { 084 menuCommandTag.setAction(action); 085 } 086 if (actionListener != null) { 087 menuCommandTag.setActionListener(actionListener); 088 } 089 if (onclick != null) { 090 menuCommandTag.setOnclick(onclick); 091 } 092 if (link != null) { 093 menuCommandTag.setLink(link); 094 } 095 if (resource != null) { 096 menuCommandTag.setResource(resource); 097 } 098 if (jsfResource != null) { 099 menuCommandTag.setJsfResource(jsfResource); 100 } 101 if (disabled != null) { 102 menuCommandTag.setDisabled(disabled); 103 } 104 if (binding != null) { 105 menuCommandTag.setBinding(binding); 106 } 107 if (label != null) { 108 menuCommandTag.setLabel(label); 109 } 110 if (immediate != null) { 111 menuCommandTag.setImmediate(immediate); 112 } 113 if (transition != null) { 114 menuCommandTag.setTransition(transition); 115 } 116 menuCommandTag.doStartTag(); 117 118 facetTag = new FacetTag(); 119 facetTag.setPageContext(pageContext); 120 facetTag.setParent(menuCommandTag); 121 facetTag.setName(org.apache.myfaces.tobago.TobagoConstants.FACET_ITEMS); 122 123 facetTag.doStartTag(); 124 selectOneRadio = new SelectOneRadioTag(); 125 selectOneRadio.setPageContext(pageContext); 126 selectOneRadio.setParent(facetTag); 127 if (converter != null) { 128 selectOneRadio.setConverter(converter); 129 } 130 if (value != null) { 131 selectOneRadio.setValue(value); 132 } 133 selectOneRadio.doStartTag(); 134 135 return super.doStartTag(); 136 } 137 138 @Override 139 public int doEndTag() throws JspException { 140 141 // Move attribute renderedPartially from selectOne to menuCommand component 142 UIComponent selectOneComponent = selectOneRadio.getComponentInstance(); 143 UICommand command = (UICommand) menuCommandTag.getComponentInstance(); 144 ValueBinding binding = selectOneComponent.getValueBinding(TobagoConstants.ATTR_RENDERED_PARTIALLY); 145 if (binding != null) { 146 command.setValueBinding(TobagoConstants.ATTR_RENDERED_PARTIALLY, binding); 147 } else { 148 Object renderedPartially = selectOneComponent.getAttributes().get(TobagoConstants.ATTR_RENDERED_PARTIALLY); 149 ComponentUtil.setRenderedPartially(command, (String) renderedPartially); 150 } 151 152 selectOneRadio.doEndTag(); 153 facetTag.doEndTag(); 154 menuCommandTag.doEndTag(); 155 156 return super.doEndTag(); 157 } 158 159 public void setAction(String action) { 160 this.action = action; 161 } 162 163 public void setActionListener(String actionListener) { 164 this.actionListener = actionListener; 165 } 166 167 public void setOnclick(String onclick) { 168 this.onclick = onclick; 169 } 170 171 public void setLink(String navigate) { 172 this.link = navigate; 173 } 174 175 public void setResource(String resource) { 176 this.resource = resource; 177 } 178 179 public void setJsfResource(String jsfResource) { 180 this.jsfResource = jsfResource; 181 } 182 183 public void setBinding(String binding) throws JspException { 184 this.binding = binding; 185 } 186 187 public void setRendered(String rendered) { 188 this.rendered = rendered; 189 } 190 191 public void setDisabled(String disabled) { 192 this.disabled = disabled; 193 } 194 195 public void setValue(String value) { 196 this.value = value; 197 } 198 199 public void setLabel(String label) { 200 this.label = label; 201 } 202 203 public void setImmediate(String immediate) { 204 this.immediate = immediate; 205 } 206 207 public void setTransition(String transition) { 208 this.transition = transition; 209 } 210 211 public void setConverter(String converter) { 212 this.converter = converter; 213 } 214 215 @Override 216 public void release() { 217 super.release(); 218 rendered = null; 219 value = null; 220 action = null; 221 actionListener = null; 222 onclick = null; 223 link = null; 224 resource = null; 225 jsfResource = null; 226 disabled = null; 227 binding = null; 228 label = null; 229 immediate = null; 230 transition = null; 231 converter = null; 232 menuCommandTag = null; 233 facetTag = null; 234 selectOneRadio = null; 235 } 236 237 }