Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to display validation message in specific <div> element in Struts2

Tags:

struts2

I'm new to Struts 2 and facing this problem in keeping the layout of my page:

<s:form action="abc.action"><br>
    <s:textfield key="name" label="Name" /><%--here I need to display errormessage for `name`--%>
    <br>
    <s:textfield key="email" label="Email" /><%--here I need to display errormessage for `email`--%>
    <br>
    <s:submit>
</s:form>

I'm using xml-validator for my action class, this works fine. but the validation-error messages appear over the fieldname and text-box. but i want it to come afterwards respective text-box (inside another html-container). Kindly advise.

like image 585
tusar Avatar asked Jun 24 '11 08:06

tusar


2 Answers

If you're used to writing HTML, switch to the simple theme.

In struts.xml is probably the best place:

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

Then just use the fielderror tag to put the error for the field where you want it.

It's a good to be familiar with the Struts2 tags: http://struts.apache.org/release/2.3.x/docs/tag-reference.html

like image 140
Quaternion Avatar answered Nov 15 '22 07:11

Quaternion


That is the default according to Struts2 default templating. To change it, see http://www.mkyong.com/struts2/working-with-struts-2-theme-template/

like image 28
nmc Avatar answered Nov 15 '22 08:11

nmc