I've been struggling for a while now fighting with
AjaxFormComponentUpdatingBehavior and changing the value of a label
within form when a certain javascript precondition is met.
Code below.
public final class RegistrationForm extends Form<Registration> {
private static final long serialVersionUID = 1L;
private Registration _registration = new Registration();
private CityState _cityState = new CityState();
public RegistrationForm(String id) {
super(id);
add(new TextField<String>("emailAddress", new
PropertyModel<String>(_registration, "emailAddress")));
add(new PasswordTextField("password", new
PropertyModel<String>(_registration, "password")));
add(new TextField<String>("firstName", new
PropertyModel<String>(_registration, "firstName")));
add(new TextField<String>("lastName", new
PropertyModel<String>(_registration, "lastName")));
add(new TextField<String>("address1", new
PropertyModel<String>(_registration, "address1")));
add(new TextField<String>("address2", new
PropertyModel<String>(_registration, "address2")));
add(new TextField<String>("establishmentName", new
PropertyModel<String>(_registration, "establishmentName")));
final Label cityStateLabel = new Label("cityState", new
PropertyModel<String>(_cityState, "city"));
cityStateLabel.setOutputMarkupId(true);
final TextField<String> zipCodeField = new
TextField<String>("zip", new PropertyModel<String>(_registration,
"postalCode"));
zipCodeField.add(new AjaxFormComponentUpdatingBehavior("onKeyUp") {
private static final long serialVersionUID = 1L;
@Override
protected CharSequence getPreconditionScript() {
return "return $(\"input[name='zip']\").val().length == 5;";
}
@Override
protected void onUpdate(AjaxRequestTarget target) {
if(target != null) {
_log.info(String.format("Looking up postal
code: %1$s", _registration.getPostalCode()));
PostalCode pc =
_postalCodeManager.getLocaleDataForCode(_registration.getPostalCode());
_cityState.setCity(pc.getCity());
_cityState.setState(pc.getState());
target.addComponent(cityStateLabel);
}
}
});
add(zipCodeField);
add(cityStateLabel);
}
@Override
protected void onSubmit() {
try {
_accountManager.createAccount(_registration.getEmailAddress(),
_registration.getPassword());
} catch (DuplicateEmailAddressException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
The general gist is to display the city for a given input of 5
characters. The error I'm getting is completely unrelated...
exception
org.apache.wicket.WicketRuntimeException: Internal Error: Could not
render error page class
org.apache.wicket.markup.html.pages.InternalErrorPage
org.apache.wicket.request.AbstractRequestCycleProcessor.respond(AbstractRequestCycleProcessor.java:174)
org.apache.wicket.RequestCycle.step(RequestCycle.java:1321)
org.apache.wicket.RequestCycle.steps(RequestCycle.java:1370)
org.apache.wicket.RequestCycle.request(RequestCycle.java:501)
org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:455)
org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:288)
root cause
org.apache.wicket.markup.MarkupException: Tag '<DT>' (line 101, column
1) has a mismatched close tag at '</DL>' (line 102, column 1)
[markup =
jar:file:/C:/Documents%20and%20Settings/rnorris/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/web/WEB-INF/lib/wicket-1.4-rc2-javadoc.jar!/org/apache/wicket/markup/html/pages/ExceptionErrorPage.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<!--NewPage-->
So, aside from the exception being pretty useless - debugging things
gets me pretty deep in the weeds. Before I go through the trouble of
filing a JIRA ticket, can anyone tell me:
1. Is what I'm doing a covered use case (update a label in a form as
a result of a AjaxFormComponentUpdatingBehavior event)?
2. Is my approach expected to work? From the scattered documentation
I've found, this looks completely feasible.
3. Are there any known issues with the rendering and handling of
Errors in 1.4-rc2? This isn't the first time I've encountered some
really difficult to debug problems, but the fact that this is in an
AJAX scenario makes this really painful.
Thanks.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]