[stringtemplate-interest] Presenting relationships between two
lists
Terence Parr
parrt at cs.usfca.edu
Tue Jun 27 10:28:32 PDT 2006
Hi, as you can tell from my silence, i'm super busy at the moment,
but what I did for this was to send in parallel areas or arrays of
objects.
for each user:
st.setAttribute("users.{name, selected}", user.getName(),
shouldBeSelected(user));
Ter
On Jun 27, 2006, at 4:37 AM, Robert Rowland wrote:
> Hi All,
>
> Before I go on too much further can I just say that I'm not after
> reopening the old argument about conditionals . . . I can understand
> quite clearly why they are a "bad thing".
>
> However I've got a problem here that with other template systems I
> would have used conditionals, and can't seem to get my head round how
> to get this to work with StringTemplate.
>
> I have two lists of objects, with a one to one relationship between
> the items in the lists. Lets say they are reports and users. I want
> to produce a list of reports and against each report is a list of all
> the users. For each report one of those users is marked as selected.
>
> So here goes:
>
> $reports:{r|
> $r.reportName$
> $users:{u|$u.userName$ $if(u.userName==r.userName)$Yes Selected!
> $endif$
> }$
> }$
>
> Obviously the $if(u.userName==r.userName)$ doesn't work in
> StringTemplate, but I can't for the life of me work out how to get the
> same behaviour without the conditional.
>
> Hopefully I'm making sense . .
>
> Cheers Rob.
>
> p.s. in case your wondering, and in case it makes things clearer, what
> I'm actually trying to achieve is HTML select boxes, so . . .
>
> $reports:{r|
> $r.reportName$
> <select name="$r.id$>
> $users:{u|<option
> value="$r.id$-$u.id$">$if(u.userName==r.userName)$
> selected$endif$>$u.userName$</option>
> }$
> </select>
> }$
>
> Which may produce something like the following . . .
>
> My Report 1
> <select name="r1">
> <option value="r1-u1" selected>Rob</option>
> <option value="r1-u2">Fred</option>
> <option value="r1-u3">George</option>
> </select>
>
> My Report2
> <select name="r2">
> <option value="r2-u1">Rob</option>
> <option value="r2-u2">Fred</option>
> <option value="r2-u3" selected>George</option>
> </select>
> _______________________________________________
> stringtemplate-interest mailing list
> stringtemplate-interest at antlr.org
> http://www.antlr.org:8080/mailman/listinfo/stringtemplate-interest
More information about the stringtemplate-interest
mailing list