Hi Cemal. I have used the setRenderBodyOnly() in other cases. Thanks for
the reminder.
I ended up doing this:
WebMarkupContainer none = new WebMarkupContainer("none");
none.setVisible(list.isEmpty());
add(none);
RepeatingView rv = new RepeatingView("list");
rv.setVisible(!list.isEmpty());
add(rv);
for (int i = 0; i < list.size(); i++)
{
rv.add( ... )
}
My original post was more of a question about the philosophy of doing
if-then-else logic in wicket. Based on the responses to this post, it seems
that this is the current best practices:
Putting multiple components in the markup and turning them
visible/not-visible based on the data isn't such a bad thing. It works in
small cases like this. The wicket-enclosure tag makes this easy when there
is extra markup associated with a tag.
In slightly more complicated cases, using wicket-fragment is a better
solution which allows you to pick between different markup scenarios without
having to add all those components into the hierarchy and turn them on/off.
In the most complex cases, using separate Panels is more appropriate.
-Doug
jWeekend wrote:
>
> Doug,
>
> Take a look at Component's setRenderBodyOnly method if you sometimes need
> to render a link as plain text based on some condition (thanks Nilklas).
> This combined with Igor's tip could be one possible solution to the
> requirements you have mentioned, so far.
> On the http://jweekend.com/dev/LWUGReg/ London Wicket Event registration
> page we use something like this to show registrants' names as links only
> if they have entered a URL.
>
> Regards - Cemal
> http://jWeekend.co.uk http://jWeekend.co.uk
>
>
> Doug Donohoe wrote:
>>
>> Thanks igor for the suggestion.
>>
>> It's not quite that simple. If it is a valid alias, I actually want it
>> to be a link (with a label inside). So it isn't quite equivalent.
>>
>> I'll checkout fragments too!
>>
>> -Doug
>>
>>
>> igor.vaynberg wrote:
>>>
>>> right, use fragments for these small inline chunks, also because your
>>> usecase is so simple: just a string, you can simply do
>>>
>>> class aliasesmodel extends ldm {
>>> object load() {
>>> list aliases=getaliases();
>>> if (aliases.isempty()) { aliases.add(new alias("none")); }
>>> }
>>> }
>>>
>>> then there is no need to toggle the none fragment to show up
>>>
>>> -igor
>>>
>>>
>>> On Mon, Apr 21, 2008 at 11:33 AM, Enrique Rodriguez
>>> <[EMAIL PROTECTED]> wrote:
>>>> On Mon, Apr 21, 2008 at 11:27 AM, Doug Donohoe <[EMAIL PROTECTED]>
>>>> wrote:
>>>> > ...
>>>>
>>>> > I may be having a mental block, but I'm finding it tedious to
>>>> implement 'if'
>>>> > behavior in Wicket.
>>>>
>>>> I use Wicket Fragments all over the place for this sort of thing.
>>>>
>>>> http://wicket.apache.org/examplefragments.html
>>>>
>>>> Enrique
>>>>
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>>> For additional commands, e-mail: [EMAIL PROTECTED]
>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>> For additional commands, e-mail: [EMAIL PROTECTED]
>>>
>>>
>>>
>>
>>
>
>
--
View this message in context:
http://www.nabble.com/If-logic-in-wicket-seems-complicated-tp16808507p16823927.html
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]