解决使用Struts2的s:textfield标签出现Unable to find setter method for attribute: style的问题
来源:互联网 发布:免费排课软件 编辑:程序博客网 时间:2024/06/05 21:05
把项目中的struts2从2.3.1.2升级到2.3.20,跑起来之后出现一个这样的问题:
org.apache.jasper.JasperException: /pages/login.jsp (line: 103, column: 7) Unable to find setter method for attribute: style
错误消息很明显:没有style的setter方法,但是很诡异,jsp中哪有什么setter方法,定位到代码一看,是s:textfield中的style属性:
<s:textfield label="用户ID" name="model.userid" id="userid" required="true" class="{character:true}" style="width:220px; height:30px; margin-left:10px;" />
谷歌下,发现是Struts2 2.3.20的一个bug,org.apache.struts2.views.jsp.ui.AbstractUITagBeanInfo中没有对style属性进行解析处理:
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; } }}
目前已经在2.3.21中已经修复了:
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 classSetter = AbstractUITag.class.getMethod("setCssClass", String.class); Method styleSetter = AbstractUITag.class.getMethod("setCssStyle", String.class); descriptors.add(new PropertyDescriptor("class", null, classSetter)); descriptors.add(new PropertyDescriptor("cssClass", null, classSetter)); descriptors.add(new PropertyDescriptor("style", null, styleSetter)); descriptors.add(new PropertyDescriptor("cssStyle", null, styleSetter)); 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); Method 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; } } }
jira:https://fisheye6.atlassian.com/browse/struts/core/src/main/java/org/apache/struts2/views/jsp/ui/AbstractUITagBeanInfo.java?r1=587e3a41b1d306eb246aa39d71dce469f4e50e9d&r2=4964b74797971751bedad0ba0982f53ef0934a2c
0 0
- 解决使用Struts2的s:textfield标签出现Unable to find setter method for attribute: style的问题
- 关于自定义标签当中的unable to find setter method for attribute:xxx错误 小记
- 自定义标签 Unable to find setter method for attribute
- Unable to find setter method for attribute: [commandName]
- struts2的s:textField标签问题
- 解决使用python3.5来获取PCL库出现 unable to find vcvarsall.bat的问题
- struts2 在<s:form>之间添加<s:textfield>或其他标签是出现可能的错误
- repo下载android出现fatal: Unable to find remote helper for 'https'问题的方法
- 记一次git fatal: Unable to find remote helper for 'https'问题的解决
- <s:textfield>标签的tr问题
- struts2<s:textfield>value默认值的问题
- 使用Lomboz3生成Struts2项目后运行Tomcat出现Unable to load bean错误的解决
- linux使用velocity出现的一个奇葩问题-Unable to find resource
- python扩展问题”unable to find vcvarsall.bat“的解决
- Python扩展问题”unable to find vcvarsall.bat“的解决
- Unable to find vcvarsall.bat问题的解决
- struts2 s:textfield 标签输出日期问题
- struts2 使用<s>标签注意的问题
- 系统架构演化历程
- 编译时,出现ln软连接错误原因及解决方法
- 目标检测的图像特征提取之HOG特征
- 分享一个用树莓派+SS+ChinaDNS+bandwagon 做网关的帖子
- /var/log/ 常见log 说明
- 解决使用Struts2的s:textfield标签出现Unable to find setter method for attribute: style的问题
- DALFactory
- server2003 64位系统odbc读取execl问题
- 自动ssh登录的几种方法
- android 各国语言缩写
- Android应用之最新版本SDKV2.4实现QQ第三方登录
- 移动端弹出提示插件,自写移动端dialog插件
- c++_primer_exercise_1112
- Android 开发环境搭建与Hello World