Hi everybody,
I've tried something like this in the execute() method with the changes of Santosh in my action:
HttpSession session = request.getSession(true);
if (getField1() != null)
session.setAttribute("field1List",getField1());
if (getField2() != null)
session.setAttribute("field2List",getField2());
return mapping.findForward(SUCCESS);
where getField1 and getField2 are the methods that ask the database.
This is the main part of the method getField1 that returns an ArrayList:
public ArrayList getField1() {
String sql = "SELECT DISTINCT(field1) FROM table";
ArrayList field1List = new ArrayList();
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://hostname:3306/DBname?user=username&password=password");
statement = con.prepareStatement(sql);
rs = statement.executeQuery();
while (rs.next()) {
field1List.add(rs.getString(1));
}
return field1List;
}
catch ( SQLException e){......}
}
The method getField2 has a similar code.
I used this code in my JSP page:
<th><bean:message key="prompt.field1" /></th>
<logic:notPresent name = "field1List">
<h2>Field1 not in scope!</h2>
</logic:notPresent>
<logic

resent name="field1List">
<th>
<html:select property="field1">
<html

ptions collection="field1List" property="value" labelProperty="label"/>
</html:select></th>
</logic

resent>
I don't know why,but I get the message for <logic:notPresent> tag that I don't want to see.Where is the error?
Thanks,
Mattia