Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm trying to use Ajax validation in my Struts2 web app (with JQuery plugin) and i have an issue.

I had problems using the @Validations annotations so I'd just overrided the validate() method and all works fine with my xhtml forms now during the validation. The fieldsErrors are well recieved and printed in the gui.

The fact is, when the form is validated, a second POST is sent to the server to launch the Action. But, I don't know why, the framework doesn't set the model's attributes and during the generation of the HTML response after the execution of the Action, the framework can't access the attributes (only when I use the jsonValidationWorkflowStack).

I've created an simple example:

The Action

    @Namespace("/actions")
    @ParentPackage("actions")
    @InterceptorRef(value = "jsonValidationWorkflowStack")
   public class ActionTest extends ActionSupport implements
        ModelDriven<ModelTest>, ParameterAware {
    private static final long serialVersionUID = 1L;

    private ModelTest model;
    private Map<String, String[]> parameters;

    public ActionTest() {
        model = new ModelTest();
    }

    @Action(value = "actionTest", results = {
            @Result(name = SUCCESS, location = "/jsp/win.jsp"),
            @Result(name = ERROR, location = "/jsp/loose.jsp"),         
    })
    public String executeAction1() throws Exception {
        System.out.println("pass: "+getModel().getPass()); //the field is always null
        if ("test".equals(getModel().getPass()))
            return SUCCESS;
        return ERROR;
    }

    @Override
    public ModelTest getModel() {
        return model;
    }

    @Override
    public void validate() {
        String field;
        if (parameters.get("pass") != null) {
            field = parameters.get("pass")[0];
            if (field == null || field.isEmpty())
                addFieldError("pass", "the field is not set");
            else if (!"test".equals(field))
                addFieldError("pass", "the password is \"test\"");
        }

    }

    @Override
    public void setParameters(Map<String, String[]> arg0) {
        this.parameters = arg0;

    }
}

The Model

    public class ModelTest {

    private String pass;
    public String getPass() {
        return pass;
    }
    public void setPass(String pass) {
        this.pass = pass;
    }
}

The Form

<s:form action="actionTest" theme="xhtml">
<s:textfield name="pass"/>
<sj:submit validate="true"/>
</s:form>

In this example: - I'm always redirected to loose.jsp even if the password is "test" - If I want to print a in another jsp redirected by this action, i saw nothing (even if i set a default value in the model).

Can you give me a hand please???

PS: Sorry for my poor english :/

share|improve this question

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.