• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Kate Wilson
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34208
341
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
Kate Wilson
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34208
341
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the Struts forum...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic