tags:

views:

6447

answers:

4

I have simple user registration form. In which i am puting city as a tag. Here drop down box value coming from city master table from mysql database.

But when i storing whole user registration values, i m not be able to fetch currently selected city value. Can anyone help me...? My user registration 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>
+1  A: 

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

Adeel Ansari
But i have passing this page to UserAction.action Java Page. So, can UserAction be act as a servlet ? Because right now my UserAction is simple Java Class. No HttpRequest object is created in UserAction.
Nirmal
So, how are you getting the other fields, for example name and age?
Adeel Ansari
Oh... its all automagically going there. Sorry edited the post. Please check.
Adeel Ansari
A: 

Finally got the solution after writing following code :

            <s:select list="cities" name="city">
            <s:iterator value="cities">
            </s:iterator>
        </s:select>

And at the time of insertion through DAO, it will automatically fetching all the value from bean.

Nirmal
You should accept my answer in that case. In both the places. :)
Adeel Ansari
Actually, i haven't use any request or session object, so no getParamter() or getAttribute() function has been used.
Nirmal
May be, but the fact is all those are there in request context as parameters. Struts hides that from you.
Adeel Ansari
A: 

hi am new to this strut2 world.how to validate select tag in struts2?. i have to implement it in my project. if nothing is selected in select tag. application shd ask user to select something in select tag. i will be waiting for reply. pls do reply

A: 

Hi chandru,

In your action class you are probably have an attribute based on the select tag. When you set this value add an annotation above the method signature.

Something like:

@RequiredStringValidator(type = ValidatorType.SIMPLE, message = "Please select a value", fieldName = "select")

This should sort you out. This can also be done within the struts.xml file in a fairly similar way.

Cheers Nathan

nathj07