Wo,

If your data have a few standard table formats, as you seem to suggest
below, you might be better served by using a different approach with tiles.
If your tables were not in a Java method but designed within a JSP by
pulling in request saved attributes, you could use the TilesAction.execute()
method to save the header, content, tableStyle, tableHeaderStyle, and
contentStyle into request scoped variables that your JSP could import and
use, then simply change which table is being used by setting the "table"
tile attribute (within your TilesAction.execute() OR modify your definition
in tiles-defs.xml) to the appropriable table1.jsp (or table2.jsp, etc.).

If your base tile definition had:
<definition name=".Master" path="/WEB-INF/tiles/master.jsp">
        <put name="table" value="/WEB-INF/tiles/table1.jsp" />
        <!-- ... other components ... -->
</definition>

In your TilesAction.execute(), you could do:
context.putAttribute("header", "This is an example Table");
context.putAttribute("vector", content);
etc.

You could manually set which table jsp layout to use with:
content.putAttribute("table", "/WEB-INF/tiles/table7.jsp");

Inside your jsp, you could use the tiles:importAttribute to pull the
attribute into JSP scope and use it as a bean:write, logic:iterate, or other
struts (looping or single use) tag.

*** Note the "/WEB-INF/..." path prefix I used above can be anything you
wish.  I always choose /WEB-INF to hide my JSP's from external attempts to
access them since while allowing internal (i.e. implied redirect="false")
use by my Struts webapp.

Regards,
David

-----Original Message-----
From: wo_shi_ni_ba_ba [mailto:[EMAIL PROTECTED]
Sent: Tuesday, March 08, 2005 9:50 PM
To: Struts Users Mailing List
Subject: Re: problem with automation of struts html code


hi folks,
thanks for the suggetion.
I am not trying to write a templating system. I am
trying to do something different, maybe an example
will elaborate.  I have a utility function printTable1
that I want to use it to print different tables
because the tables  in my jsps share a lot of common
structures.
with this utility function, I can avoid a lot of
redundency in my jsp code.  This obviously doesn't
work if I insert struts taglibs into it.  but I also
want to use struts taglibs.  How do I solve this
problem?  How do I use tiles to solve this problem?

[code]
        public static void printTable1(JspWriter writer,
Vector header, Vector content, String tableStyle,
String tableHeaderStyle, String contentStyle){
                StringBuffer s=new StringBuffer("<div
id=\"").append(tableStyle).append("\">");
                s.append("<table>");
                s.append("<tr>");
                Object obj=null;
                String cell=null;
                for(int i=0;i<header.size();i++){
                        obj=header.get(i);
                        if(obj!=null){
                                cell=obj.toString();
                        }
                        else cell="";
                        s.append("<td
class=\"").append(tableHeaderStyle).append("\">").append(cell).append("</td>
");
                }
                s.append("</tr>");

                for(int i=0;i<content.size();i++){
                        Vector row=(Vector)content.get(i);
                        s.append("<tr>");
                        for(int j=0;j<row.size();j++){
                                obj=row.get(j);
                                if(obj==null)cell="";
                                else cell=obj.toString();
                                if(contentStyle!=null){
                                        s.append("<td
class=\"").append(contentStyle).append("\">");
                                }
                                else s.append("<td>");
                                s.append(cell).append("</td>");

                        }
                        s.append("</tr>");
                }
                s.append("</table></div>");
                try {
                        writer.println(s);
                } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }

        }
[/code]
--- Max Cooper <[EMAIL PROTECTED]> wrote:
> Don't write your own page templating system. Use
> Tiles instead.
>
> -Max
>
> On Tue, 2005-03-08 at 16:32 -0800, wo_shi_ni_ba_ba
> wrote:
> > Hi folks,
> > In my webapplications there are many html page
> with
> > the similar look and structure. I am trying to
> factor
> > out them.  So I created utility functions to print
> out
> > html code to the jspWriter.  But I am not able to
> > incorporate struts tags into these functions
> because
> > they will just be printed without being rendered
> > through the struts engine.
> > So if I print <struts:radio .../> it will come out
> > like <struts:radio.../> without any change.
> > On the other hand if I don't incorporate struts
> tags
> > into my utility functions and use just plain html
> > code, I don't get to take the full advantage of
> struts
> > tags.
> > How do I get around this problem?
> > thanks
> >


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to