struts validator woes (newbie)

T

talisman

i'm having a problem getting a simple struts validator example to
output any errors

using netbeans 3.6, the forms appear and submit ok, but no html:errors
output at all, or console output errors relating to validator.

any suggestions to debug?



i've included files below, TestForm.jsp is the form.



thanks










*** TestForm.jsp

<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<html:html>
<head>
<title>test form </title>

</head>
<body bgcolor="white">
<B>This is a template STRUTS APP</b>
Please enter your name:
<html:form action="/TestAction" >

<html:text property="ipString" size="50"/>

<html:submit property="submit" value="Submit" />

</html:form>


</body>
</html:html>





*** /WEB_INF/struts-config

<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration
1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">



<!--

This is a blank Struts configuration file with an example

welcome action/page and other commented sample elements.



Tiles and the Struts Validator are configured using the factory
defaults

and are ready-to-use.



NOTE: If you have a generator tool to create the corresponding
Java classes

for you, you could include the details in the "form-bean"
declarations.

Otherwise, you would only define the "form-bean" element itself,
with the

corresponding "name" and "type" attributes, as shown here.

-->





<struts-config>



<!-- ==================================== Data Source Configuration
-->

<!--

<data-sources>

<data-source>

<set-property

property="autoCommit"

value="false"/>

<set-property

property="description"

value="Example Data Source Configuration"/>

<set-property

property="driverClass"

value="org.postgresql.Driver"/>

<set-property

property="maxCount"

value="4"/>

<set-property

property="minCount"

value="2"/>

<set-property

property="password"

value="mypassword"/>

<set-property

property="url"

value="jdbc:postgresql://localhost/mydatabase"/>

<set-property

property="user"

value="myusername"/>

</data-source>

</data-sources>

-->



<!-- ======================================== Form Bean Definitions
-->



<form-beans>



<!-- sample form bean descriptor for an ActionForm

<form-bean

name="inputForm"

type="app.InputForm"/>

end sample -->

<form-bean name="TestFormBean"
type="com.openstack.struts.testapp.TestFormBean"/>

<!-- sample form bean descriptor for a DynaActionForm

<form-bean

name="logonForm"

type="org.apache.struts.action.DynaActionForm">

<form-property

name="username"

type="java.lang.String"/>

<form-property

name="password"

type="java.lang.String"/>

end sample -->



</form-beans>





<!-- ================================= Global Exception Definitions
-->



<global-exceptions>

<!-- sample exception handler

<exception

key="expired.password"

type="app.ExpiredPasswordException"

path="/changePassword.jsp"/>

end sample -->

</global-exceptions>





<!-- =================================== Global Forward Definitions
-->



<global-forwards>

<!-- Default forward to "Welcome" action -->

<!-- Demonstrates using index.jsp to forward -->

<forward

name="welcome"

path="/Welcome.do"/>

</global-forwards>





<!-- =================================== Action Mapping Definitions
-->



<action-mappings>



<!-- Default "Welcome" action -->

<!-- Forwards to Welcome.jsp -->

<action

path="/Welcome"

type="org.apache.struts.actions.ForwardAction"

parameter="/pages/Welcome.jsp">

</action>

<action

path="/TestAction"

type="com.openstack.struts.testapp.TestActionHandler"

name="TestFormBean"

scope="request"

input = "TestForm"

validate="true">



<forward name="success" path="/TestResult.jsp"/>

</action>



<!-- sample input and input submit actions



<action

path="/Input"

type="org.apache.struts.actions.ForwardAction"

parameter="/pages/Input.jsp"/>



<action

path="/InputSubmit"

type="app.InputAction"

name="inputForm"

scope="request"

validate="true"

input="/pages/Input.jsp"/>



end samples -->





</action-mappings>





<!-- ===================================== Controller Configuration
-->



<controller

processorClass="org.apache.struts.tiles.TilesRequestProcessor"/>

<!-- ================================ Message Resources Definitions
-->

<!-- message resources -->
<message-resources
parameter="ApplicationResources"
null="false" />


<!-- comment following if struts1.0.x -->
<plug-in className="org.apache.struts.tiles.TilesPlugin" >
<set-property property="definitions-config"
value="/WEB-INF/tiles-defs.xml" />
<set-property property="moduleAware" value="true" />
<set-property property="definitions-parser-validate" value="true"
/>
</plug-in>

<!-- end comment if struts1.0.x -->

<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property
property="pathnames"
value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>

</struts-config>



**** /WEB_INF/validation

<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE form-validation PUBLIC
"-//Apache Software Foundation//DTD Commons Validator Rules
Configuration 1.0//EN"
"http://jakarta.apache.org/commons/dtds/validator_1_0.dtd">

<form-validation>

<!--
This is a blank Validator form file with a commented examples.
-->

<global>

<!-- An example global constant
<constant>
<constant-name>postalCode</constant-name>
<constant-value>^\d{5}\d*$</constant-value>
</constant>
end example-->

</global>

<formset>

<form name="TestForm">
<field property="ipString"
depends="required,integer">
<arg0 key="display.ipString"/>
</field>
</form>


<!-- An example form
<form name="logonForm">
<field
property="username"
depends="required">
<arg0 key="logonForm.username"/>
</field>
<field
property="password"
depends="required,mask">
<arg0 key="logonForm.password"/>
<var>
<var-name>mask</var-name>
<var-value>^[0-9a-zA-Z]*$</var-value>
</var>
</field>
</form>
end example form -->

</formset>

<!-- An example formset for another locale
<formset language="fr">

<constant>
<constant-name>postalCode</constant-name>
<constant-value>^[0-9a-zA-Z]*$</constant-value>
</constant>

</formset>
-->

</form-validation>








**** TestFormBean.java



package com.openstack.struts.testapp;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
//import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.validator.ValidatorForm;



public final class TestFormBean extends ValidatorForm {

private String action = "Create";
private String ipString = null;

public void reset(ActionMapping mapping, HttpServletRequest request) {

this.action = "Create";
this.ipString = "Reseted";

}

/**
* Getter for property action.
* @return Value of property action.
*/
public java.lang.String getAction() {
return action;
}

/**
* Setter for property action.
* @param action New value of property action.
*/
public void setAction(java.lang.String action) {
this.action = action;
}

/**
* Getter for property ipString.
* @return Value of property ipString.
*/
public java.lang.String getIpString() {
return ipString;
}

/**
* Setter for property ipString.
* @param ipString New value of property ipString.
*/
public void setIpString(java.lang.String ipString) {
this.ipString = ipString;
}

}







********** TestActionHandler.java



package com.openstack.struts.testapp;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Locale;
import java.util.Vector;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import org.apache.struts.validator.ValidatorActionForm;

import com.openstack.struts.testapp.*;

public final class TestActionHandler extends Action {

public ActionForward perform(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)

throws IOException, ServletException {




TestFormBean tform = (com.openstack.struts.testapp.TestFormBean)
form;


String tmpStr = "Welcome " + tform.getIpString() + " !";
tform.setIpString(tmpStr);

request.setAttribute("TestFormBean", tform);

return (mapping.findForward("success"));




}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top