为什么我的actionErrors和fieldErrors用大括号[]显示? [英] Why are my actionErrors and fieldErrors displayed with braces []?

查看:111
本文介绍了为什么我的actionErrors和fieldErrors用大括号[]显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一旦页面在我的Struts 2应用程序中捕获了错误,这些错误就会从我的资源包中正确显示,但是它们总是用大括号显示.[]例如

Once the pages have captured errors within my Struts 2 application the errors are displayed correctly from my resource bundles however they are always displayed with a braces [] For example

[first name must not be empty]

这些通过标签显示

<s:actionerror />

<s:iterator value="fieldErrors">
   <s:property value="value" />
</s:iterator>

这些通过Action-validation.xml进入,并通过验证方法设置addFieldError()

These come through the Action-validation.xml and setting a addFieldError() through the validation method

这与将主题设置为simple有关吗?我看不到文档中的任何内容,也看不到其他帖子中的任何内容...

Is this something to do with my theme being set to simple ? I can't see anything in documentation or anything through other posts...

推荐答案

为什么

不,这与主题无关.看一下getFieldErrors方法.它返回map,其中value是一个字符串列表.

Why

No, it is not about theme. Take a look at getFieldErrors method. It returns map where value is a list of strings.

public Map<String, List<String>> getFieldErrors() {
    return validationAware.getFieldErrors();
}

您的代码遍历地图,并且value是列表.以字符串形式显示的列表将带有大括号.

Your code iterates over map and value is a list. List as string will be displayed with surrounding braces.

如果仅需要错误消息的值而不是密钥,则可以使用addActionError方法,并遍历actionErrors.

If you need only value of the error message and not the key then you can use addActionError method instead and iterate over actionErrors.

如果要迭代fieldErrors,则可以这样做.

If you want to iterate fieldErrors then you can do it like that.

<s:iterator value="fieldErrors">
    <s:property value="key"/>:
    <s:iterator value="value">
        <s:property/>
    </s:iterator>
</s:iterator>

当然还有用于显示错误/消息的标签,请参见非表单UI标记.

And of course there are tags for displaying errors/messages, see Non-Form UI Tags.

这篇关于为什么我的actionErrors和fieldErrors用大括号[]显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆