You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Mu Mike <mi...@hotmail.com> on 2004/03/15 09:03:44 UTC

please help, using logic:iterate and html:form

Hi, all, last week, I spent a whole day trying to figure the below problem 
out, and you warmhearted guys just came and helped me,but to greatly 
disappiont you, I m still at a loss to know where the problem is ,so I 
decided to explain detailedly and completely of what I did and hope you 
nice buddies can help me find the problem


goal: I want to submit an array of Fonbean(java class file listed below) to 
an action
strategy: I decide to use html:form and logic:iterate to do this

1.what I have in my configruation xml

        <form-beans> 
            <form-bean name="testBeanForm" 
type="com.mycom.form.TestBeanForm"/>
        </form-beans>

       <action-mappings>
         <action path="/testAction"
            type="com.mycom.action.TestAction"
            name="testBeanForm"
            scope="session">
         </action>
       </action-mappings>

2.TestBeanForm.java

public class TestBeanForm extends ActionForm {

    public FontBean[] getTestBean() {
        if(testBean==null)
        {
          testBean=new FontBean[2];
          testBean[0]=new FontBean();
          testBean[1]=new FontBean();
        }
        return testBean;
    }

    public void setTestBean(FontBean[] testBean) {
        this.testBean = testBean;
    }

    FontBean[] testBean;
}


3. FontBean.java

public class FontBean  {
    public int getSize() {
        return size;
    }

    public void setSize(int size) {
        this.size = size;
    }

    public String getFontName() {
        return fontName;
    }

    public void setFontName(String fontName) {
        this.fontName = fontName;
    }

    private int size;
    private String fontName;

}

4. my jsp file

<html:form action="/testAction.do">
   <logic:iterate  name="testBeanForm" property="testBean" 
type="com.mycom.bean.propertybean.FontBean" id="mybean" indexId="index1">
      <html:text name="mybean" property="fontName" value="font1" 
indexed="true"/>

      /* I think when I submit, the testBeanForm will automatically fill 
its testBean's elements of their fontName attributes with "font1" */

   </logic:iterate>
   <html:submit property="submitValue">Submit Changes</html:submit>
</html:form>


5.my action class file

public class TestAction extends Action {
    public ActionForward execute(ActionMapping actionMapping,
                                 ActionForm form,
                                 HttpServletRequest servletRequest,
                                 HttpServletResponse servletResponse) 
throws Exception
    {
        System.out.println("stepped into action");
        TestBeanForm bform=(TestBeanForm)form;

 /*I stopped here to check if the form has its testBean variable filled 
with
"font1" of its fontName attribute, but it doesnt, the testBean of form is 
just the object I created in getTestBean(),that is, contains two elements, 
both the fontName attributes of the two elements are null */
         
        return actionMapping.findForward("error");
    }
}



so what on earth is the problem?

Thanks&Regards
Mike

_________________________________________________________________
享用世界上最大的电子邮件系统― MSN Hotmail。  http://www.hotmail.com  


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


Re: please help, using logic:iterate and html:form

Posted by as as <sa...@yahoo.com>.
Mike,

What error are you getting....
 
-Sam.

Mu Mike <mi...@hotmail.com> wrote:
Hi, all, last week, I spent a whole day trying to figure the below problem 
out, and you warmhearted guys just came and helped me,but to greatly 
disappiont you, I m still at a loss to know where the problem is ,so I 
decided to explain detailedly and completely of what I did and hope you 
nice buddies can help me find the problem


goal: I want to submit an array of Fonbean(java class file listed below) to 
an action
strategy: I decide to use html:form and logic:iterate to do this

1.what I have in my configruation xml


type="com.mycom.form.TestBeanForm"/>



type="com.mycom.action.TestAction"
name="testBeanForm"
scope="session">



2.TestBeanForm.java

public class TestBeanForm extends ActionForm {

public FontBean[] getTestBean() {
if(testBean==null)
{
testBean=new FontBean[2];
testBean[0]=new FontBean();
testBean[1]=new FontBean();
}
return testBean;
}

public void setTestBean(FontBean[] testBean) {
this.testBean = testBean;
}

FontBean[] testBean;
}


3. FontBean.java

public class FontBean {
public int getSize() {
return size;
}

public void setSize(int size) {
this.size = size;
}

public String getFontName() {
return fontName;
}

public void setFontName(String fontName) {
this.fontName = fontName;
}

private int size;
private String fontName;

}

4. my jsp file


type="com.mycom.bean.propertybean.FontBean" id="mybean" indexId="index1">
indexed="true"/>

/* I think when I submit, the testBeanForm will automatically fill 
its testBean's elements of their fontName attributes with "font1" */


Submit Changes



5.my action class file

public class TestAction extends Action {
public ActionForward execute(ActionMapping actionMapping,
ActionForm form,
HttpServletRequest servletRequest,
HttpServletResponse servletResponse) 
throws Exception
{
System.out.println("stepped into action");
TestBeanForm bform=(TestBeanForm)form;

/*I stopped here to check if the form has its testBean variable filled 
with
"font1" of its fontName attribute, but it doesnt, the testBean of form is 
just the object I created in getTestBean(),that is, contains two elements, 
both the fontName attributes of the two elements are null */

return actionMapping.findForward("error");
}
}



so what on earth is the problem?

Thanks&Regards
Mike

_________________________________________________________________
�������������ĵ����ʼ�ϵͳ�� MSN Hotmail�� http://www.hotmail.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!?
Yahoo! Mail - More reliable, more storage, less spam