解决Struts2.2.20版本的标签不支持style属性的问题
我先把Exception错误信息贴出来:org.apache.jasper.JasperException: /WEB-INF/jsp/topicAction/addUI.jsp (line: 40, column: 0) Unable to find setter method for attribute: style
通过Exception定位的源代码是:
通过提示我们大概能知道是因为找不到style属性的setter方法,可这个标签是struts2封装的HTML原生标签,但style属性在HTML里使用是完全没问题的,由此我想到可能是struts2封装的问题,于是乎找到struts关于UI标签的源码。如下:
public class AbstractUITagBeanInfo extends SimpleBeanInfo {
private static final Logger LOG =
LoggerFactory.getLogger(AbstractUITagBeanInfo.class);
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;
}
}
}
发现 AbstractUITagBeanInfo中确实没有对style属性的解析处理代码,于是我去官网下载了更新版本的struts(struts2.3.21),查看源代码 惊喜的发现它解决了这个问题。我把它的这部分代码贴出来:
descriptors.add(new PropertyDescriptor("class", null, classSetter));
descriptors.add(newPropertyDescriptor("cssClass", null, classSetter));
descriptors.add(new PropertyDescriptor("style", null, styleSetter)); //这里是相对于struts2.3.20增加的对style属性的解析
descriptors.add(new PropertyDescriptor("cssStyle", null, styleSetter)); //这里是相对于struts2.3.20增加的对cssStyle属性的解析
那么问题来了,我们要怎么解决这个问题呢,我的做法是在工程中新建一个和AbstractUITagBeanInfo这个类同名同包的文件(包名和类名都要相同),再把struts2.3.21版本中这个类的源代码拷贝过来,这样新的类就会覆盖原来的那个标签处理类。当然你也可以找到这个类所在的jar包删掉再把新版本中的这个jar包加进来。
注:这个不仅是针对<s:form/>标签,所有有style属性的标签如<s:textfiled/>等都会出现这个问题。
版权声明:本文为博主原创文章,未经博主允许不得转载。
解决Struts2.2.20版本的标签不支持style属性的问题的更多相关文章
- 让arclist标签也支持currentstyle属性 完美解决
1.查找到: $channelid = $ctag->GetAtt('channelid'); 在下面插入:$currentstyle = $ctag->GetAtt('currentst ...
- dede织梦 arclist标签完美支持currentstyle属性
由于客户需求,所以进行对文章的arclist标签进行设置当前样式(currentstyle),修改前记得备份. dede版本v5.7sp 找到PHP修改: include/taglib/arclist ...
- 在VSCode中编辑HTML文档时,在Dom标签上写style属性时智能提示的问题
首先在VSCode中打开一个HTML文件 然后点右下角的“选择语言模式” 然后点击配置HTML语言的基础设置 然后在打开的界面中(右侧) 输入如下代码 { "editor.quickSugg ...
- background低版本安卓浏览器不支持复合属性,要分开写
background:url("http://..../xxx.jpg") no-repeat center/cover; 这种复合形式在有些低端安卓浏览器中不支持,最好分开写: ...
- 解决struts2中UI标签出现的问题: The Struts dispatcher cannot be found
解决struts2中UI标签出现的问题: The Struts dispatcher cannot be found 异常信息: The Struts dispatcher cannot be fou ...
- struts2的s:iterator 标签 详解
s:iterator 标签有3个属性:value:被迭代的集合id :指定集合里面的元素的idstatus 迭代元素的索引1:jsp页面定义元素写法 数组或list <s:iterator ...
- 框架学习之Struts2(四)---拦截器和标签
一.拦截器概述 1.1 在struts2框架中封装了很多功能,struts2里面封装的功能都是在拦截器里面,struts2里面又很多拦截器,但不是每次这些拦截器都执行,每次执行型默认的拦截器. 默认拦 ...
- mysql-5.7.20 版本的 mysql-group-replication 可用性测试报告
一.喜迎 mysql-5.7.20 事实上mysql-group-replication 功能是在mysql-5.7.17这个版本上引入的,它实现了mysql各个结点间数据强一致性, 这个也成为了我 ...
- struts2的s:iterator 标签 详解<转>
struts2的s:iterator 可以遍历 数据栈里面的任何数组,集合等等 以下几个简单的demo: s:iterator 标签有3个属性: value:被迭代的集合 id : ...
随机推荐
- JAVA车票管理系统(简单GUI)
一. 需求分析 1.设计题目:车票管理系统 用JAVA语言和数据结构知识设计设计车票管理系统.要求如下所述: 一车站每天有n个发车班次,每个班次都有一个班次号(1.2.3…n),固定的发车时间, ...
- js设计模式系列之(一)请节约你的请求-代理模式
What’s the proxy pattern? 代理模式其实就是将违反单一性原则的类给抽离出来,尽量满足开放和封闭的原则. 相当于一个类的行为只是一种,但是你可以给这个类添加额外的行为.比如: 一 ...
- 深入了解Json转变为map的思想,附源代码2
最近在做一个投票情况的用例,返回的结果打算放到JSON中 数据库的结果集如上图所示:optionkey代表选项,optionval代表其值 第一次做的时候考虑应该键值对应的关系,所以前台接到的json ...
- MergeSort 归并排序
实现: 二路归并 public class TestMergeSort { public int[] mergeSortArray(int[] arr, int left, int right){ i ...
- WebService-使用JDK开发WebService
一.使用JDK开发WebService 2.1.开发WebService服务器端 1.定义一个interface,使用@WebService注解标注接口,使用@WebMethod注解标注接口中定义的所 ...
- Linux基本操作 1-----命令行BASH的基本操作
1 Shell(壳)是用户与操作系统底层(通常是内核)之间交互的中介程序,负责将用户指令.操作传递给操作系统底层 shell 分为两种 CUI : Command Line Interface Lin ...
- Android Fragment详解(六):Fragement示例
把条目添加到动作栏 你的fragment们可以向activity的菜单(按Manu键时出现的东西)添加项,同时也可向动作栏(界面中顶部的那个区域)添加条目,这都需通过实现方法onCreateOptio ...
- Android高级图片滚动控件,编写3D版的图片轮播器
转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/17482089 大家好,好久不见了,最近由于工作特别繁忙,已经有一个多月的时间没写博 ...
- HashMap陷入死循环的例子
//使用这个例子可以模拟HashMap陷入死循环的效果,可能需要执行多次才会出现. 1 package com.hanzi; import java.util.HashMap; public clas ...
- 数据库分库分表(sharding)系列(一)拆分实施策略和示例演示
本文原文连接: http://blog.csdn.net/bluishglc/article/details/7696085 ,转载请注明出处!本文着重介绍sharding切分策略,如果你对数据库sh ...