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?
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.
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.
Joined: Sep 17, 2004
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?
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 http://www.niallp.pwp.blueyonder.co.uk (Niall Pemberton's Lazy DynaBean) if you're using v1.2.