I’m writing a web application using Struts 1.1. One of the initial web pages displays a grid of rows, loaded from a database table. The primary key of this table is not shown as part of the grid; instead it is displayed as a drop-down box so that only the rows for the selected key will be displayed.
What I want to do is to remember which value has been selected by the user, when they select a different drop-down value, and then choose to go to another page. This primary key is shared by several other tables, and I want it to default to display the corresponding rows with the same selected key, when the user moves to another JSP page.
<html:link forward="AddCTypeNew">Add Control Type</html:link>
<html:link forward="ListCType">List Control Types</html:link>
</li> The code I am using to display the drop down box in the JSP pages is as follows:
My problem is in storing the String ‘controllerID’. I have tried storing is as a parameter, an attribute, and, in this example, as a System.getProperty. The above code successfully reads from a List of cType objects. But the check as to which value needs the “selected=true” attribute always fails because the controllerID String is always null.
In my struts-config.xml file, here is an example of an action that is called, that tries to retrieve the controllerID String:
<action path="/addBCodeNew" type="filemaint.AddButtonCodePreAction"
name="cTypeForm" attribute="cType" validate="false" scope="session">
<forward name="success" path="/WEB-INF/pages/tiles/buttonCodeAddTiles.jsp" />
</action> I have tried both ‘session’ and ‘request’ as values for the scope attribute, but neither has worked.
I’m not sure what else to illustrate in regards to my problem. If I’ve missed any important information about my configuration, I’ll happily supply it.
My bottom line questions are:
Why is my controllerID String always null? What is the correct way to store a value submitted to a form, so that any other JSP page can successfully retrieve it?