Hello, I am trying to create my first validation. I have two problems:
First one: I want to use Requieredstring validator. The problem is that my application is not complaining if I do leave the input field empty. Here is my code: reqisterqa.jsp: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ 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> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <link rel="stylesheet" href="../resources/css/mobiletrainingstyle.css" type="text/css" media="screen"> <title>Insert title here</title> </head> <body> <h3 class="redtext"><s:property value="message" /></h3> <s:form method="POST" action="postRegisterQAForm.action"> <s:textfield name="heading" label="Fråga" required="true"/> <s:textarea name="answer" label="Svar" cols="30" rows="15" required="true"/> <s:submit value="Spara" align="center"/> </s:form> </body> </html> struts.xml (part of): <package name="org.nicsoft.application.mobiletraining.qa" extends="struts-default"> <action name="postRegisterQAForm" class="org.nicsoft.application.mobiletraining.qa.RegisterQAFormAction"> <result name="input">/jsp/forms/registerqa.jsp</result> <result name="error">/jsp/forms/registerqa.jsp</result> <result>/jsp/forms/registerqa.jsp</result> </action> </package> RegisterQAForm class: package org.nicsoft.application.mobiletraining.qa; import java.io.IOException; import java.util.Map; import org.apache.struts2.interceptor.ParameterAware; import com.opensymphony.xwork2.ActionSupport; public class RegisterQAFormAction extends ActionSupport implements ParameterAware { public String message; public String heading; Map param; public String execute() throws Exception { System.out.println(param.get("heading")[0]); System.out.println(param.get("answer")[0]); QAHandler handleQA = new QAHandler(); handleQA.storeQA(param); setMessage("Ärende " + param.get("heading")[0] + " registrerat"); if (getHeading() != null){ return SUCCESS; } else{ return ERROR; } } public void setParameters(Map param) { this.param = param; } public void setMessage(String message){ this.message = message; } public String getMessage() { return message; } public void setHeading(String heading){ this.heading = heading; } public String getHeading(){ return this.heading; } } RegisterQAForm-validation.xml: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator 1.0.2//EN" "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd"> <validators> <field name="heading"> <field-validator type="requiredstring"> <param name="trim">true</param> <message>Heading Name is required</message> </field-validator> </field> </validators> I did put the RegisterQAForm-validation.xml in the same package as the class RegisterQAForm. Also tried to put it in the root/default package, no difference. Can anyone tell me what is the problem? Since I moved this mail-conversation from another mail that corrupted the mail, I include some questions from the old conversation here posted by Dave: Q: "why you're using ParameterAware" ... "it's generally cleaner to just use the action properties" A: The reason is because I found the instructions on the struts homepage. Using the action properties, I assume I need to define those in the struts.xml, correct? My second problem: I also want to use the Field Validator at some point. But it's some problem with the AbstractValidationActionSupport class. It isn't found. Anyone knows where this class is located? Couldn't find it in XWork where I though it's supposed to be. Q: "That class is part of the showcase app, not part of Struts itself." A: So what is the solution? The instructions wasn't that clear about where the class came from on the instruction page: http://struts.apache.org/2.1.6/docs/using-field-validators.html Thank you in advance! Regards, Niklas --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@struts.apache.org For additional commands, e-mail: user-h...@struts.apache.org