Here's my struts.xml
<struts>
<package name="noshame" extends="struts-default">
<action name="Register">
<result>/Register.jsp</result>
</action>
</package>
</struts>
my web.xml:
<web-app>
<display-name>NoShame</display-name>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
<init-param>
<param-name>actionPackages</param-name>
<param-value>com.naildrivin5.applications.noshame.client</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
My JSP:
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<body>
<s:form id="register" action="registerNew">
<s:fielderror><s:param>name</s:param></s:fielderror><s:textfield
required="true" name="name" label="Your Name" />
<s:textfield required="true" name="email" label="Email Address" />
<s:password required="true" name="password" label="Password" />
<s:password required="true" name="passwordConfirm" label="Confirm
Password" />
<input class="submitButton" type=submit>
</s:form>
</body>
</html>
My Action class:
@Results({
@Result(name="success", value="/Success.jsp"),
@Result(name="error", value="/Register.jsp")
})
@Validation()
public class RegisterNewAction
{
public String execute() throws Exception
{
// omittied boring logic
return "success";
}
private String itsName;
@RequiredFieldValidator(type = ValidatorType.FIELD, message =
"Name is required")
public void setName(String name) { itsName = name; }
public String getName() { return itsName; }
// omitted other accecssors
}
The docs for doing validation via XML indicate setting up some sort of
interceptor (but there is no real instruction for that, either), so is
there some annotation way I have to do that?
On 8/15/07, Laurie Harper <[EMAIL PROTECTED]> wrote:
> David Copeland wrote:
> > I'm a Struts newb and am trying to get up to speed on Struts 2.
> >
> > The scant documentation is throwing me a bit; I'm trying to do
> > everything annotation-based, and for Validation, it seems to be simply
> > not working at all.
> >
> > Per the docs, I have tagged my action class with @Validator and tagged
> > my setXXX method with @RequiredFieldValidator.
> >
> > My form's JSP contains <s:fielderror><s:param>XXX</s:param></s:fielderror>.
> >
> > When I submit the form with no value for XXX, my execute method
> > executes as it would before I added the validation stuff.
> >
> > I would really like to avoid XML files, but it seems that if I'm using
> > annotations, everything needs to be done that way.
>
> I'm not sure what that last paragraph means; you can certainly use XML
> validation for one action and annotations in another. I'm not sure to
> what extent it's possible to mix XML and annotation based validation in
> the *same* action, but there's certainly no requirement to pick one or
> the other for the application as a whole.
>
> It may help if you post the relevant parts of your config, JSP and
> action code. There are several 'moving parts' involved in making
> validation work, and it's hard to guess where the problem is without
> seeing what you have done.
>
> L.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]