I'm developing a shopping cart application. In my application has customer registration form. I'm using Struts2 tiles. When the client clicks Register button, my application pops up a jquery model window. In my NewUser.java
action class overridden the validate()
method of ActionSupport
class. If the email field is empty, How do I popup the register form with field error.
My action class:
@Override
public void validate() {
if (customer.getEmail().equals("")) {
addFieldError("email", "First Name is Required.");
}
}
My popup window:
<div id="register" class="modal hide fade" tabindex="-1">
<form action="CustomerAdd">
<label class="control-label" for="email">Email address</label>
<div class="controls">
<s:textfield name="customer.email" cssClass="input-xlarge"/>
</div>
</form>
</div>
<a href="#register" class="btn btn-small" data-toggle="modal">
Register now <i class="icon-chevron-right"></i>
</a>
Struts2 action:
<action name="CustomerAdd" class="com.shopping.op.customer.CustomerAdd">
<result name="success" type="tiles">success_customer</result>
<result name="failed" type="tiles">failed_customer</result>
<result name="not_available" type="tiles">user_already_added</result>
<result name="input" type="tiles">validate_customer</result>
</action>
tiles definition:
<definition name="validate_customer" extends="baselayout">
<put-attribute name="opr" value="/customer/customer.jsp"/>
<put-attribute name="body" value="/login.jsp"/><!--This page has the Register button-->
</definition>
Thanks in Advance!
In your popup window you need to add
actionerror
tag to display the errors. Like this,I hope if you properly handled validate method you may not able submit until email is entered. What you missed is display the error in popup window.