As mentioned in previous posts, I'm a new wicket user and I'm migrating
online.ddpoker.com to it.
I may be having a mental block, but I'm finding it tedious to implement 'if'
behavior in Wicket.
As an example, I have a page which lists information about a DD Poker online
user. It lists known aliases for the user (which are linked to details
about that alias) or none:
Known Aliases: none
--- or ---
Known Aliases: _Tahoe_ _Zorro_
Ideally, I'd like a reusable panel component which displays 'none' or the
linked aliases. Thus the displaying page can just define <div
wicket:id="aliases"></div> and do add(new Aliases("aliases")) in the java
code.
However, in order for Aliases to do it's thing, it seems like I need to do
one of two things:
***** OPTION ONE *****
Define a template like
A: <-span- wicket-id="none">None</-span->
B: <-a- href="#" wicket-id="links"><-span-
wicket-id="name">Name</-span-></-a->
Then in the java code, use setVisible() to turn A/B on/off depending on
whether there are any aliases.
****** OPTION TWO *****
Define a template like
<-div- wicket-id="aliasDetail"></-div->
Define two more panels, AliasesNone and AliasesList
and in the java code do
if (aliases.size() == 0)
{
add new AliasesNone("aliasDetail");
}
else
{
add new AliasesList("aliasDetail");
}
The problem I see with this is that to implement a simple fragment would
require 3 panel classes (with 3 associated HTML classes) as opposed to the
few lines of JSP code I use today.
***** END OPTIONS *****
In summary, it seems to me that in order to do if-then logic in wicket, I
need to choose one of the following options:
a) list all options in the html template and turn off the ones that don't
apply depending on the data.
b) define Panels at a very fine level and have the Java code select the
correct sub-panel depending on the data.
This is seems like a lot of work - is there an easier way?
I also feel that I want to be able to add components in Java with out
needing associated markup. In other words, I feel artificially constrained
not being able to do something like this:
<-html->
Known aliases: <-span- wicket:id="aliases">list here || none</-span->
</-html->
List a = getAliases(user);
if (a.empty())
{
add(new Label("aliases", "none");
}
else
{
RepeatingView rv = new RepeatingView("aliases");
add(rv);
for (Alias alias : a)
{
Link l = new Link([detailpage for alias]);
rv.add(l);
l.add(new Label(alias.getName());
}
}
I'm interested to here what wicket users have done in practice. It seems
very common to have if-logic in html pages that depending on the condition
display completely different html hierarchies.
Thanks,
-Doug
--
View this message in context:
http://www.nabble.com/If-logic-in-wicket-seems-complicated-tp16808507p16808507.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]