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! :-)
Can you post the actual generated HTML, and can you post the controller action that handles the submission?
The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.
posted 4 months ago
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).
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.
An IDE is no substitute for an Intelligent Developer.
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