Re: onsubmit gets called after page reload

2016-07-04 Thread Iamuser
Hello,
Yes, and it works well, so thank you so much.



On Mon, Jul 4, 2016 at 5:36 PM, Sven Meier [via Apache Wicket] <
ml-node+s1842946n467502...@n4.nabble.com> wrote:

> The form is checking whether there are any errors before invoking your
> #onSubmit() method.
>
> Have you tried overriding #onConfigure()?
>
> Regards
> Sven
>
> --
> If you reply to this email, your message will be added to the discussion
> below:
>
> http://apache-wicket.1842946.n4.nabble.com/onsubmit-gets-called-after-page-reload-tp4675020p4675028.html
> To unsubscribe from onsubmit gets called after page reload, click here
> 
> .
> NAML
> 
>


--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/onsubmit-gets-called-after-page-reload-tp4675020p4675030.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



Re: onsubmit gets called after page reload

2016-07-04 Thread Sven Meier
The form is checking whether there are any errors before invoking your
#onSubmit() method.

Have you tried overriding #onConfigure()?

Regards
Sven

--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/onsubmit-gets-called-after-page-reload-tp4675020p4675028.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



Re: onsubmit gets called after page reload

2016-07-04 Thread Iamuser
Hello,
Please check the image. Hope this is helpful.
Thank you.

On Mon, Jul 4, 2016 at 9:44 AM, Sven Meier [via Apache Wicket] <
ml-node+s1842946n4675021...@n4.nabble.com> wrote:

> 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 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 {
> >
> > private static final long serialVersionUID = 1L;
> >
> > public UploadForm(String id, IModel docmodel) {
> > super(id, docmodel);
> > TextField fileDescription = new
> > TextField("fileDescription", new
> > PropertyModel(getModelObject(), "description"));
> > add(fileDescription);
> >
> > final LoadableDetachableModel> documentsModel = new
> > LoadableDetachableModel>() {
> >
> > private static final long serialVersionUID = 1L;
> >
> > @Override
> > protected List load() {
> > return SpringCtx.getAppDB(DocDao.class).selectByParentId(238);
> > }
> > };
> >
> > final WebMarkupContainer documentsContainer = new
> > WebMarkupContainer("documentsContainer");
> > documentsContainer.setOutputMarkupId(true);
> > add(documentsContainer);
> >
> > documentsContainer.add(new ListView("documentList", documentsModel)
> > {
> > private static final long serialVersionUID = 1L;
> >
> > @Override
> > protected void populateItem(ListItem item) {
> > item.add(new Label("document",
> > item.getModelObject().getDescription()));
> > }
> > @Override
> > public boolean isVisible() {
> > List 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));
> > }
> > }
> >
> > };
> >
> > 
> >
> > 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: [hidden email]
> 
> > For additional commands, e-mail: [hidden email]
> 
> >
>
>
> -
> To unsubscribe, e-mail: [hidden email]
> 
> For additional commands, e-mail: [hidden email]
> 
>
>
>
> --
> If you reply to this email, your message will be added to the discussion
> below:
>
> http://apache-wicket.1842946.n4.nabble.com/onsubmit-gets-called-after-page-reload-tp4675020p4675021.html
> To unsubscribe from onsubmit gets called after page reload, click here
> 
> .
> NAML
> 

Re: onsubmit gets called after page reload

2016-07-04 Thread Sven Meier

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 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 {

private static final long serialVersionUID = 1L;

public UploadForm(String id, IModel docmodel) {
super(id, docmodel);
TextField fileDescription = new
TextField("fileDescription", new
PropertyModel(getModelObject(), "description"));
add(fileDescription);

final LoadableDetachableModel> 
documentsModel = new
LoadableDetachableModel>() {

private static final long serialVersionUID = 1L;

@Override
protected List load() {
return 
SpringCtx.getAppDB(DocDao.class).selectByParentId(238);
}
};

final WebMarkupContainer documentsContainer = new
WebMarkupContainer("documentsContainer");
documentsContainer.setOutputMarkupId(true);
add(documentsContainer);

documentsContainer.add(new 
ListView("documentList", documentsModel)
{
private static final long serialVersionUID = 1L;

@Override
protected void populateItem(ListItem item) 
{
item.add(new Label("document",
item.getModelObject().getDescription()));
}
@Override
public boolean isVisible() {
List 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));
}
}

};



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...@wic