Re: Is it the best way to code a Link depending on a condition

2009-09-25 Thread cmoulliard
In fact, the example createLabel is not really the most interesting. Let's me explaining what I consider as a good candidate and what I have done 1) A HTML page contains a table which is populated dynamically using a service collecting data from a DB. the last column of the table is a link

Re: Is it the best way to code a Link depending on a condition

2009-09-23 Thread Nicolas Melendez
ok, i understand, thanks, NM On Tue, Sep 22, 2009 at 9:45 PM, Jeremy Thomerson jer...@wickettraining.com wrote: It's the same reason you shouldn't use new Label(id object.getSomeText());. See this example: public MyPage () { Person p = getPersonFromSomewhere(); Label l = new

Re: Is it the best way to code a Link depending on a condition

2009-09-23 Thread josephpachod
hi Charles The whole issue is that you don't know how the data (in this case a String) is to be retrieved. Can it be read only once ? Should it be refresh on each request cycle ? On each access to the data ? Does it come from a database ? Wicket's model allows you to go away from all these

Re: Is it the best way to code a Link depending on a condition

2009-09-22 Thread Nicolas Melendez
Jeremy:you say 2 - don't call setEnabled() - override isEnabled why is better override isEnable then setEnable? thanks NM On Mon, Sep 21, 2009 at 9:44 AM, cmoulliard cmoulli...@gmail.com wrote: Joseph, Can you explain a little bit what you mean by provide it with attribute (IModelString)

Re: Is it the best way to code a Link depending on a condition

2009-09-22 Thread Jeremy Thomerson
It's the same reason you shouldn't use new Label(id object.getSomeText());. See this example: public MyPage () { Person p = getPersonFromSomewhere(); Label l = new Label(numberOfPhoneNumbers, p.getPhoneNumbers().size()); l.setVisible(p.getPhoneNumbers().size() 0); new

Re: Is it the best way to code a Link depending on a condition

2009-09-21 Thread cmoulliard
Joseph, Can you explain a little bit what you mean by provide it with attribute (IModelString) ? private Label labelTitle; public static Label createLabelTitle(String title) { return new Label(title,new Model( title )); } -- becomes private

Re: Is it the best way to code a Link depending on a condition

2009-09-19 Thread Jeremy Thomerson
This is because you're not using models correctly. And you apparently are not using page inheritance either. Both of those things will fix this problem that you describe. Also, Wicket makes it *very* easy to create reusable code - in your link example, just make a subclass of link as a concrete

Re: Is it the best way to code a Link depending on a condition

2009-09-18 Thread Joseph Pachod
cmoulliard wrote: (...) I think that this is a general remark that some users make about Wicket. It is very difficult to reuse part of the code. Here is another example : I have a label called id which is used in different page. The way proposes by Wicket to code it is Page Request

Re: Is it the best way to code a Link depending on a condition

2009-09-18 Thread cmoulliard
What I have done to avoid to repeat the creation of the labels is to define and use static method private Label labelTitle; public static Label getLabelTitle(String title) { return new Label(title,new Model( title )); } Joseph Pachod wrote:

Re: Is it the best way to code a Link depending on a condition

2009-09-18 Thread Joseph Pachod
cmoulliard wrote: What I have done to avoid to repeat the creation of the labels is to define and use static method private Label labelTitle; public static Label getLabelTitle(String title) { return new Label(title,new Model( title )); } I personally

Is it the best way to code a Link depending on a condition

2009-09-17 Thread Charles Moulliard
Hi, I would like to know if there is a better way to code this case : What I would like to do is to enable/disable a link depending on a condition. If the condition is true, than we create the link otherwise we disable it. In both case, a label must be defined for the Link. I mean, is it

Re: Is it the best way to code a Link depending on a condition

2009-09-17 Thread Matthias Keller
Sure, just create it (including the onClick which might be invalid), but afterwards set the setEnabled() as needed. As long as the link is disabled, it can never be clicked thus the onClick() will never be executed anyway, so it's irrelevant if the requestFormModel is valid or not... I dont

Re: Is it the best way to code a Link depending on a condition

2009-09-17 Thread cmoulliard
You are right. I don't need the setEnabled(false) in the onClick method I have changed my code : link = new Link(linkRequest) { @Override public void

Re: Is it the best way to code a Link depending on a condition

2009-09-17 Thread Matthias Keller
Hi As I said in my previous mail, just initialize the link once using the upper variant. Use an if before to create the requestFormModel, in case 2, the requestFormModel can be null - as the onClick is never executed this will not matter. Have something like: final Model requestFormModel;

Re: Is it the best way to code a Link depending on a condition

2009-09-17 Thread cmoulliard
Mattias, OK about what you propose but we repeat the test a second time so the code still remains very verbose. Thanks for the suggestion. I think that this is a general remark that some users make about Wicket. It is very difficult to reuse part of the code. Here is another example : I have

Re: Is it the best way to code a Link depending on a condition

2009-09-17 Thread Matthias Keller
Hi Yes there'll always be some repetition. Depending on your logic you might also stuff the first block in the onClick event to generate the model if it's not used anywhere else. That could eliminate the first block. The problem about reusable components in wicket is that probably you might