打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
关于struts2 API 中InputConfig 内 methodName 和resultName的使用方法

转载于:http://chenchangqun11.iteye.com/blog/799306

 

对于methodName 和resultName的区别很迷惑,查了很多资料都不得其解

最后在API中找到答案

引用

(1)Marks a action method that if it's not validated by ValidationInterceptor then execute input method or input result.

Annotation usage: The InputConfig annotation can be applied at method level.

Annotation parameters:

Parameter  Required   Default  Notes
methodName no         (2)execute this method if specific
resultName no         (3)return this result if methodName not specific



(1)当验证方法没有通过时,改变默认返回的input视图
(2) 执行指定的方法
(3)返回result 如果methodName 没有指定

废话少说 上代码

Java代码
  1. public class StudentAction extends  ActionSupport {   
  2.    @InputConfig(methodName="input2",resultName="resultTest")   
  3.            
  4.     public String inputConfigTest2(){   
  5.                
  6.        return INPUT;   
  7.                
  8.         }   
  9.     public void validateInputConfigTest2(){   
  10.         addFieldError("ss", "main validateInputConfigTest2");   
  11.     //validate方法在遇到 addFieldError方法时会自动返回input视图   
  12.            
  13.     }   
  14.         public String input2(){   
  15.                
  16.             return "test";   
  17.         }   
  18.   
  19. }  
  1. <span style="font-size: medium;">public class StudentAction extends  ActionSupport {  
  2.    @InputConfig(methodName="input2",resultName="resultTest")  
  3.           
  4.     public String inputConfigTest2(){  
  5.               
  6.        return INPUT;  
  7.               
  8.         }  
  9.     public void validateInputConfigTest2(){  
  10.         addFieldError("ss", "main validateInputConfigTest2");  
  11.     //validate方法在遇到 addFieldError方法时会自动返回input视图  
  12.           
  13.     }  
  14.         public String input2(){  
  15.               
  16.             return "test";  
  17.         }  
  18.   
  19. }  
  20. </span>  


@InputConfig(methodName="input2",resultName="resultTest") 的作用是改变默认返回的input视图 API中可查
resultName只有在methodName没写如@InputConfig(resultName="resultTest") 时才起做用


Jsp页面

Java代码
  1. <%@taglib prefix="s" uri="/struts-tags" %>//导入struts2标签   
  2.   
  3. <body>   
  4.   <s:fielderror/>   
  5. inputconfig test   
  6. </body>  
  1. <span style="font-size: medium;"><%@taglib prefix="s" uri="/struts-tags" %>//导入struts2标签  
  2.   
  3. <body>  
  4.   <s:fielderror/>  
  5. inputconfig test  
  6. </body>  
  7.   
  8. </span>  



上述代码只写了少部分 请自己配置 Action 并测试
调用方法 如 http://localhost:8080/struts2test10/studentAction!inputConfigTest2 

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
struts2学习
Android注解(annotation)实现绑定事件的原理
aop注解简单日志
Enterprise Java Community: Building on Struts for Java 5 Users
struts2采用convention
Struts2.1 annotation防止表单重复提交
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服