wood burning stoves 2.0*
The moose likes Struts and the fly likes Data loading problem in select tag using ajax in struts2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Data loading problem in select tag using ajax in struts2" Watch "Data loading problem in select tag using ajax in struts2" New topic
Author

Data loading problem in select tag using ajax in struts2

sam raghav
Greenhorn

Joined: Jul 10, 2009
Posts: 10
Dear all,

I am new to struts. I have some code like this.

registration.jsp
------------------
<body onload = "doRequestGETState(' StateAction?stateBn.state= ' + '');">
<span id = "inp" />
</body>

registrationInput.jsp
<s:fielderror/>
<s:actionerror/>

<s:select name="regBn.stateId" list="stateList" cssStyle="width: 180px;"
title="State" tabindex="1" onchange="doRequestGETState(' StateAction?stateBn.state=' + this.value); "
listValue="stateName" listKey="stateId" value="stateBn.state" headerKey=""
headerValue="Select State"/>

<s:select name="regBn.city" list="cityList" cssStyle="width: 180px;" title="City" tabindex="1"
listValue="cityName" listKey="cityId" headerKey="" headerValue="Select City" />


struts.xml
--------------
<action name="StateAction" class="com.iMovers.res.action.StateAction">
<result name="success">/registrationInput.jsp</result>
</action>

<action name="RegistrationAction" class="com.iMovers.res.action.RegistrationAction">
<result name="input">/registrationInput.jsp</result>
</action>


Problem is on validating registrationInput.jsp and coming back to registrationInput.jsp I am getting error

"The requested list key 'stateList' could not be resolved as a collection/array/map/enumeration/iterator type."

If I will change the result name from registrationInput.jsp to registration.jsp then I can not display error message.

Please let me know If there is any way to come out of it.

Thanks and regards
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Actions are instantiated per-request: the collection still needs to exist for the collection to be displayed.
sam raghav
Greenhorn

Joined: Jul 10, 2009
Posts: 10
Thanks for the reply.

Yes I know it is session less and server has to ping again before displaying the collections. But if I ping the server then I will lost the error messages.

Is there any way to come out of it.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Either keep the list in session or application context, re-generate it, or use the message store interceptor to keep the messages across the requests.
sam raghav
Greenhorn

Joined: Jul 10, 2009
Posts: 10
Thanks for the continuous support.
Please give me a example. That will be more helpful for me.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

An example of what? Putting a variable into a scope? Creating a collection? Using the message store interceptor?
sam raghav
Greenhorn

Joined: Jul 10, 2009
Posts: 10
David thanks for your continuous support.
I have used Message Store Interceptor. But after using that I am able to reclaim the message wherever I want but because of this I loses all the current request attributes.

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Not *because* of the message store interceptor. You're losing request attributes because you're making another request.
sam raghav
Greenhorn

Joined: Jul 10, 2009
Posts: 10
As I have given in first post, I am using ajax to fill dependent select box,

-----------------------------------
<body onload = "doRequestGETState(' StateAction?stateBn.state= ' + '');">
<span id = "inp" />
</body>
------------------------------------

so, request will go automatically when it will forwarded to registration.jsp.
 
 
subject: Data loading problem in select tag using ajax in struts2
 
Similar Threads
How to retain value in struts 2 using <s:select></s:select> tag
Problem while implementing cascade select option in Struts2 [City/Locality/Streets]
Struts select tag problem
Struts
s:select and data conversion