You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Joe Smith <ap...@yahoo.com> on 2004/10/15 19:56:42 UTC

process regular fields in html form

When we process the form data without file upload control in JSP. We can use JavaBeans in JSP, then the following will store all the request form data to MyObjectModel object:

 

<jsp:useBean id="om" class="MyObjectModel" />

<jsp:setProperty name="om" property="*" />

 

However, when we process the form data that contains file upload, and uses commons-fileupload, then we should approach the following, is that correct? 

 

if (item.isFormField())

{

      String name = item.getFieldName();

      String value = item.getString();

      

      MyObjectModel om = new MyObjectModel();

      if (name.equals("fieldName1"))

            ad.setFieldName1(value);

      else if (name.equals("fieldName2"))

            ad. setFieldName2(value);

      else if (name.equals("fieldName3"))

            ad.setFieldName3(value);

      //etc...

}

 

Please advise. Thanks!!

 

		
---------------------------------
Do you Yahoo!?
Yahoo! Mail Address AutoComplete - You start. We finish.

Re: process regular fields in html form

Posted by Martin Cooper <mf...@gmail.com>.
That's basically correct. However, you could use Commons BeanUtils to
help make this cleaner and a lot shorter. Something like this should
do it:

    String name = item.getFieldName();
    String value = item.getString();
    MyObjectModel om = new MyObjectModel();
    PropertyUtils.setProperty(om, name, value);

There is also a pending enhancement to FileUpload to provide a request
wrapper so that non-file parameters can be accessed in the same manner
as for regular requests. I am hoping to get to that very soon.

--
Martin Cooper


On Fri, 15 Oct 2004 10:56:42 -0700 (PDT), Joe Smith <ap...@yahoo.com> wrote:
> 
> When we process the form data without file upload control in JSP. We can use JavaBeans in JSP, then the following will store all the request form data to MyObjectModel object:
> 
> <jsp:useBean id="om" class="MyObjectModel" />
> 
> <jsp:setProperty name="om" property="*" />
> 
> However, when we process the form data that contains file upload, and uses commons-fileupload, then we should approach the following, is that correct?
> 
> if (item.isFormField())
> 
> {
> 
>      String name = item.getFieldName();
> 
>      String value = item.getString();
> 
>      MyObjectModel om = new MyObjectModel();
> 
>      if (name.equals("fieldName1"))
> 
>            ad.setFieldName1(value);
> 
>      else if (name.equals("fieldName2"))
> 
>            ad. setFieldName2(value);
> 
>      else if (name.equals("fieldName3"))
> 
>            ad.setFieldName3(value);
> 
>      //etc...
> 
> }
> 
> Please advise. Thanks!!
> 
> 
> ---------------------------------
> Do you Yahoo!?
> Yahoo! Mail Address AutoComplete - You start. We finish.
>

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