This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes dependency fields 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 "dependency fields in Struts2 " Watch "dependency fields in Struts2 " New topic
Author

dependency fields in Struts2

Neha Kore
Greenhorn

Joined: Feb 13, 2012
Posts: 9
Hi,

I have a list containing id,itemName and price.

And i want to show the itemName as select list and onchange of itemName, price should be displayed in the textfield automatically.

How to achieve this in Struts2 please help me in this regard,

my code is as follows

in action class i am fetching the itemlist as
List<Items> listItemsLi = transSer.getItems();//transSer is a service classs obj

and in jsp
<s:select list="%{listItemsLi}" name="itemId" id="itemId" headerKey="0" headerValue="---Select---" listKey="%{itemId}" listValue="%{itemName}" cssStyle="width:100%" onchange="setPrice(this.value);"/>// this value is set by ajax call to load xml file content,

<s:textfield name="price" id="price" maxlength="25" cssStyle="width:100%" />

need solution for this without ajax call.

thanks in advance
Ayan mallick
Ranch Hand

Joined: Nov 17, 2012
Posts: 44
I don't know why you don't want an ajax call here. Because one portion of page you want to change dynamically keeping rest unaffected that's what is the idea behind ajax.
Neha Kore
Greenhorn

Joined: Feb 13, 2012
Posts: 9
Hi,
How store the list values of action class into javascript array in jsp of Struts2?
Converting List values of action class to javascript array.
Rest i will handle with function call.
Help will be greatefull,

Thanks
Ayan mallick
Ranch Hand

Joined: Nov 17, 2012
Posts: 44
Yes that could be done. inside the controller you create json String like this. and put that String in request along with item list. and jsp part will be like this



I have tested it and it's working. yes if we go this way we don't have to call ajax that's a time saver. put your iteration logic inside function because you need to find out what item has been selected that particular object price you need to show.


Neha Kore
Greenhorn

Joined: Feb 13, 2012
Posts: 9
Hi,
I want the java script array of this type

var itemId = [
#set ($ctr=1)
#set ($listsize = $listItemsLi.size()) //list from action class
#foreach($item in $listItemsLi)
#if($ctr<$listsize)
["0","$item.itemId","$item.itemName","$ctr","$listsize","$item.itemPrice"],
#else
["0","$item.itemId","$item.itemName","$ctr","$listsize","$item.itemPrice"]
#end
#set ($ctr=$ctr+1)
#end

];


which we do normally in other frameworks but how to get this is done in struts2?
 
Don't get me started about those stupid light bulbs.
 
subject: dependency fields in Struts2
 
Similar Threads
Struts2 Select tag
how to hide and show contents with struts2 div tag
Highlighting Multiple values in a Multi-Select dropdown using Struts2
Retaining the value in struts2 using Select and optionTransferSelect
iterate problem in struts2