struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alfredo Manuel Osorio Martinez" <>
Subject Struts 2 s:action tag doesn't render action errors if any are present
Date Thu, 28 Oct 2010 17:35:18 GMT
For example I have the following:


<action name="personForm">



<action name="savePerson">


    <result name="input">/jsp/personForm.jsp</result>


<action name="countries">




<%@ taglib prefix="s" uri="/struts-tags" %>

<s:form action="savePerson">

        <s:textfield name="firstName" label="First Name" />

        <s:textfield name="lastName" label="Last Name" />

        <s:action name="countries" executeResult="true" />

        <s:submit />


public class CountriesAction extends ActionSupport {

    public String execute() {

        countries = getCountries();

        return SUCCESS;


    private Map<String, String> getCountries() {



    private Map<String, String> countries;  



    <%@ taglib prefix="s" uri="/struts-tags" %>

    <s:select name="countryId" label="Countries" list="countries" 

        headerKey="-1" headerValue="Please select the country ..."/>


public class SavePerson extends ActionSupport {

    public void validate() {

        if (firstName == "") {

            addFieldError(firstName, "First Name is required.");


        if (lastName == "") {

            addFieldError(lastName, "Last Name is required.");


        if (countryId == "-1") {

            addFieldError(countryId, "Country is required.");



    public String execute() {

        //get the properties and save the person...

        return SUCCESS;


    private String firstName;

    private String lastName;

    private String countryId;

    //corresponding setters and getters..


When I submit the form and a validation error occurs for example let's
say we didn't fill in any data so the input fields 'firstName' and
'lastName' will have their corresponding message next to them. But
that's not the case for the country select list, even though there are
action errors those won't display. 

I believe this happens because the parent action which is SavePerson is
the one who added the errors (addFieldErrors) but when the other action
Countries (the one that populates the list) is called then those errors
are not available in that context because if I call hasErrors() within
that Action it will be "false" so when the input gets rendered and check
if there are any errors in order to render the message will call
hasErrors and will return false so no errors messages will be rendered.

This approach of calling another action just to render another input
controls is one of the ways that Struts 2 FAQS tell to do that:

So how can I make those controls on those actions render the action
errors from its parent action.

Any thoughts?

Thank you in advance


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message