You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Daniel Ferreira Castro <df...@gmail.com> on 2009/02/05 12:14:41 UTC

A doubt regarding "best-practices"

In lots of books about wicket I can see a Page implementation declaring a
Form as an inner class of the Page.
Of course that this is, in part, a personal preference.
I think, in my opinion, that the approach of declaring the Form as an inner
class makes the code more "dirty".  I mean, the Page class grows a lot and
by inspecting the code is hard to understand at a first glance the scope of
each entity and field.  So I prefer to declare the Form as a top class
instead inner class.

Is there any reccomendation that denies such thing?

And also, regarding Forms yet...
If I declare a Form as a top class should I have a markup html for it
because this form will be treated as a component?


-- 
"Two rules to succeed in life:
1 - don“t tell people everything you know."
--------
We shall go on to the end.
We shall fight in France
We shall fightover the seas and oceans.
We shall fight with growing confidence and growing strength in the air.
We shall defend our island whatever the cost may be
We shall fight on beaches, we shall fight on the landing grounds,
We shall fight in the fields and in the streets,
We shall fight on the hills.
We shall never surrender.
Winston Churchill

Re: A doubt regarding "best-practices"

Posted by Kent Tong <ke...@cpttm.org.mo>.

Daniel Ferreira Castro wrote:
> 
> I think, in my opinion, that the approach of declaring the Form as an
> inner
> class makes the code more "dirty".  I mean, the Page class grows a lot and
> by inspecting the code is hard to understand at a first glance the scope
> of
> each entity and field.  So I prefer to declare the Form as a top class
> instead inner class.
> 

No. First of all, your page class should not keep growing larger and larger.
You should put most of the logic into your domain classes, not in the page
class. Once you do that, your page should be clean and easy to understand
despite the presence of an anonymous Form subclass.

Second, the structure of the Java code should match the structure of the
HTML file. This will make it easier to understand how they work together.



-----
--
Kent Tong
Wicket tutorials freely available at http://www.agileskills2.org/EWDW
Axis2 tutorials freely available at http://www.agileskills2.org/DWSAA
-- 
View this message in context: http://www.nabble.com/A-doubt-regarding-%22best-practices%22-tp21849426p21869946.html
Sent from the Wicket - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: A doubt regarding "best-practices"

Posted by Leszek Gawron <lg...@apache.org>.
Daniel Ferreira Castro wrote:
> In lots of books about wicket I can see a Page implementation declaring a
> Form as an inner class of the Page.
> Of course that this is, in part, a personal preference.
> I think, in my opinion, that the approach of declaring the Form as an inner
> class makes the code more "dirty".  I mean, the Page class grows a lot and
> by inspecting the code is hard to understand at a first glance the scope of
> each entity and field.  So I prefer to declare the Form as a top class
> instead inner class.
> 
> Is there any reccomendation that denies such thing?

It's probably a matter of preference and how big your form code actually is.

> 
> And also, regarding Forms yet...
> If I declare a Form as a top class should I have a markup html for it
> because this form will be treated as a component?

No, Form doesn't extend WebMarkupContainerWithAssociatedMarkup.

-- 
Leszek Gawron

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: A doubt regarding "best-practices"

Posted by Martin Makundi <ma...@koodaripalvelut.com>.
>>> If I declare a Form as a top class should I have a markup html for it
>>> because this form will be treated as a component?
>
>>  Wicket works both ways.
>
> No, Form doesn't extend WebMarkupContainerWithAssociatedMarkup.

Ah.. might be true, if you want it to have its own markup, you will
embed it into a panel.

**
Martin

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: A doubt regarding "best-practices"

Posted by Martin Makundi <ma...@koodaripalvelut.com>.
> I prefer to declare the Form as a top class instead inner class.

That is ok. This way you can also re-use the same form from different
pages/panels.

> If I declare a Form as a top class should I have a markup html for it
> because this form will be treated as a component?

Depends on your situation. Again, if you want everything clean you can
make it have its own markup. In my situation I re-use some forms on
different pages and the markup is always different, so I chose not to
have its own markup.

Wicket works both ways.

**
Martin

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: A doubt regarding "best-practices"

Posted by Timo Rantalaiho <Ti...@ri.fi>.
On Thu, 05 Feb 2009, Daniel Ferreira Castro wrote:
> I think, in my opinion, that the approach of declaring the Form as an inner
> class makes the code more "dirty".  I mean, the Page class grows a lot and
> by inspecting the code is hard to understand at a first glance the scope of
> each entity and field.  So I prefer to declare the Form as a top class
> instead inner class.

As a rule of a thumb, it's a good idea to thrive to follow 
the single responsibility principle [1] also with Wicket 
classes. This might or might not get more complicated with 
inter-component dependencies.

[1] http://www.objectmentor.com/resources/articles/srp.pdf

Best wishes,
Timo


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org