Struts中FeildError问题

2014-11-24 10:38:56 · 作者: · 浏览: 2

Struts中在前台中通过拿到action中addFieldError("fielderror.test", "wrong!")添加的错误信息是,默认情况下是带了

  • ...
格式的。这个给自己设定错误信息的表现带来不便,三种解决方法:


1. 在前台jsp页面中加入css控制


.formFieldError ul li{


list-style-type: none
}






2. 在struts.xml中配置配置如下常量时,默认的ui主题会到struts-core的jar包中找对应的配置




这个配置截图:



若value=simple,则找template.simple中配置,这里的value还可以取值xhtml,css_xhtml,xhtml,那么对应的就找对应的template中的ui配置,其中有一个文件为/template/simple/fielderror.ftl。只要自己在src下定义一个相同名称的配置,然后删除其中的加格式的部分就可以了。




删除后如下,直接拷贝到fielderror.ftl中


<#--
/*
* $Id: fielderror.ftl 722375 2008-12-02 05:19:57Z wesw $
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
-->
<#if fieldErrors ><#t/>
<#assign eKeys = fieldErrors.keySet()><#t/>
<#assign eKeysSize = eKeys.size()><#t/>
<#assign doneStartUlTag=false><#t/>
<#assign doneEndUlTag=false><#t/>
<#assign haveMatchedErrorField=false><#t/>
<#if (fieldErrorFieldNames size > 0) ><#t/>
<#list fieldErrorFieldNames as fieldErrorFieldName><#t/>
<#list eKeys as eKey><#t/>
<#if (eKey = fieldErrorFieldName)><#t/>
<#assign haveMatchedErrorField=true><#t/>
<#assign eva lue = fieldErrors[fieldErrorFieldName]><#t/>
<#if (haveMatchedErrorField && (!doneStartUlTag))><#t/>

<#if parameters.cssClass >
class="${parameters.cssClass html}"<#rt/>
<#else>
class="errorMessage"<#rt/>

<#if parameters.cssStyle >
style="${parameters.cssStyle html}"<#rt/>

>
<#assign doneStartUlTag=true><#t/>
<#t/>
<#list eva lue as eEachValue><#t/>

  • ${eEachValue}

  • <#t/>
    <#t/>
    <#t/>
    <#t/>
    <#if (haveMatchedErrorField && (!doneEndUlTag))><#t/>

    <#assign doneEndUlTag=true><#t/>
    <#t/>
    <#else><#t/>
    <#if (eKeysSize > 0)><#t/>

    <#list eKeys as eKey><#t/>
    <#assign eva lue = fieldErrors[eKey]><#t/>
    <#list eva lue as eEachValue><#t/>
    ${eEachValue}
    <#t/>
    <#t/>

    <#t/>
    <#t/>
    <#t/>


    3. 直接将struts.xml中的中的value改为自己自定义的值,如






    然后在src中定义template.mytheme将原来默认的配置全部拷进去,然后在这里面像2那样改掉fielderror.ftl。