You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Adam Ruggles <a....@gmail.com> on 2008/10/29 06:24:30 UTC
Struts 2.1.2 client side validation doesn't get generated
I'm trying to get struts to spit out the client side validation code and it
doesn't seem to be working. The backend validation is working fine but when
I use the xhtml theme with the <s:head />, the script code under the form is
not being generated.
Looking at the code it looks like it's failing this check
"parameters.performValidation?default(false) == true" in the
form-close-validate.ftl file. What would cause the performValidation not to
be set as true?
I'm using annotations to markup my action.
public class TestAction extends ActionSupport {
private String username, email, password, password2;
@Override
public String execute() {
return SUCCESS;
}
public String save() {
// Do stuff and return SUCCESS ...
}
@RequiredStringValidator(message = "Required Field.", key =
"validation.required")
@EmailValidator(message = "Enter a valid email.", key = "validation.email")
public String getEmail() {
return email;
}
@RequiredStringValidator(message = "Required Field.", key =
"validation.required")
@StringLengthFieldValidator(trim = true, minLength = "3" , maxLength =
"16",
message = "Must be between ${minLength} and ${maxLength}.", key =
"validation.length")
public String getPassword() {
return password;
}
@FieldExpressionValidator(expression = "password2.equals(password)",
message = "Passwords do not match.", key = "validation.match.passwords")
@RequiredStringValidator(message = "Required Field.", key =
"validation.required")
public String getPassword2() {
return password2;
}
@RequiredStringValidator(message = "Required Field.", key =
"validation.required")
@StringLengthFieldValidator(trim = true, minLength = "3" , maxLength =
"16",
message = "Must be between ${minLength} and ${maxLength}.", key =
"validation.length")
public String getUsername() {
return username;
}
public void setEmail(final String email) {
this.email = email;
}
public void setPassword(final String password) {
this.password = password;
}
public void setPassword2(final String password2) {
this.password2 = password2;
}
public void setUsername(final String username) {
this.username = username;
}
}
here is my form code:
<s:form label="Test Form" id="save3" action="save" namespace="/install"
validate="true" theme="xhtml" cssClass="form-large">
<s:textfield key="username" required="true" theme="xhtml" />
<s:textfield key="email" required="true" theme="xhtml" />
<s:password key="password" required="true" theme="xhtml" />
<s:password key="password2" required="true" theme="xhtml"/>
<s:submit key="save" theme="xhtml" />
</s:form>
struts.xml
<!-- Constant Settings -->
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.codebehind.pathPrefix" value="/WEB-INF/pages/"/>
<constant name="struts.url.includeParams" value="none" />
<constant name="struts.custom.i18n.resources" value="global-messages" />
<constant name="struts.objectFactory" value="guice" />
<constant name="guice.module" value="test.util.ConfigurationModule" />
<!-- Development Settings "Change these when going to production" -->
<constant name="struts.devMode" value="true" />
<constant name="struts.i18n.reload" value="true" />
<constant name="struts.configuration.xml.reload" value="true" />
<package name="test" namespace="/install" extends="struts-default">
<action name="index" class="test.action.TestAction">
<result>/WEB-INF/pages/index.jsp</result>
</action>
<action name="save" class="test.action.TestAction" method="save">
<result name="success">/WEB-INF/pages/success.jsp</result>
<result name="input">/WEB-INF/pages/index.jsp</result>
<result name="error">/WEB-INF/pages/error/default.jsp</result>
</action>
</package>
--
View this message in context: http://www.nabble.com/Struts-2.1.2-client-side-validation-doesn%27t-get-generated-tp20221161p20221161.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts 2.1.2 client side validation doesn't get generated
Posted by Adam Ruggles <a....@gmail.com>.
Anyone? The server side validation works fine, when I post the form it comes
back with the correct validation but the client side is not being generated
because the performValidation is being set to false.
The obvious work around is to edit the form-close-validate.ftl and remove
(parameters.performValidation?default(false) == true), but why does this
performValidation there? Especially since the form-validate doesn't make
the same check and generates the return function.
--
View this message in context: http://www.nabble.com/Struts-2.1.2-client-side-validation-doesn%27t-get-generated-tp20221161p20240335.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Struts 2.1.2 client side validation doesn't get generated
Posted by Adam Ruggles <a....@gmail.com>.
It looks like this is a Google Guice issue. When I swapped the guice plugin
for the spring plugin everything worked as expected.
--
View this message in context: http://www.nabble.com/Struts-2.1.2-client-side-validation-doesn%27t-get-generated-tp20221161p20240986.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org