You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@click.apache.org by Haim Schindler <ha...@gmail.com> on 2011/04/29 11:08:00 UTC
Forms question.
Hello,
I am not sure what is the right way to use forms.
Sometimes its a problem when the form has to be constructed again after
submit and before the callback is called.
Example:
in url I type:
*www.mysite.com/clickPage?p=100*
then in the click page I *create a form*.
based on the url parameter "*p=100*" in the form creation I do:
...
Integer calculatedNumber = dbService.loadData(*p*);
form.add(new *HiddenField*("calculatedNumber", *calculatedNumber*));
...
I dont keep the "p" as a HIDDEN field in the form since I dont need it
anymore. all I care about now, is "*calculatedNumber*"
the user clicked "*SUBMIT"
*now, the calls should go to "*onSubmit*"
but before that, the form needs to be recreated, and it needs "*p*" to do
so.
but "*p*" is *not *there anymore and then I get exception
Am I missing something ?
Thank you
Haim Schindler
Re: Forms question.
Posted by Gilberto <gi...@gmail.com>.
On Fri, Apr 29, 2011 at 7:24 AM, Haim Schindler <ha...@gmail.com>wrote:
> on the first request to:
>
>
> www.mysite.com/clickPage?p=100
>
> the page was loaded and then:
>
> 1. based on "p=100" I do consuming calculation to calculate
> "calculatedValue"
> 2. now, I create the form, having "calculatedValue" as HiddenField. (I
> dont need the state "p" anymore for next steps)
>
> When submitting the form, page is called again (for second time), but now,
> the value of "p" is not relevant anymore (it could also be many "p"'s like:
> "p1", "p2", ... , "p100").
> I want to handle the "post" request, and for that I need only
> "calculatedValue" I dont care about "p" now.
> But because the way Click works, I have to construct the FORM again so
> "onSubmit" will be executed. why should I ? I am not going to render the
> form again, I just want to process the "onSubmit" call and then decide to
> redirect to somewhere else. (in other words, I dont need the data the I
> needed before to construct the form)
>
>
>
When you do www.mysite.com/clickPage?p=100 you are doing a get request. I
usually put a public variable - in this case P - in the page and in the
onGet() I do initialize the form fields that I need so:
<quote>
/** Bindable variables(ID, used on the Get method) can automatically
have their value set by request parameters */
public String id;
/** Bindable variables(used to track where the page was requested) can
automatically have their value set by request parameters */
public String referrer;
private EntityManager em = EntityManagerContext.getEntityManager();
.
.
.
public void onGet() {
System.out.println("\n onGet() method \n");
if (id != null) {
Vehicle vehicle = em.find(Vehicle.class, id);
if (vehicle != null) {
// Copy vehicle data to form. The idField value will be set
by
// this call
form.copyFrom(vehicle);
//id parameter of the page is NOT null, then isNew=false
isNewField.setValueObject(false);
//it is the PK, here we can't change it, whick in this case
idField
//is not a HiddenField
idField.setReadonly(true);
}
} else {
//id parameter of the page is null, then isNew=true
isNewField.setValueObject(true);
}
if (referrer != null) {
// Set referrerField HiddenField to bound referrer field
referrerField.setValue(referrer);
}
}
</quote>
Hth,
Gilberto
Re: Forms question.
Posted by Bob Schellink <sa...@gmail.com>.
On second read I think I understand better. Looks like you have a
multi step process where you first do an expensive operation and then
on the second post to the same form you don't want to perform the
expensive operation. Almost like a wizard? In this case you might want
to think of moving to a another page for confirming the calculated
value?
But Click will have to construct the Form again to handle the submit
button click. You could also put a conditional around the form
creation eg. depending on wheather P is present and instead use the
page onPost method for handling the final post request.
Bob
On Fri, Apr 29, 2011 at 12:43 PM, Bob Schellink <sa...@gmail.com> wrote:
> I dont understand the problem then. Yes the form needs to be
> constructed again because Click need to process the submit button on
> the second request to invoke onSubmit. Also you might want to retrieve
> the value from a field in your Page. If the form and fields are not
> constructed, how will you retrieve the value? You will need to parse
> it directly from the request.
>
> You could always place an if-then-else to conditionally build the form
> or even POST your form to another page that doesn't contain the form.
> But I wouldn't recommend it.
>
> What is your concern with the fact that the form is created again?
>
> Bob
>
> On Fri, Apr 29, 2011 at 12:24 PM, Haim Schindler
> <ha...@gmail.com> wrote:
>> on the first request to:
>>
>> www.mysite.com/clickPage?p=100
>>
>> the page was loaded and then:
>>
>> 1. based on "p=100" I do consuming calculation to calculate
>> "calculatedValue"
>> 2. now, I create the form, having "calculatedValue" as HiddenField. (I dont
>> need the state "p" anymore for next steps)
>>
>> When submitting the form, page is called again (for second time), but now,
>> the value of "p" is not relevant anymore (it could also be many "p"'s like:
>> "p1", "p2", ... , "p100").
>> I want to handle the "post" request, and for that I need only
>> "calculatedValue" I dont care about "p" now.
>> But because the way Click works, I have to construct the FORM again so
>> "onSubmit" will be executed. why should I ? I am not going to render the
>> form again, I just want to process the "onSubmit" call and then decide to
>> redirect to somewhere else. (in other words, I dont need the data the I
>> needed before to construct the form)
>>
>>
>>
>> On Fri, Apr 29, 2011 at 12:45 PM, Bob Schellink <sa...@gmail.com> wrote:
>>>
>>> This is fundamental to stateless, share nothing architectures. Each
>>> request needs all the information in order to satisfy the action. In
>>> your case you need p otherwise you cannot construct the form. There
>>> are geneally two options:
>>> - store P in the session
>>> - store P in a hiddenField and bind it's value explicitly if you need
>>> it before the onProcess event eg. during onInit:
>>> ClickUtils.bind(pField);
>>> pField.getValue();
>>>
>>> regards
>>>
>>> Bob
>>>
>>> On Fri, Apr 29, 2011 at 11:08 AM, Haim Schindler
>>> <ha...@gmail.com> wrote:
>>> > Hello,
>>> >
>>> > I am not sure what is the right way to use forms.
>>> > Sometimes its a problem when the form has to be constructed again after
>>> > submit and before the callback is called.
>>> >
>>> > Example:
>>> >
>>> > in url I type:
>>> >
>>> > www.mysite.com/clickPage?p=100
>>> >
>>> > then in the click page I create a form.
>>> > based on the url parameter "p=100" in the form creation I do:
>>> > ...
>>> > Integer calculatedNumber = dbService.loadData(p);
>>> > form.add(new HiddenField("calculatedNumber", calculatedNumber));
>>> > ...
>>> >
>>> > I dont keep the "p" as a HIDDEN field in the form since I dont need it
>>> > anymore. all I care about now, is "calculatedNumber"
>>> >
>>> > the user clicked "SUBMIT"
>>> >
>>> > now, the calls should go to "onSubmit"
>>> > but before that, the form needs to be recreated, and it needs "p" to do
>>> > so.
>>> > but "p" is not there anymore and then I get exception
>>> >
>>> > Am I missing something ?
>>> >
>>> > Thank you
>>> > Haim Schindler
>>> >
>>
>>
>
Re: Forms question.
Posted by Bob Schellink <sa...@gmail.com>.
I dont understand the problem then. Yes the form needs to be
constructed again because Click need to process the submit button on
the second request to invoke onSubmit. Also you might want to retrieve
the value from a field in your Page. If the form and fields are not
constructed, how will you retrieve the value? You will need to parse
it directly from the request.
You could always place an if-then-else to conditionally build the form
or even POST your form to another page that doesn't contain the form.
But I wouldn't recommend it.
What is your concern with the fact that the form is created again?
Bob
On Fri, Apr 29, 2011 at 12:24 PM, Haim Schindler
<ha...@gmail.com> wrote:
> on the first request to:
>
> www.mysite.com/clickPage?p=100
>
> the page was loaded and then:
>
> 1. based on "p=100" I do consuming calculation to calculate
> "calculatedValue"
> 2. now, I create the form, having "calculatedValue" as HiddenField. (I dont
> need the state "p" anymore for next steps)
>
> When submitting the form, page is called again (for second time), but now,
> the value of "p" is not relevant anymore (it could also be many "p"'s like:
> "p1", "p2", ... , "p100").
> I want to handle the "post" request, and for that I need only
> "calculatedValue" I dont care about "p" now.
> But because the way Click works, I have to construct the FORM again so
> "onSubmit" will be executed. why should I ? I am not going to render the
> form again, I just want to process the "onSubmit" call and then decide to
> redirect to somewhere else. (in other words, I dont need the data the I
> needed before to construct the form)
>
>
>
> On Fri, Apr 29, 2011 at 12:45 PM, Bob Schellink <sa...@gmail.com> wrote:
>>
>> This is fundamental to stateless, share nothing architectures. Each
>> request needs all the information in order to satisfy the action. In
>> your case you need p otherwise you cannot construct the form. There
>> are geneally two options:
>> - store P in the session
>> - store P in a hiddenField and bind it's value explicitly if you need
>> it before the onProcess event eg. during onInit:
>> ClickUtils.bind(pField);
>> pField.getValue();
>>
>> regards
>>
>> Bob
>>
>> On Fri, Apr 29, 2011 at 11:08 AM, Haim Schindler
>> <ha...@gmail.com> wrote:
>> > Hello,
>> >
>> > I am not sure what is the right way to use forms.
>> > Sometimes its a problem when the form has to be constructed again after
>> > submit and before the callback is called.
>> >
>> > Example:
>> >
>> > in url I type:
>> >
>> > www.mysite.com/clickPage?p=100
>> >
>> > then in the click page I create a form.
>> > based on the url parameter "p=100" in the form creation I do:
>> > ...
>> > Integer calculatedNumber = dbService.loadData(p);
>> > form.add(new HiddenField("calculatedNumber", calculatedNumber));
>> > ...
>> >
>> > I dont keep the "p" as a HIDDEN field in the form since I dont need it
>> > anymore. all I care about now, is "calculatedNumber"
>> >
>> > the user clicked "SUBMIT"
>> >
>> > now, the calls should go to "onSubmit"
>> > but before that, the form needs to be recreated, and it needs "p" to do
>> > so.
>> > but "p" is not there anymore and then I get exception
>> >
>> > Am I missing something ?
>> >
>> > Thank you
>> > Haim Schindler
>> >
>
>
Re: Forms question.
Posted by Haim Schindler <ha...@gmail.com>.
on the first request to:
www.mysite.com/clickPage?p=100
the page was loaded and then:
1. based on "p=100" I do consuming calculation to calculate
"calculatedValue"
2. now, I create the form, having "calculatedValue" as HiddenField. (I dont
need the state "p" anymore for next steps)
When submitting the form, page is called again (for second time), but now,
the value of "p" is not relevant anymore (it could also be many "p"'s like:
"p1", "p2", ... , "p100").
I want to handle the "post" request, and for that I need only
"calculatedValue" I dont care about "p" now.
But because the way Click works, I have to construct the FORM again so
"onSubmit" will be executed. why should I ? I am not going to render the
form again, I just want to process the "onSubmit" call and then decide to
redirect to somewhere else. (in other words, I dont need the data the I
needed before to construct the form)
On Fri, Apr 29, 2011 at 12:45 PM, Bob Schellink <sa...@gmail.com> wrote:
> This is fundamental to stateless, share nothing architectures. Each
> request needs all the information in order to satisfy the action. In
> your case you need p otherwise you cannot construct the form. There
> are geneally two options:
> - store P in the session
> - store P in a hiddenField and bind it's value explicitly if you need
> it before the onProcess event eg. during onInit:
> ClickUtils.bind(pField);
> pField.getValue();
>
> regards
>
> Bob
>
> On Fri, Apr 29, 2011 at 11:08 AM, Haim Schindler
> <ha...@gmail.com> wrote:
> > Hello,
> >
> > I am not sure what is the right way to use forms.
> > Sometimes its a problem when the form has to be constructed again after
> > submit and before the callback is called.
> >
> > Example:
> >
> > in url I type:
> >
> > www.mysite.com/clickPage?p=100
> >
> > then in the click page I create a form.
> > based on the url parameter "p=100" in the form creation I do:
> > ...
> > Integer calculatedNumber = dbService.loadData(p);
> > form.add(new HiddenField("calculatedNumber", calculatedNumber));
> > ...
> >
> > I dont keep the "p" as a HIDDEN field in the form since I dont need it
> > anymore. all I care about now, is "calculatedNumber"
> >
> > the user clicked "SUBMIT"
> >
> > now, the calls should go to "onSubmit"
> > but before that, the form needs to be recreated, and it needs "p" to do
> so.
> > but "p" is not there anymore and then I get exception
> >
> > Am I missing something ?
> >
> > Thank you
> > Haim Schindler
> >
>
Re: Forms question.
Posted by Bob Schellink <sa...@gmail.com>.
This is fundamental to stateless, share nothing architectures. Each
request needs all the information in order to satisfy the action. In
your case you need p otherwise you cannot construct the form. There
are geneally two options:
- store P in the session
- store P in a hiddenField and bind it's value explicitly if you need
it before the onProcess event eg. during onInit:
ClickUtils.bind(pField);
pField.getValue();
regards
Bob
On Fri, Apr 29, 2011 at 11:08 AM, Haim Schindler
<ha...@gmail.com> wrote:
> Hello,
>
> I am not sure what is the right way to use forms.
> Sometimes its a problem when the form has to be constructed again after
> submit and before the callback is called.
>
> Example:
>
> in url I type:
>
> www.mysite.com/clickPage?p=100
>
> then in the click page I create a form.
> based on the url parameter "p=100" in the form creation I do:
> ...
> Integer calculatedNumber = dbService.loadData(p);
> form.add(new HiddenField("calculatedNumber", calculatedNumber));
> ...
>
> I dont keep the "p" as a HIDDEN field in the form since I dont need it
> anymore. all I care about now, is "calculatedNumber"
>
> the user clicked "SUBMIT"
>
> now, the calls should go to "onSubmit"
> but before that, the form needs to be recreated, and it needs "p" to do so.
> but "p" is not there anymore and then I get exception
>
> Am I missing something ?
>
> Thank you
> Haim Schindler
>