[stringtemplate-interest] Presenting relationships between two lists

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


Sorry sent that last mail too early.

Here's my sample code.  As you can see I'm actually pulling in two
templates and pushing the result of one into the other once for each
report (or analysis as they are reffered to in the code).  This just
feels wrong . . . .

    StringTemplateGroup tabledefs = new StringTemplateGroup("myGroup");
    StringTemplate template = tabledefs.getInstanceOf("all_analyses");

    /* get analyses */
    IItem[] analyses = someGetAllUserAnalysesFunc();

    /* get all users */
    IUser[] users = someGetAllUserFunc();
    Arrays.sort(users, new UserComparator());

    /* for each analysis, build a template with that analysis and all
users, with the correct user set as selected */
    for (int i=0;i<analyses.length;i++) {
        IItem analysisItem = analyses[i];
        Analysis analysis = new Analysis(analysisItem.getFullName(),
analysisItem);
        analysis.setMediasuface(ms);
        analysis.setContext(ctx);

        StringTemplate fragment = tabledefs.getInstanceOf("analysis_item");
		   	
        fragment.setAttribute("analysis.{name,authorname}",
analysisItem.getName(), analysisItem.getAuthorName());

        for (int j=0;j<users.length;j++) {
            IUser user = users[j];
            fragment.setAttribute("users.{key,name,selected}",
user.getKey(), user.getFullName(),
analysis.isAuthorUserName(user.getUserName()));
        }
		
        template.setAttribute("fragments", fragment.toString());	
    }

    out.print(template.toString());


More information about the stringtemplate-interest mailing list