STRUTS2 Validation Information Style modification

Source: Internet
Author: User

Struts2 inside the Fielderror label style modification problem

When we register a user, if the prompt to the foreground is a duplicate user name and the user name is too long, you will have to add multiple errors to the action , then to the foreground how to take it out in turn

Solutions

1. The solution I came up with was to make a judgment at the corresponding action in the background and eventually give an error message, except that the error message could be judged combined (background processing). Which means we can get values from the value stack .

<s:property value= "fielderror.name[0]"/>

2. Use the struts2 <s:fielderror/> tag to get the error message, but have their own format, to find ways to remove his format : The style imposed by struts is covered out, You can also manually set its style to none

. errormessage{

List-style-type: none;

}

But this still has ul Li thus has the effect of the line change so how to remove the ul Li? This is still a bit of a hassle.

3. Remove the ul Li method

1. unpack the Strut-core package to see the TEMPLATE-SIMPLE-FIELDERROR.FTL file to the last point

<ul< #rt/>

< #if parameters.cssclass?? >

class= "${parameters.cssclass?html}" < #rt/>

< #else >

class= "ErrorMessage" < #rt/>

</#if >

< #if Parameters.cssstyle?? >

Style= "${parameters.cssstyle?html}" < #rt/>

</#if >

>

< #list EKeys as ekey>< #t/>

< #assign evalue = fielderrors[ekey]>< #t/>

< #list evalue as eeachvalue>< #t/>

<li><span>< #if parameters.escape>${eeachvalue!? html}< #else >${eeachvalue!} </#if ></span></li>

</#list >< #t/>

</#list >< #t/>

</ul> Change into

< #list EKeys as ekey>< #t/>

< #assign evalue = fielderrors[ekey]>< #t/>

< #list evalue as eeachvalue>< #t/>

<span>< #if parameters.escape>${eeachvalue!? HTML} < #else >${eeachvalue!} </#if ></span>

</#list >< #t/>

</#list >< #t/>

That is, remove the ul Li and then pack and put it back .

2. Generally this destroys the other person's encapsulation,struts inside can take the form of covering the specific following:

Configuring Constants in Struts.xml is the same as specifying which style we use and then changing the appropriate struts style .

<constant name= "Struts.ui.theme" value= "simple"/>

Then create a new package template in the SRC directory . Simple (to build two times in order) and then put the modified Filederror.flt file inside, restart the project, you will see the UL Li disappeared when you want to add any style you like

3. You can define your own theme

Configure constants inside the Struts.xml

<constant name= "Struts.ui.theme" value= "MyTheme"/>

Of course, we have to put the strutscore inside the whole contents of the folder inside the template-mytheme, and modify our Fielderror.flt file  

Finally struts all the tags, only fielderror to add CSS to us, when we change the Fielderror after the other label we still use the theme= "simple" theme

<constant name= "Struts.ui.theme" value= "simple"/> where theme= "XHTML" is the default

STRUTS2 Validation Information Style modification

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.