Hi All, I have a jsp page that I am reusing for 3 differant conditions. Basically it has the same content, but sometimes shows 3 rows and 3 columns of data, other times 1 row and 9 columns of data, etc. So, I added a numColumn and numRow value to my form so I can render the jsp on the fly for differant configurations.
My question is, am I trying too hard to re-use code that maybe shouldn't be re-used? I could just have 3 similar jsp pages, each with thier own action. Would either be considered better practice, or is reusing the jsp considered an OK thing to do?
To make the jsp page configurable, there are a lot of scriptlets with for loops and I am also not sure if this also is an ok idea.
Any opinions appreciated, and thanks in advance for your time.
You might be able to get some good advice if you give a little more detail. Either way, you might want to read up about DispatchAction.
You should be able to use a combination of tiles and custom tags to get the most reuse.
Joined: May 17, 2001
Thank you for your reply. Here is more information about my application. I will be rendering a page given a viewType, for the sake of argument, lets say my view types are named vOne, vTwo, and vThree. vOne will show data in a table like this :
my init.do action will determine that I need to forward to vThreeAction.do because of the value pulled from the request, in vThreeAction.do, I will tell the form that I should use one row with 7 columns (they are form values, numRows, numColumns). If the url had been http://localhost/myApp/init.do?viewType=vOne, I would go to vOneAction.do, where I would set numRows = 3 and numColums=3.
I then render the jsp page.
So, for these three views, I only need one jsp page, one struts form, and 3 struts actions. The tricky part is, If I want to submit the form to preform some action, like sorting, then I somehow have to know that I am submitting to vOneAction.do, vTwoAction.do, or vThreeAction.do.
Am I making this too complicated? Should I just use 3 differant jsp's ?
Joined: May 05, 2006
You might not even have to pass around viewType and you might be able to avoid populating numRows and numColumns. All you should have to do is populate a multidimensional list and put that in the form. For example:
Then use dispatch action to call the correct action.
Deciding whether or not to use 3 different pages is going to be based on the similarity of things, but technically you can get away with one that is not very complex.
Joined: May 17, 2001
Dom, I can't thank you enough! This approach worked like a charm. I did already have the vector type code you suggested, just was iterating over the list of lists using scriptlets, I didnt think of the fact that I could get and use the <iterate tag, one of those "not seeing the forrest for the trees" things I guess.
Thanks so much for your time, my page is so improved by this !
Now off to try to get the Dispatch action to work . . .
subject: OK to make the value of action attribute of a form a variable ?