I have a index.jsp
from which I am calling an action class TestAction
(on click of hyperlink) which have method(display) to load values for combobox from database along with execute method,to display on page test.jsp
.
On test.jsp
,I have some input fields along with combo boxes.On click of button on test.jsp I want to validate input fields,but problem is that when i am coming from index.jsp ,that time only validation is happening and test.jsp
opens with error messages.
I tried both client side validation using <ActionName>-validator.xml
as well as used server side validation by overriding validate method.How can avoid validation on click of hyperlink on index.jsp and can do it on button click on test.jsp.
Here is my code :
index.jsp :
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Data</title>
</head>
<body>
<s:form>
<a href="<s:url action="displayAction.action"/>" >Display Data</a><br>
</s:form>
</body>
</html>
test.jsp :
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Data</title>
<script type="text/javascript">
function openPopUp(){
document.getElementById('testForm').setAttribute('target', '_blank');
document.getElementById('testForm').setAttribute('action', 'testAction.action');
}
</script>
<s:head theme="ajax" debug="true"/>
</head>
<body bgcolor="white">
<s:form validate="true" id="testForm">
<div>
<s:actionerror/>
</div>
<table>
//Mapping of data from database
</table>
<s:submit id="submitButton" value="Display Chart" align="center" onclick="openPopUp();"/>
</s:form>
</body>
</html>
struts.xml
<action name="testAction"
class="testAction"
method="execute">
<result name="success" type="chart">
<param name="value">chart</param>
<param name="type">jpeg</param>
<param name="width">600</param>
<param name="height">400</param>
</result>
</action>
<action name="displayAction"
class="testAction"
method="display">
<result name="success">test.jsp</result>
</action>