I am running into a bit of a problem and I wondered if others have had this
too. I am populating an options tag by creating a bean collection using
values from a resultset and then calling that collection from the options
tag using property="value" and labelProperty="label" which are of course the
getters in the the beans of the bean collection. My problem happens when I
add to the database and the change should reflect in the results of the bean
collection refreshing the bean collection. It does not. I does however
reflect the additional tables that have been written to the database when I
restart tomcat. I have encapsulated the code that creates the bean
collection into a tag that handles the sql call, bean population and
collection population.
-------------------------------------------------------
The code in the tag is as follows:
-------------------------------------------------------
package ws.phase.storeadmin.tags;
import ws.phase.sql.*;
import ws.phase.beantools.*;
import ws.phase.logging.*;
import com.codestudio.sql.*;
import java.sql.*;
import javax.sql.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import javax.servlet.*;
import java.io.*;
import java.util.*;
/**
*
* @author Administrator
* @version
*/
public class CatOrderList extends TagSupport{
public int doStartTag() throws JspTagException {
return EVAL_BODY_INCLUDE;
}
public int doEndTag() throws JspTagException {
try{
String property;
String value;
Connection conn = null;
Statement stmtread = null;
String sql = "";
sql = "SELECT NAME FROM CATEGORY";
conn = ConnectionPool.getConnection();
stmtread =
conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ
_ONLY);
ResultSet rs = stmtread.executeQuery(sql);
int count=0;
ArrayList list = new ArrayList();
while(rs.next()){
count=count + 1;
list.add(new
LabelValueBean(String.valueOf(count),String.valueOf(count)));
}
count=count + 1;
list.add(new
LabelValueBean(String.valueOf(count),String.valueOf(count)));
pageContext.setAttribute("catlist", list);
conn.close();
} catch (SQLException ex) {
} catch (IOException ex) {
}
return EVAL_PAGE;
}
}
-------------------------------------------------------
The select and option tags are as follows
-------------------------------------------------------
<html:select property="type"><html:options collection="catlist"
property="value" labelProperty="label" /></html:select>
-------------------------------------------------------
Problem recap
-------------------------------------------------------
- My page works great the first time it is called the select/option tag
produces a drop down from the database results (which are just numbers that
define a display sequence for the addition of a category)
- Once a category is added and I return to the add a category page the drop
sequence drop down does not reflect that an additional record has been added
and produces the same amout of numbers in the sequence dropdown
(selec/options dropdown).
-------------------------------------------------------
Question
-------------------------------------------------------
If I call the population of the bean collection from the top of the jsp page
and make a call to the database then why doesn't it update the results of my
sequence options dropdown.