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