wood burning stoves 2.0*
The moose likes JSP and the fly likes Architecture Advice Required: to JSP or not ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Architecture Advice Required: to JSP or not ?" Watch "Architecture Advice Required: to JSP or not ?" New topic
Author

Architecture Advice Required: to JSP or not ?

Brendan Laing
Greenhorn

Joined: Mar 22, 2006
Posts: 10
Hi,

We'd like to make use of JSP's and I'm sure we do not have an unusual business case but we can't see how we can due to the following technical challenges. I'm sure there is an expert who has better experience on this, can you advise us?

The challenge:

We have an object (say a car object) that has properties (the driver is) with values (person objects). The car object may have other properties (has passengers) with no values at all. We want to display to a web browser user the car object.

The car object belongs to the car class so we know all the properties the car should have. It is from that class we are able to build up an XHTML using a div for the object with a table containing rows for each property. Then we need to map the object's property values into the cells of the table. There may be mulitple values (i.e. 4 passengers), and we want to display each value using a div with an image (to allow drag and drop).

I can see several ways of solving this.
1) The car object is a class and has a method parse which returns it's own XHTML logic. The car object has a hashmap containing the properties and each property has a hasmap containing the values. For example:

object
parse
<DIV>
<TABLE>
loop through properties and parse each one
</TABLE>
</DIV>

property
parse
<TR>
<TD>label</TD>
<TD>
loop through values and parse each one
</TD>
</TR>

property value
parse
<DIV>
<IMG src="..">
</DIV>

This builds up the final example XHTML for the object:

<DIV id="car">
<TABLE>
<TR>
<TD>p_driver</TD>
<TD>
<DIV>
<IMG src=".Bob.">
</DIV>
</TD>
</TR>
<TR>
<TD>p_passengers</TD>
<TD>
<DIV>
<IMG src=".Fred.">
</DIV>
<DIV>
<IMG src=".Wilma.">
</DIV>
</TD>
</TR>
</TABLE>
</DIV>


2) Do the same as above and build an XML instead of XHTML. Then parse using XSLT:

<Object id="car">
<TABLE>
<Prop>p_driver</Prop>
<ObjectValue>.Bob.</ObjectValue>
<Prop>p_passengers</Prop>
<ObjectValue>.Fred.</ObjectValue>
<ObjectValue>.Wilma.</ObjectValue>
</Object>


3) Since we may want to present the same objects in different formats depending on the user i.e. we may want to use a column for each property instead of rows (transpose the table). We like the idea of seperating the generation of the presentation (XHTML) logic from the data preparation stage (reading both the class, object, and properties). JSP's would be perfect for this. But we would like to modularise the JSP so that for example the property values are their own reusable JSP's. In this case we would need to pull together many JSP's to produce the final XHTML. One way to do this (but surely not the best way by far) is for the servlet to read the JSP (or file based XHTML definition) and then dynamically build up the XHTML using the JSP's as templates (this sounds too much like XSLT). Otherwise how would you do the following:

Define 3 JSP's:
Object_Container.JSP
Property.JSP
Objecy_Value.JSP

The Object container would be used for the car. Then it would need to read the servlet bean and loop through the properties, and then insert the property jsp for each one found. The property JSP would then need to read the servlet and loop through the objct_value JSP for each value found.

4) Use JSF. We want more control on the gui components that JSF will allow, so this is not an option.

So in the end we can't see how to do option 3 in a sensible way so for the time being we've stuck with option 1. Option 2 may be an option but we're concerned about performance and first like to exhaust the JSP option. Any tips, traps, or insults for our stupidity...?

Brendan

[ May 10, 2006: Message edited by: Brendan Laing ]

[ May 10, 2006: Message edited by: Brendan Laing ]

[ May 10, 2006: Message edited by: Brendan Laing ]

[ May 10, 2006: Message edited by: Brendan Laing ]
[ May 10, 2006: Message edited by: Bear Bibeault ]
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1016
Not entirely certain why you want to separate properties

Two possible solutions I think
1 - Standard JSP and JSTL. The JSTL forEach loop is perfect for iterating and repeating code. Basically its a JSP version of your option1.

2 - Custom tags. You write a custom tag to render each of object, property and value.

Personally I think the JSTL approach will be easier and better than custom tags.

Does this help?
Brendan Laing
Greenhorn

Joined: Mar 22, 2006
Posts: 10
Thanks for you reply, suggesting xslt confirms my thoughts from an ongoing support point of view, what about the performance costs, compared to other options?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60822
    
  65

Stefan didn't say a word about xslt.

I'm not really seeing the issue. What you are trying to do sounds like a straight-froward JSP/JSTL page. Unless there's something I'm really missing, it sounds like you are vastly over-complicating and over-engineering this.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Brendan Laing
Greenhorn

Joined: Mar 22, 2006
Posts: 10
Thanks Bear,

Sorry I did miss read Stefans reply.

I'll read up on JSTL tonight!

Thanks
Brendan
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Architecture Advice Required: to JSP or not ?
 
Similar Threads
submitting and forwarding JSP pages with beans
have problem with multiple forms on a jsp
problem in combining <jsp:include> and struts 2.2.1
How to configure?
JSP and XML