File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes creating html form dynamically using logic:iterate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "creating html form dynamically using logic:iterate" Watch "creating html form dynamically using logic:iterate" New topic

creating html form dynamically using logic:iterate

Ann Anderson

Joined: Dec 29, 2008
Posts: 7
I am new to Struts. I have retrieved data dynamically in form of list in action class.Now I want to write each row in different html form with two submit buttons on each form on the same page. i.e I want to create dynamic <html:form> with dynamic <html:submit> on it with a row of data retrieved dynamically. Please someone help me out.

Thanks in advance
Regards Ann
Suman Mainam

Joined: Apr 16, 2008
Posts: 5

Ann, I strange to here about your post, tell me one thing wha is the neccessity to create dynamic forms with dynamic submit(), actually as for the struts we have seperate form for each jsp page, and by default we use that forname everywhere in that whole html.

anyways try with this code it may help you

<logic:iterate name="formBeanName" type="package root of formBeanName" property="args" id="id" indexId="indId">
<html:form action="/actionName">
// enter the required code here

each form will have a seperate formName and submit

Ann Anderson

Joined: Dec 29, 2008
Posts: 7
Thanks Suman

I have tried the same code you have written below but my page was not displayed when I added the line
<html:form action="/actionName"> so I felt I was wrong somewhere. I will try again.
Below is the code.

I am using struts1.3.10

This is my Action class
public class ViewCelebrity extends Action {

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)throws Exception{
List listLoginData = new ArrayList();
SessionFactory sessionFactory;
Session session;
Transaction transaction;
Configuration configuration;
Query query;

try {
LoginForm loginForm = new LoginForm();
sessionFactory=new Configuration().configure().buildSessionFactory();
query = session.createQuery("from LoginForm loginData");
listLoginData = query.list();
request.setAttribute("listLoginData", listLoginData);
catch(Exception e){

return mapping.findForward("success");
}//end of execute

This is my ActionForm calss

public class LoginForm extends ValidatorForm{

private String userName;
private String passWord;
private String pin;
private String reType;

public void setUserName(String userName){
this.userName = userName;
System.out.println("Inside setUserName");

public void setPassWord(String passWord){
this.passWord = passWord;
System.out.println("Inside setPassWord");

public void setPin(String pin){ = pin;
System.out.println("Inside setPin");

public void setReType(String reType){
this.reType = reType;
System.out.println("Inside setReType");

public String getUserName(){
System.out.println("Inside getUserName");
return userName;

public String getPassWord(){
System.out.println("Inside getPassWord");
return passWord;

public String getPin(){
System.out.println("Inside getPin");
return pin;

public String getReType(){
System.out.println("Inside getReType");
return reType;

public void reset(){


This is my .jsp page

<tiles:insert attribute="header"/>
<table bgcolor="green" width="100%">
<td>User Name</td>
<logic:iterate id="cele" name="listLoginData">
<html:form action="/action">
<td><bean:write name="cele" property="userName" /></td>
<td><bean:write name="cele" property="passWord"/></td>
<td><bean:write name="cele" property="pin"/></td>
<tiles:insert attribute="footer"/>


I have one more question. I want each row to be placed on different tile and insert the tiles on this page dynamically. How should i do?

I agree. Here's the link:
subject: creating html form dynamically using logic:iterate
It's not a secret anymore!