1 /* 2 * Copyright (c) 2011-2024 PrimeFaces Extensions 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a copy 5 * of this software and associated documentation files (the "Software"), to deal 6 * in the Software without restriction, including without limitation the rights 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 * copies of the Software, and to permit persons to whom the Software is 9 * furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 * THE SOFTWARE. 21 */ 22 package org.primefaces.extensions.component.parameters; 23 24 import java.util.Map; 25 26 import javax.el.ValueExpression; 27 import javax.faces.component.UIComponent; 28 29 import org.primefaces.extensions.component.base.AbstractParameter; 30 import org.primefaces.extensions.util.DummyValueExpression; 31 32 /** 33 * Component class for the <code>MethodParameter</code> component. 34 * 35 * @author Thomas Andraschko / last modified by $Author$ 36 * @version $Revision$ 37 * @since 0.5 38 */ 39 public class MethodParameter extends AbstractParameter { 40 41 public static final String COMPONENT_TYPE = "org.primefaces.extensions.component.MethodParameter"; 42 43 /** 44 * Properties that are tracked by state saving. 45 * 46 * @author Thomas Andraschko / last modified by $Author$ 47 * @version $Revision$ 48 */ 49 @SuppressWarnings("java:S115") 50 protected enum PropertyKeys { 51 type 52 } 53 54 public MethodParameter() { 55 setRendererType(null); 56 } 57 58 @Override 59 public String getFamily() { 60 return AbstractParameter.COMPONENT_FAMILY; 61 } 62 63 public String getType() { 64 return (String) getStateHelper().eval(PropertyKeys.type, null); 65 } 66 67 public void setType(final String type) { 68 getStateHelper().put(PropertyKeys.type, type); 69 } 70 71 /** 72 * Enables converters to get the value type from the "value" expression. 73 * 74 * @param name DOCUMENT_ME 75 * @return DOCUMENT_ME 76 */ 77 @Override 78 public ValueExpression getValueExpression(final String name) { 79 if ("value".equals(name)) { 80 // get type from parent component 81 // MethodSignatureTagHandler stores all parameters to the parent component 82 final UIComponent parent = getParent(); 83 final Map<String, Object> parentAttribtues = parent.getAttributes(); 84 final Class<?>[] parameterTypes = (Class<?>[]) parentAttribtues.get(MethodSignatureTagHandler.PARAMETERS_TYPES_ATTRIBUTE_NAME); 85 final Class<?> parameterType = parameterTypes[parent.getChildren().indexOf(this)]; 86 87 return new DummyValueExpression(parameterType); 88 } 89 90 return super.getValueExpression(name); 91 } 92 }