File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Generated JSP Pages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Generated JSP Pages" Watch "Generated JSP Pages" New topic

Generated JSP Pages

Stuart Bell

Joined: Sep 17, 2004
Posts: 22

I am looking into a move away from Struts, but before I do so I want to make sure that it is not possible in Struts. The existing web app that we have is based on Struts, where each JSP page has a corresponding ActionForm bean class. There is a tight coupling between each question field in the JSP page and the getters/setters in the ActionForm.

The new functionality that we are looking at introducing moves to a more dynamically generated world, where the question fields are 'reflexive' in that they may or may not be shown depending on the previous question's answer. However, where does that leave our tightly coupled fields? Previously, we knew what the fields would be, going into this we don't. Can Struts cope with such a set up?

Has anyone else had a similar situation?



SCJP (Java 2)<br />SCJD<br />SCWCD
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Moved to Struts forum

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I can think of several ways to handle this using Struts.

The most obvious way would be to have your JSP display a collection of questions using <logic:iterate> and indexed properties. Your Action class could then determine which questions go in the collection based on the response to each question.

Consultant, Sima Solutions
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
When you say "move away from Struts" what part of Struts are you giving up and what are you moving to? Is there another technology that you think would make this easier?

This is definitely possible in Struts and the details of the solution would depend on your requirements. My project has a number of survey pages that are entirely data driven. I did not work on the development, so I am fuzzy on the implementation. I just know that the implementation was rather tricky and that the code is fairly complex, but that we were able to obtain quite a bit of reuse and the client can change the content of the surveys without code changes.

- Brent
Stuart Bell

Joined: Sep 17, 2004
Posts: 22
Guys, thanks for your responses so far. I was wondering if Merrill could elaborate on the use of the <logic:iterate> tag.

To give you a bit more background, I have been looking into technologies such as Cocoon as we have a questions.xml file that defines what question to ask, the question number and what page it is on. The questions.xml is created by another application that will be used to build the question logic. The questions.xml is its output which we can take to build the pages.

The generation of the page will be simple enough. I think (not using cocoon) we would simply perform an XSL transformation on the questions.xml to create the question page html. We are using some AJAX to give a dynamic reflexive feel, but I don't AJAX would be as suited to create a whole page.

Our data from the question pages are mapped and stored to an XML file. In our current Struts (1.0) set up, this was easy to do as we had a getter and a setter for each field. This was the area that I puzzled by. If we are dynamically creating the pages from the questions.xml, how can we then map the answers to the XML data source when we don't know what questions will be generated on the page?

Hope that adds a bit more detail.


Alec Lee
Ranch Hand

Joined: Jan 28, 2004
Posts: 569
LazyActionForm and LazyDynaBean may do what you want. It seems that they are supported in Struts 1.3 (i have not used v1.3). Alternatively, try (Niall Pemberton's Lazy DynaBean) if you're using v1.2.
I agree. Here's the link:
subject: Generated JSP Pages
jQuery in Action, 3rd edition