mirror of
https://github.com/apache/struts.git
synced 2026-08-06 23:27:07 +00:00
Adds BeanInfo to allow define class attribute in JSPs
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
<s:url id="url" action="HelloWorld">
|
||||
<s:param name="request_locale">en</s:param>
|
||||
</s:url>
|
||||
<s:a href="%{url}">English</s:a>
|
||||
<s:a class="test" href="%{url}">English</s:a>
|
||||
</li>
|
||||
<li>
|
||||
<s:url id="url" action="HelloWorld">
|
||||
|
||||
@@ -44,7 +44,7 @@ public abstract class AbstractUITag extends ComponentTagSupport implements Dynam
|
||||
protected String disabled;
|
||||
protected String label;
|
||||
protected String labelSeparator;
|
||||
protected String labelPosition;
|
||||
protected String labelposition;
|
||||
protected String requiredPosition;
|
||||
protected String errorPosition;
|
||||
protected String name;
|
||||
@@ -96,7 +96,7 @@ public abstract class AbstractUITag extends ComponentTagSupport implements Dynam
|
||||
uiBean.setDisabled(disabled);
|
||||
uiBean.setLabel(label);
|
||||
uiBean.setLabelSeparator(labelSeparator);
|
||||
uiBean.setLabelposition(labelPosition);
|
||||
uiBean.setLabelposition(labelposition);
|
||||
uiBean.setRequiredPosition(requiredPosition);
|
||||
uiBean.setErrorPosition(errorPosition);
|
||||
uiBean.setName(name);
|
||||
@@ -148,6 +148,7 @@ public abstract class AbstractUITag extends ComponentTagSupport implements Dynam
|
||||
public void setCssStyle(String cssStyle) {
|
||||
this.cssStyle = cssStyle;
|
||||
}
|
||||
|
||||
public void setStyle(String cssStyle) {
|
||||
this.cssStyle = cssStyle;
|
||||
}
|
||||
@@ -173,7 +174,7 @@ public abstract class AbstractUITag extends ComponentTagSupport implements Dynam
|
||||
}
|
||||
|
||||
public void setLabelposition(String labelPosition) {
|
||||
this.labelPosition = labelPosition;
|
||||
this.labelposition = labelPosition;
|
||||
}
|
||||
|
||||
public void setRequiredPosition(String requiredPosition) {
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.struts2.views.jsp.ui;
|
||||
|
||||
import com.opensymphony.xwork2.util.logging.Logger;
|
||||
import com.opensymphony.xwork2.util.logging.LoggerFactory;
|
||||
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.beans.SimpleBeanInfo;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Describes properties supported by the AbstractUITag - base class for all UI tags
|
||||
* This bases on HtmlTagSupportBeanInfo class from StripesFramework - thanks!
|
||||
*/
|
||||
public class AbstractUITagBeanInfo extends SimpleBeanInfo {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AbstractUITagBeanInfo.class);
|
||||
|
||||
@Override
|
||||
public PropertyDescriptor[] getPropertyDescriptors() {
|
||||
try {
|
||||
List<PropertyDescriptor> descriptors = new ArrayList<PropertyDescriptor>();
|
||||
|
||||
// Add the tricky one first
|
||||
Method setter = AbstractUITag.class.getMethod("setCssClass", String.class);
|
||||
descriptors.add(new PropertyDescriptor("class", null, setter));
|
||||
descriptors.add(new PropertyDescriptor("cssClass", null, setter));
|
||||
|
||||
for (Field field : AbstractUITag.class.getDeclaredFields()) {
|
||||
String fieldName = field.getName();
|
||||
if (!"dynamicAttributes".equals(fieldName)) {
|
||||
String setterName = "set" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1);
|
||||
setter = AbstractUITag.class.getMethod(setterName, String.class);
|
||||
descriptors.add(new PropertyDescriptor(fieldName, null, setter));
|
||||
}
|
||||
}
|
||||
|
||||
PropertyDescriptor[] array = new PropertyDescriptor[descriptors.size()];
|
||||
return descriptors.toArray(array);
|
||||
} catch (Exception e) {
|
||||
// This is crazy talk, we're only doing things that should always succeed
|
||||
LOG.fatal("Could not construct bean info for AbstractUITag. This is very bad.", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,12 +25,22 @@ import org.apache.struts2.TestAction;
|
||||
import org.apache.struts2.views.jsp.AbstractUITagTest;
|
||||
|
||||
import javax.servlet.jsp.JspException;
|
||||
import java.beans.BeanInfo;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.PropertyDescriptor;
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
public class AnchorTest extends AbstractUITagTest {
|
||||
|
||||
public void testBeanInfo() throws Exception {
|
||||
BeanInfo beanInfo = Introspector.getBeanInfo(AbstractUITag.class);
|
||||
for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) {
|
||||
System.out.println(pd.getName() + ": write = " + pd.getWriteMethod() + ", read = " + pd.getReadMethod());
|
||||
}
|
||||
}
|
||||
|
||||
public void testSimple() throws Exception {
|
||||
createAction();
|
||||
|
||||
|
||||
@@ -109,7 +109,7 @@ public class ComponentTest extends AbstractUITagTest {
|
||||
tag.getComponent().addParameter("argle", "bargle");
|
||||
tag.getComponent().addParameter("glip", "glop");
|
||||
tag.getComponent().addParameter("array", new String[]{"a", "b", "c"});
|
||||
tag.getComponent().addParameter("obj", tag);
|
||||
tag.getComponent().addParameter("objClass", tag.getClass().getName());
|
||||
tag.doEndTag();
|
||||
|
||||
// System.out.println(writer);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
param hello = world
|
||||
param argle = bargle
|
||||
param glip = glop
|
||||
param obj.Class = class org.apache.struts2.views.jsp.ui.ComponentTag
|
||||
param obj.Class = org.apache.struts2.views.jsp.ui.ComponentTag
|
||||
|
||||
param array[0] = a
|
||||
param array[1] = b
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
param hello = ${parameters.hello}
|
||||
param argle = ${parameters.argle}
|
||||
param glip = ${parameters.glip}
|
||||
param obj.Class = ${parameters.obj.class}
|
||||
param obj.Class = ${parameters.objClass}
|
||||
|
||||
<#list parameters.array as element>
|
||||
param array[${element_index}] = ${element}
|
||||
|
||||
@@ -56,7 +56,7 @@ public class TabbedPanelTag extends AbstractClosingTag {
|
||||
tabbedPanel.setSelectedTab(selectedTab);
|
||||
tabbedPanel.setCloseButton(closeButton);
|
||||
tabbedPanel.setDoLayout(doLayout);
|
||||
tabbedPanel.setLabelposition(labelPosition);
|
||||
tabbedPanel.setLabelposition(labelposition);
|
||||
tabbedPanel.setTemplateCssPath(templateCssPath);
|
||||
tabbedPanel.setBeforeSelectTabNotifyTopics(beforeSelectTabNotifyTopics);
|
||||
tabbedPanel.setAfterSelectTabNotifyTopics(afterSelectTabNotifyTopics);
|
||||
|
||||
Reference in New Issue
Block a user