Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

Use of validation interceptor with alias interceptor in struts2

Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I have implemented alias interceptor. Now when i implement the validation interceptor the validation works fine but the error message is not shown. The reason I understand is due to the difference in field name in the action and jsp pages, Request your assistance to fix.

The code listing is as given below....

The index.jsp file is

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
<%@ taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">;
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Struts 2</title>
<s:form action="hello">
<s:textfield label="User Name" name="username"/> <br/>
<s:textfield label="User password" name="userpwd"/> <br/>
<s:textfield label="Field 1" name="scrField1"/> <br/>
<s:textfield label="Field 2" name="scrField2"/> <br/>
<s:submit value="Say Hello"/>


The HelloAction is as given below


import com.opensymphony.xwork2.ActionSupport;

public class HelloAction extends ActionSupport{

private String name;
private String password;
private String field1;
private String field2;

public String getName() {
return name;

public void setName(String nm) { = nm;

public String getPassword() {
return password;

public void setPassword(String password) {
this.password = password;

public String getField1() {
System.out.println("inside HelloAction.getField1 field1 =="+field1);
return field1;

public void setField1(String scrField1) {

this.field1 = scrField1;
System.out.println("inside HelloAction.setField1 field1=="+field1);

public String getField2() {
System.out.println("inside HelloAction.getField2 field2 =="+field2);
return field2;

public void setField2(String scrField2) {
this.field2 = scrField2;

public String execute() throws Exception{
return "success";


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "">;
<constant name="struts.devMode" value="true" />
<package name="helloworld" extends="struts-default">
<action name="hello" class="" method="execute">

<param name="aliases">#{ 'username' : 'name','userpwd' : 'password', 'scrField1' : 'field1', 'scrField2' : 'field2'}</param>

<interceptor-ref name="alias">
<param name="excludeMethods">input,back,cancel,browse</param>

<interceptor-ref name="validation">
<param name="excludeMethods">input,back,cancel,browse</param>
<interceptor-ref name="workflow">
<param name="excludeMethods">input,back,cancel,browse</param>

<result name="success">/MainPage.jsp</result>
<result name="input">/index.jsp</result>
HelloAction-validation is as given below
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE validators PUBLIC "-//Apache Struts//XWork Validator 1.0.3//EN"
<field name="name" >
<field-validator type="requiredstring">
<message >User Name is Required.</message>

You guys wanna see my fabulous new place? Or do you wanna look at this tiny ad?
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic