Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

dependency fields in Struts2

 
Neha Kore
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic