You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@click.apache.org by Victor França <vi...@gmail.com> on 2009/01/29 16:22:22 UTC

Statefull pages with ActionLinks on

Hi gents,

   I'm facing a problem with ActionLinks on statefull pages.

   I have one statefull search page with two parameters. First is a Table
control holding a List of VO's and the other one is one Select control.

   The table has a "remove" ActionLink for each row. This is done with a
LinkDecorator.
   This page also has a "Search" Submit that forwards me to another page
where the user can select the rows which will apear on the table on the
first page.

   If i select a Option on the Select control on the first page and hit
"Search", the form is submited and i i'm forward to the second page, then I
select one row on the second page's table and come back to the first page.
As a result of this operation, i can see the search page's table filled with
the row i selected on the second page and the Select control filled with the
option i had selected before hit "Search". Ok.

   The problem is if I click on the ActionLink "remove" on the table on the
search page. The right method is been called on my class, but the Select
Control is been cleared, its state is not been keeped.

  I'm not doing anything on my onInit method.

   So, how can i keep the state of statefull pages if an ActionLink is
clicked?

regards,

Victor França

Re: Statefull pages with ActionLinks on

Posted by Bob Schellink <sa...@gmail.com>.
Victor França wrote:
> 
> By the way, i'd like to congratulate you guys for the greate job on 
> Click framework, it's helping me a lot and offering me an excelent 
> productivity.


That is good to hear. :)

Re: Statefull pages with ActionLinks on

Posted by Victor França <vi...@gmail.com>.
Thanks, Bob. Issue solved. I didn't know about this control attribute
visibility effect.
By the way, i'd like to congratulate you guys for the greate job on Click
framework, it's helping me a lot and offering me an excelent productivity.

Regards,

Victor



Victor França


On Thu, Jan 29, 2009 at 12:06 PM, Bob Schellink <sa...@gmail.com> wrote:

> Victor França wrote:
>
>     public FNetSelect sltClientGroup =new FNetSelect("sltClientGroup",
>>
>
>
> I think the problem is that sltClientGroup is declared as "public". Click
> handles public controls in a special way in that it automatically adds them
> directly to your Page. Meaning when the Page controls are processed, the
> Select will also be processed (which internally invokes bindRequestValue).
> This would nullify your Select value.
>
> The fix should be easy, just declare your Select as "private" and it won't
> be added directly to the Page controls. With this change Select will only
> have its value bound if the Form is actually submitted.
>
> Btw you should probably declare your controls as private unless you want
> them added to the Page's controls. See the following section for details on
> this feature:
>
>
> http://incubator.apache.org/click/docs/configuration.html#application-autobinding
>
>
>    It doesn't matter the content of the constructor, as it will be called
>> just on the first time the Page is requested, isn't?
>>
>
>
> Yep this is correct. :)
>
> kind regards
>
> bob
>

Re: Statefull pages with ActionLinks on

Posted by Bob Schellink <sa...@gmail.com>.
Victor França wrote:

>     public FNetSelect sltClientGroup =new FNetSelect("sltClientGroup", 


I think the problem is that sltClientGroup is declared as "public". 
Click handles public controls in a special way in that it 
automatically adds them directly to your Page. Meaning when the Page 
controls are processed, the Select will also be processed (which 
internally invokes bindRequestValue). This would nullify your Select 
value.

The fix should be easy, just declare your Select as "private" and it 
won't be added directly to the Page controls. With this change Select 
will only have its value bound if the Form is actually submitted.

Btw you should probably declare your controls as private unless you 
want them added to the Page's controls. See the following section for 
details on this feature:

http://incubator.apache.org/click/docs/configuration.html#application-autobinding


>    It doesn't matter the content of the constructor, as it will be 
> called just on the first time the Page is requested, isn't?


Yep this is correct. :)

kind regards

bob

Re: Statefull pages with ActionLinks on

Posted by Victor França <vi...@gmail.com>.
Hi Bob,

   Thanks for quick answer.

   I tried to figure out where i could be manually setting the Select
control value without success.
   I'm not playing with select#bindRequestValue.

   Please, take a look at the main methods of the Search Page and its
controls:

    public Form form = new Form();

    public FieldSet fstClientGroup = new FieldSet("fldClientGroup");
    public FNetSelect sltClientGroup =new FNetSelect("sltClientGroup",
getMessage(PageMessages.LABEL_CLIENT_GROUP));

    public FieldSet fstProducts = new FieldSet("fldProducts");
    public Table tblProducts = new Table("tblProducts");
    public AbstractLink alkDelete = new
ActionLink(getMessage(PageMessages.ACTION_LABEL_DELETE));
    public Submit sbtSearch = new
Submit(getMessage(PageMessages.ACTION_LABEL_SEARCH));

    public Submit sbtGenerateReport =
            new Submit("sbtGenerateReport",
getMessage(PageMessages.ACTION_LABEL_GENERATE_REPORT));


    @Override
    public void onInit() {
        clearErrorMessage();
    }

    @Override
    public void onRender() {
        tblProducts.setRowList(getSelectedProductsSessionList());
    }

    /**
     * This method is called when Delete Action Link is clicked
    **/
    private ActionListener getDeleteActionListener() {
        return new ActionListener() {
            @Override
            public boolean onAction(Control source) {
                Integer idSelectedProduct = ((ActionLink)
source).getValueInteger();

                ProductVO productVO = (ProductVO) new
ProductService().load(idSelectedProduct);

                getSelectedProducts().remove(productVO);

                return true;
            }

        };
    }


   It doesn't matter the content of the constructor, as it will be called
just on the first time the Page is requested, isn't?


Regards,

Victor França

On Thu, Jan 29, 2009 at 8:35 AM, Bob Schellink <sa...@gmail.com> wrote:

> Hi Victor,
>
>
> Victor França wrote:
>
>
>>   So, how can i keep the state of statefull pages if an ActionLink is
>> clicked?
>>
>
>
> When a stateful page is enabled (#setStateful(true)), Click will place the
> Page in the session and reuse that same page the following request. So the
> state of the Page should be preserved when you follow the ActionLink.
>
> Without seeing your code my guess is that somewhere on the page the Select
> value is reset. Perhaps you manually set the Select value on the Page or use
> select#bindRequestValue?
>
> If you can feel free to post an example.
>
> kind regards
>
> bob
>

Re: Statefull pages with ActionLinks on

Posted by Bob Schellink <sa...@gmail.com>.
Hi Victor,


Victor França wrote:

> 
>    So, how can i keep the state of statefull pages if an ActionLink is 
> clicked?


When a stateful page is enabled (#setStateful(true)), Click will place 
the Page in the session and reuse that same page the following 
request. So the state of the Page should be preserved when you follow 
the ActionLink.

Without seeing your code my guess is that somewhere on the page the 
Select value is reset. Perhaps you manually set the Select value on 
the Page or use select#bindRequestValue?

If you can feel free to post an example.

kind regards

bob