I need to get an id from
jsp session Object, and pass this id to some other class and use it to get some data from database, and then display those data in an drop down list only if the user select an option from an existing dropdown list.
I used following code to get the id in the JSP.
<%
User user = (User)request.getSession().getAttribute("user");
String id = user.getID();
if (user.isDemoUser())
id = "483297701";
%>
I have a DAO class with method like
public Vector findAllData(String id)throws Exception{}
in my Form class, I did this
public class VerificationsForm {
private String selectedVerification;
private String selectedSession;
private String id;
private String[] sessionValues;
private String[] sessionLabels;
public void setSessionValues(){
VerificationDAO sgrDAO = VerificationDAO.getInstance();
Vector vec = null;
try{
vec =sgrDAO.findAllSessions(getId());
}
catch(Exception e){}
finally{
if (vec!=null && vec.size()>0) {
int s = vec.size();
sessionValues = new String[s];
vec.copyInto(sessionValues);
}
}
}
public String[] getSessionValues(){
if (sessionValues==null) setSessionValues();
return this.sessionValues;
}
public void setSessionLabels(){
String[] temp = getSessionValues();
int s = (temp==null?0:temp.length);
sessionLabels = new String[s];
for (int i=0; i<s;i++){
sessionLabels[i] = formatSession(temp[i]);
}
}
public String[] getSessionLabels(){
if (sessionLabels==null) setSessionLabels();
return this.sessionLabels;
}
public void setId(String value){ this.id=value; }
public String getId(){ return this.id; }
public void setSelectedVerification(String value){ this.selectedVerification=value; }
public String getSelectedVerification(){ return this.selectedVerification; }
public void setSelectedSession(String value){this.selectedSession=value;}
public String getSelectedSession(){return this.selectedSession;}
}
The problem is: It seems that the id that I need to ne used in the Form object can not be passed, it alsway get null value? so, this may not a good design to deal with the case. Any help is welcome.