• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Validation error mesage is not display in browser

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All;

Please help me.This is my issue: I amnew struts2.Its going inside the validate() , but not display in browser.

Action class is:

public class UserAction extends ActionSupport {
private CountryDAO countryDAO = new CountryDAO();
private List<User> lstUser;
private User user;
private UserDAO userDAO = new UserDAO();



public UserAction(){
}

public User getUser() {
return user;
}

public void setUser(User user) {
this.user = user;
}

public String execute(){
try {
userDAO.persisteUserCountry(getUser().getCountry().getName(), user);
}catch(Exception e) {
System.out.println("----" + e.getMessage());
e.printStackTrace();
}
return SUCCESS;
}


public void validate(){

if(getUser().getUsername().length() == 0){
addActionMessage("User Name is required");
}

if(getUser().getPassword().length() == 0){
addActionMessage("Password is required");
}

if(getUser().getPassword().length() > 6){
addActionMessage( "Minimum passsword length is 6");
}

System.out.println("###########" + this.hasActionMessages());

}

My Jsp is like this:

<s:fielderror/>
<s:actionerror/>
<s:actionmessage/>


<s:actionmessage/>
<div id="result">Submit form bellow.</div>
<s:form action="accountTypeAction" >

<s:textfield name="user.username" label="Email" required="true" />
<!-- <s:textfield name="confirmEmail" key="label.confirmmail" size="20" /> -->
<s:password name="user.password" label="Password" required="true"/>

<s:select name="user.accountType" label="Account Type" list="#{'peronal':'peronal','company':'company'}" />
<s:select label="Country of residence" name="user.country.name" headerKey="- - -"
headerValue="Select Country"
list="#session.countries"
listKey="id"
listValue="name" />

and struts.xml is :
<struts>
<include file="struts-default.xml"/>

<!-- Configuration for the default package. -->

<package name="default" extends="struts-default">

<action name="accountType" class="com.providence.pgw.action.CountryAction">
<result name="success">userAccountType.jsp</result>
</action>

<action name="accountTypeAction" class="com.providence.pgw.action.UserAction">
<result name="input" type="redirect-action">accountType</result>
<result name="error" type="redirect-action">accountType</result>
<result name="success" >emailVarification.jsp</result>
</action>

<action name="emailVerify" class="com.providence.pgw.action.UserAction" method="displayPersonalInfo">
<interceptor-ref name="params" />
<interceptor-ref name="validation">
<param name="excludeMethods">displayPersonalInfo</param>
</interceptor-ref>
<result name="input" >activationKeyExit.jsp</result>
<result name="error" >errorActivationKey.jsp</result>
<result name="success">personalDetails.jsp</result>
</action>



</package>
</struts>

When I submit the form its going inside the validate method and redirect to input. But not display error message in browser.

Please anybody help me soon.

Thanks for advancce.



S.Piraba
 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Piraba please UseCodeTags when you post a source code.

I don't know why the code is not working (might be because of your interceptor configuration) but generally addFieldError method is used if you want to add an error message for a particular field...
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic