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