Re: Updating a Label in a Form using AjaxFormComponentUpdatingBehavior

2009-04-29 Thread Ryan Norris

Wow.  Nice catch.

Lesson learned - be cautious with the m2eclipse plugin and the WTP  
when attching Javadocs to the library.


Thanks.

On Apr 28, 2009, at 10:55 PM, Jeremy Thomerson wrote:


You have the javadocs jar in your classpath.  It shouldn't be.  That
should fix the error page so that you can see your error (which should
also be visible in the logs anyway).

--
Jeremy Thomerson
http://www.wickettraining.com




On Tue, Apr 28, 2009 at 8:53 PM, Ryan Norris ryannor...@gmail.com  
wrote:

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 FormRegistration {
private static final long serialVersionUID = 1L;

private Registration _registration = new Registration();
private CityState _cityState = new CityState();

public RegistrationForm(String id) {
super(id);

add(new TextFieldString(emailAddress, new
PropertyModelString(_registration, emailAddress)));
add(new PasswordTextField(password, new
PropertyModelString(_registration, password)));
add(new TextFieldString(firstName, new
PropertyModelString(_registration, firstName)));
add(new TextFieldString(lastName, new
PropertyModelString(_registration, lastName)));
add(new TextFieldString(address1, new
PropertyModelString(_registration, address1)));
add(new TextFieldString(address2, new
PropertyModelString(_registration, address2)));
add(new TextFieldString(establishmentName, new
PropertyModelString(_registration, establishmentName)));

final Label cityStateLabel = new Label(cityState, new
PropertyModelString(_cityState, city));
cityStateLabel.setOutputMarkupId(true);

final TextFieldString zipCodeField = new
TextFieldString(zip, new PropertyModelString(_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

Updating a Label in a Form using AjaxFormComponentUpdatingBehavior

2009-04-28 Thread Ryan Norris
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 FormRegistration {
        private static final long serialVersionUID = 1L;

        private Registration _registration = new Registration();
        private CityState _cityState = new CityState();

        public RegistrationForm(String id) {
            super(id);

            add(new TextFieldString(emailAddress, new
PropertyModelString(_registration, emailAddress)));
            add(new PasswordTextField(password, new
PropertyModelString(_registration, password)));
            add(new TextFieldString(firstName, new
PropertyModelString(_registration, firstName)));
            add(new TextFieldString(lastName, new
PropertyModelString(_registration, lastName)));
            add(new TextFieldString(address1, new
PropertyModelString(_registration, address1)));
            add(new TextFieldString(address2, new
PropertyModelString(_registration, address2)));
            add(new TextFieldString(establishmentName, new
PropertyModelString(_registration, establishmentName)));

            final Label cityStateLabel = new Label(cityState, new
PropertyModelString(_cityState, city));
            cityStateLabel.setOutputMarkupId(true);

            final TextFieldString zipCodeField = new
TextFieldString(zip, new PropertyModelString(_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: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org