I've found the mistake: the TextField must override getStatelessHint() this
way:
@Override
protected boolean getStatelessHint()
{
return false;
}
now it works.
--
From: "Rut Bastoni"
Sent: Thursday, October 07, 2010 4:08 PM
To:
Subject: Help with custom component that implements IOnChangeListener
Hi everyone,
i'm trying to implement a custom TextField that fires "onchange" event
without using Ajax (it is a requirement of my project - i have good
reasons
not to use Ajax).
Looking at the source files of DropDownChoice, CheckBox etc. (they all
implement the "wantOnSelectionChangedNotifications()" mechanism) i created
a
class:
class OnChangeTextField extends TextField implements
IOnChangeListener
{
// . my stuff
@Override
public void onSelectionChanged()
{
updateModel();
onSelectionChanged(getModelObject());
}
protected void onSelectionChanged(final Object newSelection)
{
System.out.println("Event fired");
}
/**
* Processes the component tag - This is like DropDownChoice and other
default FormComponents di
*/
@Override
protected void onComponentTag(final ComponentTag tag)
{
// url that points to this components IOnChangeListener method
CharSequence url = urlFor(IOnChangeListener.INTERFACE);
Form form = findParent(Form.class);
if (form != null)
{
tag.put("onchange", form.getJsForInterfaceUrl(url));
}
super.onComponentTag(tag);
}
but that doesn't work. When i type into my textfield, i get an error page
saying:
WicketMessage: Attempt to access unknown request listener interface
IRedirectListener
Root cause:
org.apache.wicket.WicketRuntimeException: Attempt to access unknown
request
listener interface IRedirectListener
at org.apache.wicket.markup.html.form.Form.dispatchEvent(Form.java:1320)
at org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:870)
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:182)
at
org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73)
etc. etc.
I looked into the sources, in particular Form.java, it seems like the url
of
my listener (obtained by "urlFor(IOnChangeListener.INTERFACE)") is wrong,
because this is the value that get stored in the hidden fild of the form,
and when the form dispatches events, it does not cause the correct
IListenerInterfaceRequestTarget be created.
I wonder, why does this mechanism work on DropDownChoice and others, and
not
on my component?
Is this a bug? Or am I doing some mistake?
Thanks a Lot
Rut Bastoni
-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org
-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org