You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Troy Cauble <tr...@gmail.com> on 2009/07/30 06:45:24 UTC
reloading DropDownChoice choices
I have the following
Page
Form
DDC
TextFields
Buttons
The DDC has a LoadableDetachableModel with a hibernate call for
the *choices* model and "new Model()" for the DDC model.
Changing the DDC selection, changes the TextFields appropriately.
But I have a Button and a form submit that change the hibernate data for
the choices. They also clear the DDC selection with
ddc.setModelObject(null).
How do I get the DDC to reload the choices? The old choices are visible
unless I reload the page. I have a printf in ldm.load() that tells me it is
not
being called until I reload the page.
Thanks!
-troy
Re: reloading DropDownChoice choices
Posted by Troy Cauble <tr...@gmail.com>.
Well, I found some detachable model documentation and figured it out.
LDM::detach() will cause a getObject() call to load(). Putting detach early
in my Form::submit() was sufficient for this example.
Another wrinkle was that I also had a Button with the same issue and putting
detach() in Button::onSubmit() was not work. Changing the Button to a Link
and using onClick() did, though.
-troy
On Thu, Jul 30, 2009 at 7:29 PM, Troy Cauble <tr...@gmail.com> wrote:
> Here's a minimal example of my problem.
> Again, the LDM::getObject() call AFTER the onSubmit()
> call that changes the data does not result in a LDM::load().
>
> There's a load() before the onSubmit(), but that's too early.
>
> Anyone? What am I missing?
>
> Thanks,
> -troy
>
>
> [jetty] DDC choices LDM: getObject
> [jetty] DDC choices LDM: load(reading choices)
> [jetty] DDC choices LDM: onAttach
> [jetty] Form onSubmit
> [jetty] DDC choices LDM: getObject
> [jetty] DDC choices LDM: onDetach
> [jetty]
>
>
>
> <?xml version="1.0" encoding="UTF-8"?>
> <html>
> <head></head>
> <body>
> Pressing the button adds an entry to the drop down list,
> but you can't see it without reloading the page.
> <br/>
> What am I missing?
> <div style="position:relative; left:10px;">
> <br/>
> <form wicket:id="form" style="position:relative; left:10px;">
> <select wicket:id="ddc"/>
> <input type="submit" value="add an entry"/>
> </form>
> </div>
> </body>
> </html>
>
> package dummy;
>
> import java.util.*;
>
> import org.apache.wicket.PageParameters;
> import org.apache.wicket.markup.html.WebPage;
> import org.apache.wicket.markup.html.form.*;
> import org.apache.wicket.model.*;
>
> public class Dummy extends WebPage
> {
> private static final long serialVersionUID = 1L;
>
> private ArrayList<String> choices = new ArrayList<String>();
> private Integer item = new Integer(1);
>
> public Dummy(final PageParameters parameters)
> {
> super(parameters);
>
> choices.add(item.toString());
>
> IModel choicesModel = new LoadableDetachableModel() {
> private static final long serialVersionUID = 1L;
> @Override
> protected void onAttach() {
> System.out.println("DDC choices LDM: onAttach");
> super.onAttach();
> }
> @Override
> protected void onDetach() {
> System.out.println("DDC choices LDM: onDetach\n");
> super.onDetach();
> }
> @Override
> public Object getObject() {
> System.out.println("DDC choices LDM: getObject");
> return super.getObject();
> }
> @Override
> protected Object load() {
> System.out.println("DDC choices LDM: load(reading
> choices)");
> // Note the clone() --
> // to simulate a hibernate pull
> return choices.clone();
> }
> };
>
> final DropDownChoice ddc = new DropDownChoice("ddc",
> new Model(), choicesModel);
>
> Form form = new Form("form") {
>
> private static final long serialVersionUID = 1L;
>
> @Override
> protected void onSubmit()
> {
> System.err.printf("Form onSubmit\n");
> ddc.setModelObject(null);
> choices.add((++item).toString());
> }
> };
>
> add(form);
> form.add(ddc);
> }
> }
>
>
Re: reloading DropDownChoice choices
Posted by Troy Cauble <tr...@gmail.com>.
Here's a minimal example of my problem.
Again, the LDM::getObject() call AFTER the onSubmit()
call that changes the data does not result in a LDM::load().
There's a load() before the onSubmit(), but that's too early.
Anyone? What am I missing?
Thanks,
-troy
[jetty] DDC choices LDM: getObject
[jetty] DDC choices LDM: load(reading choices)
[jetty] DDC choices LDM: onAttach
[jetty] Form onSubmit
[jetty] DDC choices LDM: getObject
[jetty] DDC choices LDM: onDetach
[jetty]
<?xml version="1.0" encoding="UTF-8"?>
<html>
<head></head>
<body>
Pressing the button adds an entry to the drop down list,
but you can't see it without reloading the page.
<br/>
What am I missing?
<div style="position:relative; left:10px;">
<br/>
<form wicket:id="form" style="position:relative; left:10px;">
<select wicket:id="ddc"/>
<input type="submit" value="add an entry"/>
</form>
</div>
</body>
</html>
package dummy;
import java.util.*;
import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.*;
import org.apache.wicket.model.*;
public class Dummy extends WebPage
{
private static final long serialVersionUID = 1L;
private ArrayList<String> choices = new ArrayList<String>();
private Integer item = new Integer(1);
public Dummy(final PageParameters parameters)
{
super(parameters);
choices.add(item.toString());
IModel choicesModel = new LoadableDetachableModel() {
private static final long serialVersionUID = 1L;
@Override
protected void onAttach() {
System.out.println("DDC choices LDM: onAttach");
super.onAttach();
}
@Override
protected void onDetach() {
System.out.println("DDC choices LDM: onDetach\n");
super.onDetach();
}
@Override
public Object getObject() {
System.out.println("DDC choices LDM: getObject");
return super.getObject();
}
@Override
protected Object load() {
System.out.println("DDC choices LDM: load(reading
choices)");
// Note the clone() --
// to simulate a hibernate pull
return choices.clone();
}
};
final DropDownChoice ddc = new DropDownChoice("ddc",
new Model(), choicesModel);
Form form = new Form("form") {
private static final long serialVersionUID = 1L;
@Override
protected void onSubmit()
{
System.err.printf("Form onSubmit\n");
ddc.setModelObject(null);
choices.add((++item).toString());
}
};
add(form);
form.add(ddc);
}
}
Re: reloading DropDownChoice choices
Posted by Troy Cauble <tr...@gmail.com>.
It seems my problem may be with the use of LoadableDetachableModel.
Below is print statement debugging of a Button action that alters
the DDC choices.
[jetty] DDC choices LDM: getObject
[jetty] DDC choices LDM: load(reading docs)
[jetty] DDC choices LDM: onAttach
[jetty] delete doc Button submit
[jetty] DDC choices LDM: getObject
[jetty] DDC choices LDM: onDetach
The Button submit changes the list, the following LDM getObject() does
not result in a load() call. Am I using LDM wrong? Do I need to be
tickling the LDM or DDC somehow?
Thanks,
-troy
On Thu, Jul 30, 2009 at 12:45 AM, Troy Cauble <tr...@gmail.com> wrote:
> I have the following
>
> Page
> Form
> DDC
> TextFields
> Buttons
>
> The DDC has a LoadableDetachableModel with a hibernate call for
> the *choices* model and "new Model()" for the DDC model.
>
> Changing the DDC selection, changes the TextFields appropriately.
>
> But I have a Button and a form submit that change the hibernate data for
> the choices. They also clear the DDC selection with
> ddc.setModelObject(null).
>
> How do I get the DDC to reload the choices? The old choices are visible
> unless I reload the page. I have a printf in ldm.load() that tells me it
> is not
> being called until I reload the page.
>
> Thanks!
> -troy
>