I know HTML is not a programming language and so applying Object Oriented principles is not possible, but, I have an annoying issue which would be simply solved if you could have a form tag inheriting from a parent form tag.
I want to split my JSP page up into logical form includes for various reasons, but mainly to aid the compartmentalisation of client side data input and associated server side handling in order to promote re-use of code. However, there is one common, page scope value which I require to be submitted along with each, individual form submit.
I could duplicate this one input within each form but it seems crazy to have the same value duplicated several times on a page. A javascript “onsubmit” function could also be the answer but that is useless when javascript is turned off. I could also have a session scope variable in my java storing the value but I’d rather avoid that.
Any ideas other than sucking up the code duplication on the jsp?
If you have individual forms on the page, then yes, you’ll have to duplicate the common piece of data in all of those forms; there’s no way to “inherit” it without using JavaScript on the client.
If it’s hidden information (and it sounds like it is), you can include in each form’s
actionattribute, and so your JSP code can make the duplication fairly innocuous:Alternately you can include a
hiddenfield in each form, again by doing it once in the JSP code and then dumping it out on each form.