and below is " /> and below is " /> and below is "/>

Struts2 - Validate error not refreshing on action tag call

250 Views Asked by At

I'm currently having a problem with my setup. I have this action tag in my JSP

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

and below is the corresponding struts.xml entry

<action name="doLogin" class="siteLoginAction">
    <result name="input">login</result>
    <result name="success">home</result>
</action>

The jsp is just a login div (form, textfield, label).

Now the problem is that when I'm testing the validate function

@Override
public void validate() {
    String username = siteUser.getSiteUserUsername();
    String password = siteUser.getSiteUserPassword();

    if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) {
        addFieldError("siteUser.siteUserUsername", "Invalid login");
    } else if (!siteUserService.checkLoginExists(username, password, getBlogSiteUrl())) {
        addFieldError("siteUser.siteUserPassword", "Invalid login");
    }
}

As you can see it works,

enter image description here

but it will not go away. The error message will stay there everytime I visit that page.

Is this because of the singleton default model of the Struts2 action? I have tried @Scope("prototype") but if I use it it doesn't display the error at all

1

There are 1 best solutions below

4
Andrea Ligios On

I have this <s:action> tag in my JSP

You should not use that tag, it's an old and useless technology, drop it ASAYC.

Is this because of the singleton default model of the Struts2 action? I have tried @Scope("prototype") but if I use it it doesn't display the error at all

Actions are ThreadLocal. What you're referring to with "default model" is the default scope (Singleton) of a Spring bean, and hence of a Struts2 Action if managed by Spring. And it would be wrong, you should use scope="prototype" in that case, to make the Spring managed actions working correctly as ThreadLocal objects.

This question is not answerable more than this right now; just drop the <s:action/> tag, use scope="prototype" (or drop Spring, at least on actions handling) and see what happens, then if it still doesn't work, come back here and ask again: it will be easy to help you then.