struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rick Col <rick_c...@yahoo.com>
Subject RE: newbie question: Java array to JavaScript Array
Date Fri, 25 Jul 2003 21:09:58 GMT
Hahahahaha.....Kris, yes this is sickening. More so
after trying all possible solutions. This ruined my
Friday :((.

regards,

Rick  


--- Kris Schneider <kris@dotech.com> wrote:
> Man, this is really sick ;-). If I'm understanding
> you, maybe this will work (or
> maybe not...):
> 
> var products = new Array();
> <logic:iterate id="productBeans" name="products"
> indexId="i">
>   var productBeans<bean:write name="i"/> = new
> Array();
>   <logic:iterate id="productBean"
> name="productBeans" indexId="j">
>     productBeans<bean:write name="i"/>[<bean:write
> name="j"/>] = ["<bean:write
> name="productBean" property="productName"/>",
>                                                     
>              "<bean:write
> name="productBean" property="productId"/>"];
>   </logic:iterate>
>   products[<bean:write name="i"/>] =
> productBeans<bean:write name="i"/>;
> </logic:iterate>
> 
> 
> Quoting Rick Col <rick_cols@yahoo.com>:
> 
> > Hi,
> > 
> > I did the following, but the results were not
> > displayed.
> > Whats wrong with my code?
> > 
> > >>>>>>>>>>
> > products is a collection of ArrayLists, every
> > arrayList contains
> > a list of ProductBeans, ProductBean has
> productName
> > and productId properties.
> > 
> > products are retrieved in action class and are put
> > into session scope:
> > session.setAttribute("products", products);
> > 
> > var productsArray = new Array();
> > 
> > <logic:iterate id = "aList" name = "products"
> indexId
> > = "idx">
> > 	<logic:iterate id = "ProductBean" name = "aList"
> > indexId = "index">
> > 		productsArray[<%=idx%>][<%=index%>] 
> > 			= new Array(<bean:write name = "ProductBean"
> > property = "productName"/>,
> > 			           <bean:write name = "ProductBean"
> > property = "productId"/>);
> > 	</logic:iterate>
> > </logic:iterate>
> > >>>>>>>>>>>>>
> > 
> > Thanks in advance.
> > 
> > rick
> > 
> > 
> > 
> > --- Rick Col <rick_cols@yahoo.com> wrote:
> > > More questions about the following:
> > > 
> > > 1) It says in logic tags reference:
> > > id: "The name of a page scope JSP bean that will
> > > contain the current element of the collection on
> > > each
> > > iteration, if it is not null."
> > > 
> > > So, it means myList ArrayList should conform
> > > to JavaBean routines, is that right? For
> example:
> > > 
> > > If I have a List4Js class, it has to have
> > > getters/seters
> > > for getting/setting ArrayLists:
> > > 
> > > ArrayList myList = List4J.getResultList();
> > > 
> > > And the elements of an ArrayList should be a
> bean
> > > too.
> > > 
> > > 2) If I want to get a collection of arraylists,
> I
> > > can
> > > use the <logic:iterate> tag as following:
> > > 
> > >  <logic:iterate id="jsList"
> name="listForJavaScript"
> > >              indexId="idx">
> > >     <logic:iterate id="myBean" name="jsList"
> > >              indexId="index">
> > >         jsArray[<%=idx%>][<%=index%>] = 
> > >              <%=myBean.getYourValue()%>;
> > >     </logic:iterate>	
> > > </logic:iterate>		
> > >  
> > > Since JavaScript Array usually has the following
> > > form:
> > >   myArray = new Array("sample", 1);
> > > 
> > > Do I need to conform to the above routine to
> create
> > > an
> > > 
> > > JavaScript Array element in order to correctly
> > > display
> > > the results?
> > > 
> > > regards,
> > > 
> > > rick
> > > 
> > > 
> > > 
> > > 
> > > 
> > > 
> > > --- James Childers <jchilders@hotels.com> wrote:
> > > > You'll need to do a couple of things:
> > > > 
> > > > 1) (Assuming you're using Struts, of course.)
> > > Create
> > > > your Java array/collection/whatever in the
> Action
> > > > that gets hit before your JSP page:
> > > > 	List myList = new ArrayList();
> > > > 	// populate the list, la la la
> > > > 	request.addAttribute("listForJavascript",
> > > myList);
> > > > 	return mapping.findForward("success"); 	//
> Takes
> > > > you to, say, bongabonga.jsp
> > > > 
> > > > 2) In bongabonga.jsp:
> > > > 	<head>
> > > > 	<script type="text/javascript">
> > > > 		var jsArray = new Array();		// Do you have
> to
> > > init
> > > > this? I don't remember.
> > > > 		<logic:iterate id="jsList"
> > > > name="listForJavaScript" indexId="idx">
> > > > 			jsArray[<%=idx%>] =
> <%=jsList.getYourValue()%>;
> > > > 		</logic:iterate>		
> > > > 	</script>
> > > > 	
> > > > 3) Debug. This is all from memory. I'm sure
> there
> > > > are some glaring errors here, but this is the
> > > > general flow.
> > > > 
> > > > -= J
> 
> -- 
> Kris Schneider <mailto:kris@dotech.com>
> D.O.Tech       <http://www.dotech.com/>
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> struts-user-help@jakarta.apache.org
> 


__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.com

---------------------------------------------------------------------
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