File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 8
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: 8
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: 8
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: dependency fields in Struts2
 
Similar Threads
iterate problem in struts2
Highlighting Multiple values in a Multi-Select dropdown using Struts2
Retaining the value in struts2 using Select and optionTransferSelect
how to hide and show contents with struts2 div tag
Struts2 Select tag