File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes INDEX PROPERTY <html:form> with nested beans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "INDEX PROPERTY <html:form> with nested beans" Watch "INDEX PROPERTY <html:form> with nested beans" New topic
Author

INDEX PROPERTY <html:form> with nested beans

Prithwish Ghosh
Greenhorn

Joined: Mar 04, 2009
Posts: 9
How do I create a HTML form having indexed property control from multiple nested beans. My code is below -

Bean classes



My struts-config.xml -


JSP Pages -



This code generates html code like this -


So when I'm submitting the form its throwing NullPointerException. Is it possible to create index property control with multiple nested beans ?
Is possible then how to do that ?
As I understood about index property and class nesting hierarchy, HTML code should generate like below -

<input type="text" name="bean.ddetails[0].deptid" >
<input type="text" name="bean.ddetails[0].deptname" >
<input type="text" name="bean.ddetails[0].deptloc" >
.....
.....
<input type="text" name="bean.edetails[0].empid" >
<input type="text" name="bean.edetails[0].empname" >
<input type="text" name="bean.edetails[0].emploc" >

So that after submit the form, beans are properly filled from respective text box values.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Ok, Need one information, are you submitting or displaying employee department data through this JSP ?
If you are submitting then post the code for html:action tag


And there is a good resource here regarding Indexed properties, you may be interested !!


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Prithwish Ghosh
Greenhorn

Joined: Mar 04, 2009
Posts: 9
Sorry ! I've not mentioned the <html:form> tag. My <html:form tag points to the "/employee/PromotionProcess" action.
First I'm showing a form where user enters employee and department data tabular wise, i.e. multiple record at a time can be entered. After submit I'll take those data in an action and store them in
database. But data is not coming after submit. BeanUtility simple fails to map the text box names with the beans properties.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Prithwish Ghosh wrote: But data is not coming after submit.


Firstly, I think, the struts bean extends ActionForm class, which I don't see in your bean/form class.
And
Have you checked out whether the data is getting stored into Bean, print out this data into your action class, like

Prithwish Ghosh
Greenhorn

Joined: Mar 04, 2009
Posts: 9
Thanks Sagar for your help. I've searched out your given links and found some tricky things which gave me a different idea. I've changed my JSP page like below and my problem is solved -


Now this code generates HTML as I was looking for. Thanks to JavaRanch forum too.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Prithwish Ghosh wrote:Thanks Sagar for your help. I've searched out your given links and found some tricky things which gave me a different idea. I've changed my JSP page like below and my problem is solved -


I like your efforts, some people who joined JR just want ready code, but you searched and help yourself and that's the best thing of this forum, Its helps you to learn and engaged in some brainy discussion..

And you're welcome.

And lastly, you can avoid those scriptlet

and try some Els

Prithwish Ghosh
Greenhorn

Joined: Mar 04, 2009
Posts: 9
Actually I was not confident about EL. After your suggestion I've looked for EL tutorials and now using EL in my code like this -


Now it's working smoothly.
Thanks again.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Ok, I might wrong in explaining EL, Using El you can replace this whole,

as a


EL can access beans properties just by giving there properties name, so it expands as,




David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

That wouldn't render the text input element, though.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

David Newton wrote:That wouldn't render the text input element, though.

Oops, Yes. As I'm learning EL, tends to convert every thing into EL, forgetting its html:input :(
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: INDEX PROPERTY <html:form> with nested beans