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