• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

INDEX PROPERTY <html:form> with nested beans

 
Prithwish Ghosh
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 !!
 
Prithwish Ghosh
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That wouldn't render the text input element, though.
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 :(
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic