论坛首页 入门技术论坛

struts2 OGNL实例化数组的问题.

浏览 5533 次
该帖已经被评为新手帖
作者 正文
   发表时间:2007-10-16  
我在Action中使用了:

  private SingerDto[] singerDtos;

也定义了getter和setter方法:

public void setSingerDtos(SingerDto[] singerDtos) {
  this.singerDtos = singerDtos;
}
   
public  SingerDto[]  getSingerDtos() {
  return singerDtos;
}

歌手姓名:<input type="text" name="singerDtos[0].name"><br>
<select name="singerDtos[0].region">
           <option value="china" selected>华人歌手</option>
            <option value="korea">韩国歌手</option>
            <option value="japan">日本歌手</option>
            <option value="occident">欧美歌手</option>
 </select>
结果抛出异常:

66218 [http-8080-Processor24] DEBUG com.opensymphony.xwork2.interceptor.ParametersInterceptor  - Setting params bandName => [  ] singerDtos[0].region => [ china ] singerDtos[0].name => [ fdsfd ] uploadContentType => [ audio/mp3 ] singerDtos[0].sex => [ m ] songName => [ ddd ] type => [ 1 ] uploadFileName => [ 20076857868205.mp3 ] upload => [ C:\Program Files\apache-tomcat-5.5.25\work\Catalina\localhost\Music\upload_25bd70bb_115a4017d5e__8000_00000001.tmp ] 
66234 [http-8080-Processor24] DEBUG com.opensymphony.xwork2.util.XWorkConverter  - Property: bandName
66234 [http-8080-Processor24] DEBUG com.opensymphony.xwork2.util.XWorkConverter  - Class: edu.jlu.fuliang.action.UploadSongAction
66250 [http-8080-Processor24] DEBUG com.opensymphony.xwork2.util.XWorkConverter  - converter is null for property bandName. Mapping size: 0
66250 [http-8080-Processor24] DEBUG com.opensymphony.xwork2.util.XWorkConverter  - field-level type converter for property [bandName] = none found
66250 [http-8080-Processor24] DEBUG com.opensymphony.xwork2.util.XWorkConverter  - global-level type converter for property [bandName] = none found
66250 [http-8080-Processor24] DEBUG com.opensymphony.xwork2.util.XWorkConverter  - falling back to default type converter [com.opensymphony.xwork2.util.XWorkBasicConverter@1cbcc56]
66250 [http-8080-Processor24] DEBUG com.opensymphony.xwork2.util.InstantiatingNullHandler  - Entering nullPropertyValue [target=[edu.jlu.fuliang.action.UploadSongAction@d43997, com.opensymphony.xwork2.DefaultTextProvider@4486de], property=singerDtos]
66265 [http-8080-Processor24] ERROR com.opensymphony.xwork2.util.InstantiatingNullHandler  - Could not create and/or set value back on to object
org.springframework.beans.factory.BeanCreationException: Error creating bean with name '[Ledu.jlu.fuliang.dto.SingerDto;': Could not resolve matching constructor
 at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:178)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:800)
 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowire(AbstractAutowireCapableBeanFactory.java:258)
 at com.opensymphony.xwork2.spring.SpringObjectFactory.buildBean(SpringObjectFactory.java:145)
 at com.opensymphony.xwork2.util.InstantiatingNullHandler.createObject(InstantiatingNullHandler.java:123)
 at com.opensymphony.xwork2.util.InstantiatingNullHandler.nullPropertyValue(InstantiatingNullHandler.java:104)
 at ognl.ASTProperty.getValueBody(ASTProperty.java:94)
 at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:170)
 at ognl.SimpleNode.getValue(SimpleNode.java:210)
 at ognl.ASTChain.setValueBody(ASTChain.java:168)
 at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:177)
 at ognl.SimpleNode.setValue(SimpleNode.java:246)

我们发现ParametersInterceptor被调用后,委托给SpringObjectFactory来实例化[b]Ledu.jlu.fuliang.dto.SingerDtoorg.springframework.beans.factory.BeanCreationException: Error creating bean with name '[Ledu.jlu.fuliang.dto.SingerDto;': Could not resolve matching constructor[/b]结果实例化失败.SingerDto应该不受Spring ioc容器管理吧,难道是这个问题,在struts 2 参考文档中没有找到类似的例子,后来我把SingerDto[] singerDtos;改成List<SingerDto> singerDtos,结果好使了.我又在网上搜搜struts2是否支持数组,结果在一个网站上搜到这个结果:

[color=red]Struts doesn't support array creation due to an issue with size determination. Kinda what I though earlier. So, I've changed it over to use a List<Integer> and that works fine. 

The docs are very misleading on this point. I'd be more than happy to clean up the type conversion doc and also create an collection handling doc to help folks out with this issue. Let me know if I can help out at all.[/color]

作者同样使用了List<Integer>代替了Integer[]结果成功.struts2是否支持创建数组还是一个bug,现在还不知道,但List来代替数组就可以避免这个的错误.不知道大家遇到过这个问题么?

    
   发表时间:2008-09-27  
请问楼主怎么捕获用数组发生的异常
0 请登录后投票
   发表时间:2008-09-27  
goodfifa07 写道

请问楼主怎么捕获用数组发生的异常

把logger级别调到debug,各种信息都会有。
0 请登录后投票
论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics