struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gede Indrawan" <gede.indra...@gratika.co.id>
Subject Data transfer From Struts to JavaScript
Date Thu, 18 Dec 2003 09:53:03 GMT
Hi All,

I have jsp code below try to implement dynamic dropdown list
I utilize javascript code Dynamic Option List from
http://www.mattkruse.com/javascript/

I want 4 line hard code below (from that jsp code)

  listB.addOptions("1","bpp2","7","bpp3","8");
  listB.addOptions("2","bdl1","4","bdl3","5");
  listB.setDefaultOption("1","7");
  listB.setDefaultOption("2","4");

to be replace with dynamic value extract from:

     <html:optionsCollection property="locations" value="locationId"
label="locationName" />

become something like below

  listB.addOptions(  location[1].locationId, machine[1].machineName,
machine[1].machineId, machine[2].machineName, machine[2].machineId, ...,
machine[N].machineName, machine[N].machineId );
  listB.addOptions(  location[2].locationId, machine[1].machineName,
machine[1].machineId, machine[2].machineName, machine[2].machineId, ...,
machine[N].machineName, machine[N].machineId );
  ...
  listB.addOptions(  location[M].locationId, machine[1].machineName,
machine[1].machineId, machine[2].machineName, machine[2].machineId, ...,
machine[N].machineName, machine[N].machineId );

  listB.setDefaultOption( location[1].locationId, machine[1].machineId );

  listB.setDefaultOption( location[2].locationId, machine[1].machineId );

  ...
  listB.setDefaultOption( location[M].locationId, machine[1].machineId );


THE PROBLEM is:
All properties I need, inside

     <html:optionsCollection property="locations" value="locationId"
label="locationName" />

But I don't know how to transfer Location property (locationId) --as Object
array at Collection locations-- and Machine properties (machineId,
machineName) --as Object array on each Location-- into dynamic code above to
replace 4 line hardcode above.

Anyone expert out there can help?
Really appreciate your help.

TIA
-GI.

--------------------------------------------
JSP CODE :

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>

<HTML>

 <HEAD>
  <SCRIPT language=JavaScript src="<html:rewrite
page="/scripts/DynamicOptionList.js" />"></SCRIPT>

  <SCRIPT language=JavaScript>

  var listB = new
DynamicOptionList("machine.machineId","location.locationId");

  listB.addOptions("1","bpp2","7","bpp3","8");
  listB.addOptions("2","bdl1","4","bdl3","5");
  listB.setDefaultOption("1","7");
  listB.setDefaultOption("2","4");

  function init() {
   var theform = document.forms[0];
   listB.init(theform);
   fill(theform);
   }
  </SCRIPT>

 </HEAD>

<BODY onload=init()>

<html:form action="/addLogBook?method=executeAddLogBook">

 <table>

   <tr>
  <td><bean:message key="addLogBook.location" /></td>
  <td>
    <html:select property="location.locationId" onchange="listB.populate()">
    <html:optionsCollection property="locations" value="locationId"
label="locationName" />
   </html:select>
  </td>
   </tr>

 <tr>
  <td><bean:message key="addLogBook.machine" /></td>
  <TD>
   <html:select property="machine.machineId">
    <SCRIPT language=JavaScript>listB.printOptions()</SCRIPT>
   </html:select>
  </TD>
 </tr>

 </table>

</html:form>

</BODY>

</HTML>


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Mime
View raw message