简体   繁体   English

Struts2如何在jsp中获取ActionError计数

[英]Struts2 how to get an ActionError count in a jsp

In Struts2 I have successfully implemented an updateErrorCount() method that updates a class member variable every time addActionError() is called through out various action classes. 在Struts2中,我成功实现了updateErrorCount()方法,该方法每次在通过各种操作类调用addActionError()都会更新类成员变量。 I can then access that variable with a property tag in the associated jsp . 然后,我可以在关联的jsp使用属性标签访问该变量。 However, I am looking for a better solution. 但是,我正在寻找更好的解决方案。 Since the s:actionerror tag lists all of the errors added, is there a way to use an iterator tag or some other solution to display the error count along with all of the error messages right in the jsp ? 由于s:actionerror标记列出了所有添加的错误,是否可以使用迭代器标记或其他解决方案在jsp显示错误计数以及所有错误消息?

I thought about overriding addActionError() to avoid having to call an additional method to keep an error count but if I could simply do it all in the jsp it seems much cleaner. 我考虑过重写addActionError()以避免必须调用其他方法来保持错误计数,但是如果我可以简单地在jsp完成所有操作,则它看起来会更干净。

getActionErrors returns a collection , why can't you just call size on that? getActionErrors返回一个集合 ,为什么不能仅调用size呢?

I see few legitimate reasons to implement any of this functionality manually. 我看到很少有正当理由手动实施任何此功能。

If you have specific needs you should enumerate them in your question, otherwise I don't see the point of doing this on your own. 如果您有特定需求,则应在问题中列举它们,否则我个人认为这样做没有意义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM