DUE TO SPAM, SIGN-UP IS DISABLED. Goto Selfserve wiki signup and request an account.
...
If
...
you
...
want
...
to
...
have
...
a
...
more
...
"web
...
2.0"
...
validation
...
on
...
your
...
forms
...
here
...
is
...
a
...
quick
...
way
...
to
...
do
...
it:
...
Using
...
the
...
Wicket
...
Example:
...
Ajax
...
Builtin:
...
FormPage
...
as
...
a
...
base,
...
the
...
onError
...
method
...
is
...
called
...
if
...
any
...
of
...
your
...
validators
...
fail,
...
in
...
there
...
you
...
need
...
to
...
view
...
the
...
children
...
components
...
attached
...
to
...
your
...
form
...
and
...
check
...
the
...
isValid()
...
method
...
on
...
each
...
one to determine if that component passed validation. A really easy to do this is the following:
| Code Block |
|---|
. A really easy to do this is the following: protected void onError(final AjaxRequestTarget target, Form form) { log.warn("onError Called"); // Safe way to view the children components... log.debug("onError called"); form.visitFormComponents(new FormComponent.IVisitor() { public void formComponent(FormComponent formComponent) { log.debug("Checking: " + formComponent.getMarkupId() + " " + formComponent.isValid()); if (\ if (!formComponent.isValid()) { Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â { // If this component failed validation, do something // fancy to display it to the user... target.addComponent(formComponent); Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â target.appendJavascript( "new Effect.Shake($(\'" + formComponent.getMarkupId() + "\'));"); Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â } } }); } The above example also adds in JavaScript effects borrowed from the Effects example using the script.aculo.us library. } } }); } |
The above example also adds in JavaScript effects borrowed from the Effects example using the script.aculo.us library.
| HTML Comment | ||
|---|---|---|
| ||
Everything below here was added by aakoch, a novice, so please, if there is something wrong, fix it! Thanks! |
| Note |
|---|
The above code won't compile under 1.3.0-BETA. |
Here's some code that will work with version 1.3.0-BETA.
| Code Block |
|---|
protected void onError(final AjaxRequestTarget target, final Form form) {
form.visitFormComponents(new IVisitor() {
public Object formComponent(IFormVisitorParticipant formVisitor) {
if (formVisitor instanceof FormComponent) {
FormComponent formComponent = (FormComponent) formVisitor;
if (!formComponent.isValid()){
// If this component failed validation, do something
// fancy to display it to the user...
target.addComponent(formComponent);
// do a little dance
target.appendJavascript(
"new Effect.Shake($('" + formComponent.getMarkupId() + "'));");
}
}
return formVisitor;
}
});
}
|
To update the feedback panel:
| Code Block |
|---|
protected void onError(final AjaxRequestTarget target, final Form form) {
// or update the feedback panel
target.addComponent(form.getPage().get("feedback"));
}
|