Ok, so that 'almost' wraps this up. HypbridUrlCodingStrategy works perfectly
for the Ajax-added data.
My last problem is related to the form fields. In
AjaxFallbackButton.onSubmit ... I clean out the input that holds the value
I've just added to the database and redisplayed in a list to the user. But,
on subsequent manual browser refresh, the INPUT that I wiped refreshes with
the user's LAST INPUT.
I don't mind this for the title, content or other input fields on the page -
but I don't want values showing up that I manually removed. I think this is
part of standard browser/form fields behavior.
I think Mike's approach would work here: ie: javascript that clears this
input out on load. I 'never' want any values in this input on load. I know
how to write an IHeaderContributor - is there something similar to add a
body=onload? If not, my specific page (Java/html) doesn't really create the
<body> tag ... what is the best way to grab it so that I can possibly add a
behavior that would create an onLoad handler.
Or, is there a better, wicket way to make sure this input is empty on
browser refresh?
Thanks,
-Luther
// add a category to the view
// and clean out input that supplied it
// dbase code intentionally left out
final AjaxFallbackButton addCategoryButton = new
AjaxFallbackButton("add-category", new ResourceModel("m-add-category"),
this)
{
private static final long serialVersionUID = 1L;
@Override
protected void onSubmit(final AjaxRequestTarget target,
final Form<?> form)
{
final IModel<String> model =
categoryCandidate.getModel();
final String text = model.getObject();
// make sure we should actually do something
if (text == null)
{
return;
}
// cleans out the form.INPUT
model.setObject(new String());
// add the new text to the categoriesModel (custom Set)
categoriesModel.add(text);
// redraw the form.INPUT
target.addComponent(categoryCandidate);
// redraw the <li> of categories
target.addComponent(categoriesParent);
}
};
To test the idea ... this works when placed in the markup after the input I
want to clean out:
<script type="text/javascript">
document.getElementById("category_candidate1e").value =
'';
</script>
But I can't leave this embedded in the HTML ... and I guess the ID can
change per wicket's whim. I need to add this to an body.onload event as a
behavior --- how to do I get ahold of the <body> element from within my
Page.java?