[stringtemplate-interest] Presenting relationships between two lists

Robert Rowland robertdavidrowland at gmail.com
Tue Jun 27 23:20:53 PDT 2006


> Hi, as you can tell from my silence, i'm super busy at the moment,

No worries Terrence, thanks for getting back to me!

> 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));
>

This isn't really what my problem is (although useful, I was creating
data aggregates as java objects).  The problem I have is all users
will be displayed against all reports, but a different user will be
selected in the list against each report.

I've managed to get this working in the end, but in a rather clunky
way.  What I'm doing is creating a StringTemplate instance for each
report and then pushing all these parsed templates into another
template . . .

    IUser[] users = regionGroup.getUsers();
	Arrays.sort(users, new UserComparator());

    /* get analyses in this country */
IItem[] analyses = analysisCountryItem.getBoundBranches();
	Arrays.sort(analyses, new AnalysisComparator());


> 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
>
> _______________________________________________
> 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