tags:

views:

991

answers:

2

I have one simple User Registration form. It includes name, age, sex & city. But here city is coming form city master table & displaying user as a combo box. But when i am trying to store full user registration information through my UserDAO, how can i access that current selected city value ? My User Registration jsp form contains :

<s:form action="UserAction" >
            <s:textfield name="name" label="User Name" />
            <s:textfield name="age" label="Age" />
            <s:radio name="sex" label="Sex" list="{'M','F'}" />

            <s:select list="cities" key="cities.name"  listValue="name">
            </s:select>

        <s:submit />
</s:form>

Now i am calling UserAction's execute() method. It contains :

public String execute() throws Exception {
        UserDAO.insert(user);
        return SUCCESS;
    }

My DAO's insert method has following code :

 public static void insert(UserBean daoUb) throws Exception {
        Connection daoConn = null;
        CityBean cb=new CityBean();
        cb=daoUb.getCity();
        System.out.println("cb = "+cb);
        daoConn = connectionUtil.getConnection();

        Statement daoSt = daoConn.createStatement();
        String str = "INSERT user (name,age,sex,city) VALUES('" + daoUb.getName() + "'," + daoUb.getAge() + ",'" + daoUb.getSex() + "','"+cb.getName()+"')";
        daoSt.executeUpdate(str);
        //daoConn.close();
    }

Plz suggest me, if anyone have any suggestion. I am stuck with this problem....

+1  A: 

You can get that using similar method what you are using for other fields. The only thing you need to do is give that field a name.

Give your list the exact name what you have in your bean, in your case city. It should start working now.

Adeel Ansari
A: 

What Vinegar suggests is to modify your jsp like this

<s:select name="city" list="cities" key="cities.name"  listValue="name">
            </s:select>

This assumes that your bean has getters and setters for a city property which you have already implemented.

kazanaki