• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

dynamically generated form doesn't save values to bean  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys!

I would like to generate a form dynamically. I have this stripped-down code that generates my form:I put it into my template via:

Up to here it works fine. The form is generated well. But unfortunately expecting the value is saved as parameter (String input) of my bean, it remains null and I get
Maybe important: While trying to debug I found out that if I set this.input before generating the form, the field takes the value as pre-filled.

I am a littel bit desperated atm and would be very happy if someone could help me. Thanks in advance! :-)

Jan
 
Bartender
Posts: 9559
189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

Can you post the actual generated HTML, and can you post the controller action that handles the submission?
 
Jan Worpenberg
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, thank you, Stephan! :-)

Here is the generated HTML:

For testing-issues I use the default controller, so I have not yet specified a custom one. When I write my form static into the template it works like a charm: The submitted value is saved into the bean and auto-filled to the field, also after refreshing the page (oh, forgot to tell: the bean is sessionscoped).
 
Bartender
Posts: 20125
103
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One thing I learned long ago is that it's a lot simpler to simply code the View entirely in the View Template file and merely switch rendering on and off for dynamic sub-Views. Actually, I learned a VERY long time ago while working on Macintosh apps that dynamic view layouts can be very confusing to the user. They feel more comfortable when what they see is consistent. And, of course, it's pretty hard to create an illustrated support document if your screenshots don't match what they see on the screen.

I have only done one major app that generated a View dynamically and that was a database raw table editor, where I created collections of input controls based on the number and types of the different fields based on the jdbc metadata. If I was to do it again, it probably would not be done using dynamic code.

Still, never say never. Sometimes there's no other way. But if you do, I recommend that you keep the generated controls to a minimum. For example, statically define the form and its invariant controls (such as submit/reset buttons) in the View Template. and bind the variable items within the form - don't define the entire form as dynamic. Also, I highly recommend that when you do define controls, whether in the Template or in code, that you give each one an id attribute. It can make debugging a lot easier.

Now as to your actual problem. Without going so far as to code it all up and run through it in detail, my suspicion is that you're attempting to reference stuff that doesn't get defined until the first render-response stage, but you're sampling it during the initial restore-view phase. So you're attempting to grab data from places that don't yet exist, since the controls that supply them haven't been generated and bound at that point.
 
Something about .... going for a swim. With this tiny ad ...
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!