Try to change this code where messages
Email: {
required: "<small>Please enter a valid email address</small>",
email: "Email addresses are of the form user@host."
}
質問
For couple of days, I am trying to see as why my action is not getting invoked in this particular form.
My Form is something like below and I have struts URL tags which I am using along with Bootstrap framework:
<s:form action="RegisterUser" cssClass="form-horizontal" id="id-register-form" method="post">
Couple of Struts 2 UI tags
</s:form>
My Register user action is very simple with just an execute method in it which returns string "success"
:
public class RegisterUser extends ActionSupport {
public RegisterUser() {
}
@Override
public String execute() throws Exception {
System.out.println("Inside execute method test 1!");
return "success";
}
}
My struts.xml
for the above looks something like below:
<action name="RegisterUser" class="Mypackage.RegisterUser" method="execute">
<result name="success">/WEB-INF/views/usermanagement/register-success.jsp</result>
<result name="error">/WEB-INF/views/usermanagement/register-error.jsp</result>
</action>
But whenever I click the submit button of the form,form submission is never triggered. I have client side validation with jquery with jquery validate library and then doing server side with struts validation framework,but I believe issue is not related to validation but more on action mapping side or something related to submit button.Below is my submit button,
<s:submit type="button" cssClass="btn btn-primary" value="Create Account" cssStyle="float:left;">Create Account</s:submit>
Appreciate if someone can take a look and give me some insights. I am on Glassfish v4 and using Netbeans IDE and my Struts 2 is 2.3.15.3 on win 8.1
Here is my JS code for client side validation with jQuery:
$(document).ready(function() {
// validate the comment form when it is submitted
$("#id-register-form").validate({
errorPlacement: function(error, element) {
if (element.attr("name") == "Email") {
error.appendTo('#error-Email');
}
else if (element.attr("name") == "Password") {
error.appendTo('#error-Password');
}
else if (element.attr("name") == "ConfirmPassword") {
error.appendTo('#error-ConfirmPassword');
}
else if (element.attr("name") == "AgreetoPolicy") {
error.appendTo('#error-Agree');
}
},
rules: {
Email: {
required: true,
email: true
},
Password: {
required: true,
minlength: 5
},
ConfirmPassword: {
required: true,
minlength: 8,
equalTo: "#Password"
},
AgreetoPolicy: "required"
},
messages: {
Email: "<small>Please enter a valid email address</small>",
Password: {
required: "<small>Please provide a password</small>",
minlength: "<small>Your password must be at least 8 characters long</small>"
},
ConfirmPassword: {
required: "<small>Please provide a password</small>",
minlength: "<small>Your password must be at least 5 characters long</small>",
equalTo: "<small>Please enter the same password as above</small>"
},
AgreetoPolicy: "<strong><small>Please accept our policy</small></strong>"
}
});
});
解決
Try to change this code where messages
Email: {
required: "<small>Please enter a valid email address</small>",
email: "Email addresses are of the form user@host."
}
他のヒント
Yup issue is resolved now.It was my broken Jquery validation code that was responsible for not submitting the form...Thanks Roman and Andrea for your help and assistance.Appreciate it.