Hi,
I'm not sure which code is calling #isVisible() here, a stacktrace would
help to identify the caller.
Nevertheless it's quite normal for #isVisible() to be called a number of
times. Thus it's a recommended practice to override #onConfigure() instead:
@Override
public void onConfigure() {
List<Doc> docList = documentsModel.getObject();
setVisible(docList != null && docList.size() > 0);
}
Have fun
Sven
On 03.07.2016 21:36, Iamuser wrote:
Hello,
Please help me with the following situation:
I'm using wicket 6.
I have a page and a form.
On this form I have an input, and when user hits Upload button, the list
with the inputs should be updated.
However, there is a strange behaviour:
1. when hitting the submit button, the onsubmit method is not immediatelly
called, but instead
the isVisible() method is called on a repeated number of times, which then
calls Load() of the LoadableDetachableModel is called.
2. only after that the onSubmit() is finally called.
But this behaviour, because of the isVisible() method being called before
onSubmit() does not display the new item to the list on the page. Only after
a new refresh of the page it is finally displayed.
Here is the html and the java code:
private class UploadForm extends Form<Doc> {
private static final long serialVersionUID = 1L;
public UploadForm(String id, IModel<Doc> docmodel) {
super(id, docmodel);
TextField<String> fileDescription = new
TextField<String>("fileDescription", new
PropertyModel<String>(getModelObject(), "description"));
add(fileDescription);
final LoadableDetachableModel<List<Doc>>
documentsModel = new
LoadableDetachableModel<List<Doc>>() {
private static final long serialVersionUID = 1L;
@Override
protected List<Doc> load() {
return
SpringCtx.getAppDB(DocDao.class).selectByParentId(238);
}
};
final WebMarkupContainer documentsContainer = new
WebMarkupContainer("documentsContainer");
documentsContainer.setOutputMarkupId(true);
add(documentsContainer);
documentsContainer.add(new
ListView<Doc>("documentList", documentsModel)
{
private static final long serialVersionUID = 1L;
@Override
protected void populateItem(ListItem<Doc> item)
{
item.add(new Label("document",
item.getModelObject().getDescription()));
}
@Override
public boolean isVisible() {
List<Doc> docList =
documentsModel.getObject();
return docList != null && docList.size()
> 0;
}
}.setOutputMarkupId(true));
}
@Override
public void onSubmit() {
logger.debug("this is onsubmit()");
Doc d = new Doc();
try {
d.setFileName("test_fn");
d.setId(SpringCtx.getAppDB(DocDao.class).selectNextId());
d.setFileUrl("url");
d.setDescription(getModelObject().getDescription());
d.setParentId(238);
SpringCtx.getAppDB(DocDao.class).insert(d);
getModelObject().clear();
feedbackPanel.info(getString("upload.document.success"));
} catch (Exception e) {
logger.error("Error uploading user
file", e);
feedbackPanel.error(getString("upload.document.error") + " " +
ExceptionUtils.getRootCauseMessage(e));
}
}
};
<http://apache-wicket.1842946.n4.nabble.com/file/n4675020/1.png>
Please help me understand the issure. Thank you in advance.
--
View this message in context:
http://apache-wicket.1842946.n4.nabble.com/onsubmit-gets-called-after-page-reload-tp4675020.html
Sent from the Users forum mailing list archive at Nabble.com.
---------------------------------------------------------------------
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