You're only populating the list in the "execute" method, but that isn't run
on a validation error--"input" is.

Consider implementing Preparable. IIRC this is in the faq (I might be
recalling wrong).

Dave
 On Jun 27, 2011 3:18 AM, "akshat [PG8]" <akshat-...@iiitmk.ac.in> wrote:
> Hi everyone,
>
> Please help me in Struts2, I am stucked in action....
>
> The problem is that I have a application form for accessing that form you
> should be registered in the database. So the login utility will check for
> the password & email in the database if it is there than it will go to the
> app. form otherwise it will throw an error. It is working fine until I
want
> a dropdown in the form say that contains all the States and Cities of
India.
> I want this thing to retrieve from the database but initially I am
checking
> by hardcoding whether its working or not.
>
> So, my Action contains 2 method one is default execute() method which is
> populating the States of India but the problem is that in the struts.xml
> file when I am not stating any method than it is executing the default
> execute method and populating the dropdown but the validation method is
not
> executing and when I am passing the validating method than it is not
> populating the dropdown. I am sending my codes please help where I am
wrong,
> its very urgent yaar.
>
> I tried redirection also by Message-Store-Interceptor also but that is
also
> not working when I tried to write the states addition list separately in a
> class file.
>
> *Struts.xml*
> <action name="ApplyOL" class="net.Candidate.application.ApplyAction"
> method="applyinterface()">* --> For validation if I remove this method
than
> validation is not working but populating the dropdown.*
> <result name="input" type="tiles">Apply</result>
> <result name="error" type="tiles">Apply</result>
> <result name="success" type="tiles">OLAppForm</result>
> </action>
>
> *tiles.xml*
> <definition name="OLAppForm" extends="CandidateBaseLayout">
> <put-attribute name="title" value="INAT Online Application Registration"
/>
> <put-attribute name="menu" value="/Tiles/candidateMenu.jsp" />
> <put-attribute name="body" value="/pages/application/OLAppForm.jsp" />
> </definition>
>
> *ApplyAction.java*
> package net.Candidate.application;
>
> import java.io.*;
> import java.sql.*;
> import java.util.*;
>
> import com.opensymphony.xwork2.ActionSupport;
> import com.opensymphony.xwork2.ActionContext;
>
> import net.database.*;
> import net.Candidate.application.model.Apply;
> import net.Candidate.application.State;
>
> public class ApplyAction extends ActionSupport {
> private Apply apply;
> private List state;
> public String execute() throws Exception{
> System.out.println(state);
> state = new ArrayList();
> state.add("Maharashtra");
> state.add("Kerala");
> state.add("Karnataka");
> state.add("TamilNadu");
> return SUCCESS;
> }
> public List getState(){
> return state;
> }
> public String applyinterface() {
> try
> {
> Connection connect = null;
> ResultSet result = null;
> PreparedStatement pstmt = null;
> DBConnection getConnect = new DBConnection();
> connect = getConnect.getCon();
> int id=0;
> String qry = "SELECT id FROM Register WHERE AppEmail=? && RegPasswd=?";
> pstmt = connect.prepareStatement(qry);
> pstmt.setString(1, apply.getEmail());
> pstmt.setString(2, apply.getPassword());
> result = pstmt.executeQuery();
> while(result.next())
> {
> id = result.getInt(1);
> }
> System.out.println(id);
> boolean comparing = (id == 0);
> if (comparing == true)
> {
> addActionError(getText("validate_notRegistered"));
> return ERROR;
> }
> else
> {
> return SUCCESS;
> }
>
> } catch (SQLException e) {
> e.printStackTrace();
> }
> return SUCCESS;
> }
>
> public Apply getApply() {
> return apply;
> }
> public void setApply(Apply apply) {
> this.apply = apply;
> }
> }
>
> *Apply.java*
> package net.Candidate.application.model;
>
> import com.opensymphony.xwork2.ActionSupport;
>
> public class Apply extends ActionSupport{
> private String password;
> private String email;
>
> public String getPassword() {
> return password;
> }
> public void setPassword(String password) {
> this.password = password;
> }
>
> public String getEmail() {
> return email;
> }
> public void setEmail(String email) {
> this.email = email;
> }
> public Apply()
> {
> }
> }
>
>
> *JSP File*
> ---
> ---
> ---
> <s:select label="Select Day" name="daysname" headerKey="1" headerValue="--
> Please Select --" list="state"/>
> ---
> ---
> ---
>
> I am also trying like this......
> *ApplyAction.java*
> package net.Candidate.application;
>
> import java.io.*;
> import java.sql.*;
> import java.util.*;
>
> import com.opensymphony.xwork2.ActionSupport;
> import com.opensymphony.xwork2.ActionContext;
>
> import net.database.*;
> import net.Candidate.application.model.Apply;
> import net.Candidate.application.State;
>
> public class ApplyAction extends ActionSupport {
> private Apply apply;
> public String applyinterface() {
> try
> {
> Connection connect = null;
> ResultSet result = null;
> PreparedStatement pstmt = null;
> DBConnection getConnect = new DBConnection();
> connect = getConnect.getCon();
> int id=0;
> String qry = "SELECT id FROM Register WHERE AppEmail=? && RegPasswd=?";
> pstmt = connect.prepareStatement(qry);
> pstmt.setString(1, apply.getEmail());
> pstmt.setString(2, apply.getPassword());
> result = pstmt.executeQuery();
> while(result.next())
> {
> id = result.getInt(1);
> }
> System.out.println(id);
> boolean comparing = (id == 0);
> if (comparing == true)
> {
> addActionError(getText("validate_notRegistered"));
> return ERROR;
> }
> else
> {
> //return SUCCESS; <sx:head parseContent="true"/>
> int StateID = 0;
> String State = "";
> ResultSet result_state = null;
> String Stateqry = "Select * from state";
> pstmt = connect.prepareStatement(Stateqry);
> result_state = pstmt.executeQuery();
> {
> while (result_state.next())
> {
> StateID = result_state.getInt(1);
> State = result_state.getString(2);
> System.out.println(State);
> }
> }
> }
>
> } catch (SQLException e) {
> e.printStackTrace();
> }
> return SUCCESS;
> }
>
> public Apply getApply() {
> return apply;
> }
> public void setApply(Apply apply) {
> this.apply = apply;
> }
> }
>
> So, how can I pass the value of State & StateID in the jsp <s:select>
tag's
> list, I tried many options but neither of them working, Please
> help..........
>
> --
> Akshat

Reply via email to