You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Gupta, Karan" <ka...@transcore.com> on 2006/01/13 00:15:44 UTC

How to use a POJO inside Struts FormBean?

Hi,

I am trying to use a POJO inside a Struts (1.2.7) FormBean, 
but I am unable to access the fields inside the POJO.

package com.fmm.web.inventory.forms;
public class IDefForm extends ActionForm
{
	private IDef iDef;
	private List inventoryDefinitions;
 
	...getters ..and...setters..
}

package com.fmm.web.inventory.beans;
public class IDef
{
	private long iDefID;
	private String partNumber;
	private String description;
	private int equipType;

	.....getters ...and...setters...
}

inventoryDefinitions is a simple ArrayList() which I populate in the Action class and can easily be 
used to display several objects using the logic:iterate tag.
To add an object to the underlying DB, I want to use the iDef object bean in my form, instead of
creating copies of all the individual fields in the form bean.

This is what I want the form to look like:
<html:form action="/iDef" styleId="createIDefForm">
	<html:hidden styleId="action" property="action" value="add"/>
	Part Number:
	<html:text styleId="partNumber" property="iDef.partNumber" size="50" maxlength="50"/>
	Description:
	<html:textarea styleId="description" property="iDef.description" rows="4" cols="40"/>

     ......and so on...

</html:form>

I get this exception:
javax.servlet.ServletException: No getter method for property iDef.partNumber of bean org.apache.struts.taglib.html.BEAN

So what is the way to achieve what I am trying to do?
What am I doing wrong?

Thanks,
Karan

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


Re: How to use a POJO inside Struts FormBean?

Posted by Torgeir Veimo <to...@pobox.com>.
On Thu, 2006-01-12 at 15:15 -0800, Gupta, Karan wrote:
> 
> I get this exception:
> javax.servlet.ServletException: No getter method for property
> iDef.partNumber of bean org.apache.struts.taglib.html.BEAN
> 
> So what is the way to achieve what I am trying to do?
> What am I doing wrong? 

Probably the bean property naming along with the setters and getters, we
need to see them all to see what's wrong. 

And your nested bean should be serializable. Did you look into using
nested tags?

-- 
Torgeir Veimo <to...@pobox.com>


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


Re: How to use a POJO inside Struts FormBean?

Posted by Hubert Rabago <hr...@gmail.com>.
You'll need to rename your "iDef" property if that is what you're
calling it, via getIDef/setIDef.  That pair will result in a property
name of "IDef".  If you'd rather not change your accessor methods,
then use "IDef.partNumber" instead of "iDef.partNumber".  [Wendy can
quote the JavaBean spec related to this :)]

Also, if you still get some error when the form is submitted, that may
mean you're putting the bean in request scope and the IDef property is
null and is not available during form bean population.  Make sure
getIDef() always returns a non-null result.

Hubert

On 1/12/06, Gupta, Karan <ka...@transcore.com> wrote:
> Hi,
>
> I am trying to use a POJO inside a Struts (1.2.7) FormBean,
> but I am unable to access the fields inside the POJO.
>
> package com.fmm.web.inventory.forms;
> public class IDefForm extends ActionForm
> {
>         private IDef iDef;
>         private List inventoryDefinitions;
>
>         ...getters ..and...setters..
> }
>
> package com.fmm.web.inventory.beans;
> public class IDef
> {
>         private long iDefID;
>         private String partNumber;
>         private String description;
>         private int equipType;
>
>         .....getters ...and...setters...
> }
>
> inventoryDefinitions is a simple ArrayList() which I populate in the Action class and can easily be
> used to display several objects using the logic:iterate tag.
> To add an object to the underlying DB, I want to use the iDef object bean in my form, instead of
> creating copies of all the individual fields in the form bean.
>
> This is what I want the form to look like:
> <html:form action="/iDef" styleId="createIDefForm">
>         <html:hidden styleId="action" property="action" value="add"/>
>         Part Number:
>         <html:text styleId="partNumber" property="iDef.partNumber" size="50" maxlength="50"/>
>         Description:
>         <html:textarea styleId="description" property="iDef.description" rows="4" cols="40"/>
>
>      ......and so on...
>
> </html:form>
>
> I get this exception:
> javax.servlet.ServletException: No getter method for property iDef.partNumber of bean org.apache.struts.taglib.html.BEAN
>
> So what is the way to achieve what I am trying to do?
> What am I doing wrong?
>
> Thanks,
> Karan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

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