On Fri, Apr 29, 2011 at 7:24 AM, Haim Schindler <[email protected]>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

Reply via email to