Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Action Message tag in struts2

Tags:

struts2

I'm new to struts to How to decorate the action message and action errors in struts2 jsp page?

<s:actionmessage/>
<s:actionerror/>
like image 306
Srivathsan Avatar asked May 07 '12 13:05

Srivathsan


People also ask

What are Struts tags?

You can create Struts HTML tags from the Struts HTML Tags drawer. These tags are used to create Struts input forms, as well as other tags generally useful in the creation of HTML-based user interfaces. The output is HTML 4.01 compliant or XHTML 1.0 when in XHTML mode.

How do you create an action class in struts?

Create Action The only requirement for actions in Struts2 is that there must be one noargument method that returns either a String or Result object and must be a POJO. If the no-argument method is not specified, the default behavior is to use the execute() method.

What is S tag in JSP?

The s:form tag has an action attribute that determines where to submit the form. Because we have a file upload element in the form, we have to set the enctype to multipart.


3 Answers

you can use the css styles as well as jquery theme attribute to decorate your action error and action message.

<div class="error"><s:actionerror theme="jquery"/></div>
<div class="message"><s:actionmessage theme="jquery"/></div>

.message li
{
    font-size: 14px;
    color: #000066;
    text-align: center;
    list-style: none;
    font-family: Trebuchet MS,sans-serif,inherit,Arial,monospace;
}

.error li
{
    font-size: 14px;
    color: #990000;
    text-align: center; 
    list-style: none;
    padding-right: 50px;
}
like image 154
Srivathsan Avatar answered Jan 03 '23 12:01

Srivathsan


Hi here i am posting solution for your problem if you want your action messages and error messages to decorate use this code

<div id="sucessMsg"><s:actionerror /></div>


sucessMsg is the class that is using by struts2 internally so override this so kindly put the below code inside the css

#sucessMsg {
    text-align: center;
    font-weight: bolder;
    color:  #6A2A91;
    list-style: none;
    margin: auto;
}

#errorMsg {
    text-align: center;
    font-weight: bolder;
    color: red;
    list-style: none;
    width: 350px;
    margin: auto;
}
like image 22
Raghavender Reddy Avatar answered Jan 03 '23 12:01

Raghavender Reddy


You should view the HTML source after it is rendered to see the CSS classes and HTML structure that Struts uses to render the message. You can also look in the template files.

By Default struts renders each action message as follows:

<ul>
  <li><span class="actionMessage">${message}</span></li>
</ul>

Every message will have a <li><span class="actionMessage">${message}</span></li>.

You can create CSS for actionMessage or change the template file to render these however you want.

The template files for these are located in:

/template/simple/actionerror.ftl
/template/simple/actionmessage.ftl

Field Error might be useful to you as well:

/template/simple/fielderror.ftl

note: if you are using the xhtml theme those files may be located in that folder under template

like image 44
Allan Avatar answered Jan 03 '23 12:01

Allan