my dog learned polymorphism*
The moose likes Struts and the fly likes logic:iterate ??  Urgent - please help!!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "logic:iterate ??  Urgent - please help!!!!" Watch "logic:iterate ??  Urgent - please help!!!!" New topic
Author

logic:iterate ?? Urgent - please help!!!!

Kate Wilson
Greenhorn

Joined: Mar 23, 2004
Posts: 12
I have some java code in a jsp page that I want to change to use the Struts logic:iterate instead of the for loop.
Can someone pls. help me? I tried using the logic:iterate, but didn't know how to set the values. My code is shown below:
---------------------------------------------------
<%@ page import="mypkg.*" %>
<%
// get the productobject put to request from previous jsp's viewAction
// and get the individual field values.
myObject myobj= (myObject) request.getAttribute("productobj");
String p_id = myobj.getPid();
String time = myobj.getTime();
String product= myobj.getProduct();
String price= myobj.getPrice();
String imgreq = myobj.getImage();
System.out.println("img in jsp is " + imgreq);
%>
-------------------------------------------
I'm pre-populating my form with the above values.. for editing functionality... based on the value returned by getImage() - [which is either "Y" or "N"], I have to set the appropriate radio button. With the above code, all my fields are populated with dynamic data except the radio button. This doesn't get set.
Is there any way, I can set the radio button without changing the code to logic:iterate? All related documents that I found on the net points to the use of logic:iterate. But I'm unable to set my values using this.
Thanks,
Kate
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30762
    
156

Kate,
There's actually two concepts in this question. As you stated, logic:iterate is the struts alternative to a for loop. Html:form is the struts equivalent to a form tag. Your question really lies within the form.
If you want to use the form from struts, you need to set the radio button field within the java ActionForm. You can set it based on the image type. Without using struts, you can set the radio button in pure html:


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Kate Wilson
Greenhorn

Joined: Mar 23, 2004
Posts: 12
Originally posted by Jeanne Boyarsky:
Kate,
There's actually two concepts in this question. As you stated, logic:iterate is the struts alternative to a for loop. Html:form is the struts equivalent to a form tag. Your question really lies within the form.
If you want to use the form from struts, you need to set the radio button field within the java ActionForm. You can set it based on the image type. Without using struts, you can set the radio button in pure html:


Thanks a lot Jeanne, that worked. If I were to use logic:iterate tag, for the entire code, how would I do this? I read that it is always better to use the built-in tags from struts instead of the java code whenever possible.. can ou pls help? I tried setting the radio button in the action form, but it didn't work. Can you pls. point me to some docs where I can get the commands to output elements onto the jsp page from an action form/class?
HanMing Low
Ranch Hand

Joined: Oct 18, 2001
Posts: 196
Hi,
I'm not sure if this will directly help you.
But as far as I know about using Struts tag on checkbox, the value you define for the checkbox must equals to the property value of the action form you set in back end in order for it to be checked by default.
e.g.
in Action
((MyActionForm) actionForm).setCheckBx("a");
in jsp
<html:checkbox property="checkBx" value="a" />
In this case, the setCheckBx value in java code ("a" in this case) must be equal to the tag value in the jsp.
So, if you setCheckBx("checked");
Your <html: ... value="checked" />
in order for the checked box to be checked by default.
Hope this helps.
Cheers.

Han Ming
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30762
    
156

Kate,
To use logic:iterate you need a loop. I don't see one of those in your code snippet.
The built-in tag for what you want is html:form and it's associated tags. It is definitely better to use built-in tags.
I tried setting the radio button in the action form, but it didn't work.

This is the right idea. The official reference has all the syntax. You can try posting here specifically what didn't work.
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Moving this to the Struts forum...


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
jQuery in Action, 2nd edition
 
subject: logic:iterate ?? Urgent - please help!!!!