You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@click.apache.org by foxesout <nk...@escholar.com> on 2012/02/22 18:06:44 UTC
How to not bind variables when the form is invalid?
Hello all..
I must have missed something fundamental in click... sorry if this question
is really silly.
I have a simple form with a couple of dates, i don't use any custom
validation, only what click provides.
When the date is invalid, i get an error on the page.
But the invalid request parameter is already bound to the page variable and
is used to render the page.
I must be doing something wrong. How can I tell click not to use the
invalid parameter when the page renders?
Thank you!
--
View this message in context: http://click.1134972.n2.nabble.com/How-to-not-bind-variables-when-the-form-is-invalid-tp7308872p7308872.html
Sent from the click-user mailing list archive at Nabble.com.
Re: How to not bind variables when the form is invalid?
Posted by foxesout <nk...@escholar.com>.
Thank you Scott. I'll give it a try but I think onGet is also called after
Init and that could be a problem for me...
Thanks for the reply!
--
View this message in context: http://click.1134972.n2.nabble.com/How-to-not-bind-variables-when-the-form-is-invalid-tp7308872p7314953.html
Sent from the click-user mailing list archive at Nabble.com.
Re: How to not bind variables when the form is invalid?
Posted by foxesout <nk...@escholar.com>.
Bob,
Thanks so much! That worked! For some reason I was avoiding putting some
extra code into data provider but looks like there is no problem with it.
This worked just fine.
Thanks so much!!
--
View this message in context: http://click.1134972.n2.nabble.com/How-to-not-bind-variables-when-the-form-is-invalid-tp7308872p7314958.html
Sent from the click-user mailing list archive at Nabble.com.
Re: How to not bind variables when the form is invalid?
Posted by Bob Schellink <sa...@gmail.com>.
Hi,
The DataProvider method is only called when the table needs the data, in
this case at render time. So the following should work:
public void onInit() {
table.setDataProvider(new DataProvider() {
public List<Customer> getData() {
if (form.isValid()) {
return getCustomerService().getCustomers();
} else {
return new ArrayList(); // <-- Return empty list
}
}
});
}
regards
Bob
On Thu, Feb 23, 2012 at 12:23 AM, Scott Gray <le...@gmail.com> wrote:
> Total noob here but you could possibly try extracting your
> dataProvider logic into a separate method and then calling it from
> onGet() for defaults and from onSubmit() for the actual searches.
>
> Regards
> Scott
>
> On 23 February 2012 10:27, foxesout <nk...@escholar.com> wrote:
> > Thank you Gilberto, i actually looked through all the links you reference
> > before posting.
> > I believe I didn't formulated the question right...
> >
> > When the form is submitted, the onInit() method is executed first and
> then
> > the onSubmit() - or so I believe.
> > I set the dataProvider for the page in the onInit() method and pass the
> > request parameters to it.
> >
> > So what happens is - even if the form is invalid, the dataProvider is set
> > and the page will be rendered using invalid request parameters.
> >
> > What I'd like is to not render any data (just an empty table) if the form
> > doesn't validate.
> >
> > At the same time, when the page first loads, the data is being displayed
> > using the default parameters, so form submission is not necessary to
> display
> > data. That's why i can't set dataProvider in the onSubmit method.
> >
> > Thank you!
> >
> >
> > --
> > View this message in context:
> http://click.1134972.n2.nabble.com/How-to-not-bind-variables-when-the-form-is-invalid-tp7308872p7309878.html
> > Sent from the click-user mailing list archive at Nabble.com.
>
Re: How to not bind variables when the form is invalid?
Posted by Scott Gray <le...@gmail.com>.
Total noob here but you could possibly try extracting your
dataProvider logic into a separate method and then calling it from
onGet() for defaults and from onSubmit() for the actual searches.
Regards
Scott
On 23 February 2012 10:27, foxesout <nk...@escholar.com> wrote:
> Thank you Gilberto, i actually looked through all the links you reference
> before posting.
> I believe I didn't formulated the question right...
>
> When the form is submitted, the onInit() method is executed first and then
> the onSubmit() - or so I believe.
> I set the dataProvider for the page in the onInit() method and pass the
> request parameters to it.
>
> So what happens is - even if the form is invalid, the dataProvider is set
> and the page will be rendered using invalid request parameters.
>
> What I'd like is to not render any data (just an empty table) if the form
> doesn't validate.
>
> At the same time, when the page first loads, the data is being displayed
> using the default parameters, so form submission is not necessary to display
> data. That's why i can't set dataProvider in the onSubmit method.
>
> Thank you!
>
>
> --
> View this message in context: http://click.1134972.n2.nabble.com/How-to-not-bind-variables-when-the-form-is-invalid-tp7308872p7309878.html
> Sent from the click-user mailing list archive at Nabble.com.
Re: How to not bind variables when the form is invalid?
Posted by foxesout <nk...@escholar.com>.
Thank you Gilberto, i actually looked through all the links you reference
before posting.
I believe I didn't formulated the question right...
When the form is submitted, the onInit() method is executed first and then
the onSubmit() - or so I believe.
I set the dataProvider for the page in the onInit() method and pass the
request parameters to it.
So what happens is - even if the form is invalid, the dataProvider is set
and the page will be rendered using invalid request parameters.
What I'd like is to not render any data (just an empty table) if the form
doesn't validate.
At the same time, when the page first loads, the data is being displayed
using the default parameters, so form submission is not necessary to display
data. That's why i can't set dataProvider in the onSubmit method.
Thank you!
--
View this message in context: http://click.1134972.n2.nabble.com/How-to-not-bind-variables-when-the-form-is-invalid-tp7308872p7309878.html
Sent from the click-user mailing list archive at Nabble.com.
Re: How to not bind variables when the form is invalid?
Posted by Gilberto <gi...@gmail.com>.
Hi, one thing that makes the Apache Click strong is your
documentation. I will list some references that probably can help:
User guide->request-param-auto-binding[1]
java doc ->Form validation[2]
Bob's article on explicit bind[3]
Hth,
Gilberto
[1] http://click.apache.org/docs/user-guide/htmlsingle/click-book.html#request-param-auto-binding
[2] http://click.apache.org/docs/click-api/org/apache/click/control/Form.html
[3] http://click-framework.blogspot.com/2010/09/apache-click-220-explicit-binding.html
On Wed, Feb 22, 2012 at 2:06 PM, foxesout <nk...@escholar.com> wrote:
> Hello all..
> I must have missed something fundamental in click... sorry if this question
> is really silly.
>
> I have a simple form with a couple of dates, i don't use any custom
> validation, only what click provides.
> When the date is invalid, i get an error on the page.
> But the invalid request parameter is already bound to the page variable and
> is used to render the page.
>
> I must be doing something wrong. How can I tell click not to use the
> invalid parameter when the page renders?
>
> Thank you!
>
> --
> View this message in context: http://click.1134972.n2.nabble.com/How-to-not-bind-variables-when-the-form-is-invalid-tp7308872p7308872.html
> Sent from the click-user mailing list archive at Nabble.com.