Suresh Potiny wrote:
>
> The jsp1.1 custom tags definitely make some of these tasks easier but how
> does this or the 2nd option mentioned in the previous email
> address the dynamic form generation where the contents
> of the form depend on the some control logic (for instance, depending on the
> profile of the user, you show different forms)? Would you (as a page
> designer)
> like to see all the possible forms on your jsp page?
If the difference between how the form (or any other HTML) looks depending
on a runtime condition, like who the user is, I would prefer to put it all
in one JSP with a couple of if/else scriptlets. Usually this is easiest to
maintain. If there are big differences I would either use separate JSP pages
per runtime condition, or a JavaBean or custom tag to generate it.
For instance, a custom tag like the one in the original message below could
have different pattern elements per user role.
My rules of thumb when it comes to code in JSP pages are:
* Never ever put "business logic" code as scriptlets in a JSP page. Even
if it's intended as a quick temporary hack chances are it will stay
there forever and cause maintenance problems down the road. Business
logic is better done with JavaBeans, custom tags, or in a regular
servlet that forwards to the JSP for presentation of the result.
* Use scriptlets only for simple conditional layout decisions, such as
a few if/else to generate different messages depending on the status
of a JavaBean, or simple loops to generate lists and tables.
* If the presentation logic is too complex to be understood by the
average web page developer, let a JavaBean or custom tag generate
it (as below).
As always, what to do in each specific case depends on the size of the
application, the skill of the people involved, the expected life time
of the application, etc. In most cases though it's better to design the
application for easy maintenance and extendibility. How many "prototypes"
have not been turned into "products" overnight by just relabeling them
as products?
> ----- Original Message -----
> > "Burns, Brendan" wrote:
> > This is definitely an area where you will find a lot of different
> opinions.
> > My opinion is that in in general it's better to generate HTML with JSP
> tags
> > or scriptlets using JavaBean property values, i.e. alternative 2) above.
> > This makes it possible to reuse a JavaBean that's just a "keeper of data",
> > and all layout decisions can be made by the person who designs the JSP
> page.
> >
> > But in some cases it may make sense to use a Java object to generate
> complex
> > HTML. Take for instance a complex set of nested multi-row HTML tables used
> to
> > present some data object, with cells linked to other pages based on
> JavaBean
> > values etc. Generating this table using scriptlets may be pretty hard for
> > a non-programmer, so a JavaBean with a getHtml() method may be a better
> > choice. The HTML generating JavaBean can have a number of other properties
> > for setting things like background color, font size, etc. so the JSP page
> > designer still has some control over the look.
> >
> > With JSP 1.1 custom tags you may be able to get the best of both worlds.
> > You could use a custom tag that generates an HTML table like this:
> >
> > <foo:fooHTMLTable source="someMultiRowBean" >
> > <foo:rowPattern>
> > <TD ALIGN=RIGHT>$colA$</TD>
> > <TD>
> > <TABLE>
> > <TR>
> > <TD>$colB$</TD>
> > </TR>
> > <TR>
> > <TD>$colC$</TD>
> > </TR>
> > </TABLE>
> > </TD>
> > </foo:rowPattern>
> > </foo:fooHTMLTable>
> >
> > The custom tag takes care of looping over all rows and replaces the
> variables
> > in the pattern ($colA$, $colB$, $colC$) with the values of the
> corresponding
> > JavaBean property values for each row. So all the "tricky" code is done
> with
> > Java inside the custom tag implementation but the web page designer still
> has
> > control over the HTML code.
--
Hans Bergsten [EMAIL PROTECTED]
Gefion Software http://www.gefionsoftware.com
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html