I never understood why HTML spec, still links the action of a form to the form itself: in a form you may need more possibility (edit, delete, insert, etc...) and you'll have many buttons then, so I think that html should link the action to the button, like in any intelligent gui language.
So it would be more useful a tag like:
<input type="submit" action="servleturl"/>
In current project we used Tag Files, a feature available in JSP 2.0 specification: you can write tags using JSP, and this is very good if your tags must produce some template code.
One of our Tag File uses a syntax like the following:
<my:button action="update.jspa" > <ww:text name="'application.update.button'" /> </my:button>
The action identifies the application controller (i.e. a servlet) that will be executed when button is clicked.
The label of the button is defined by the body content of the my:button tag. In this case the "<ww:text name="'application.modify.button'" />" is resolved by a webwork <ww:text /> tag that provides internationalization(i.e. will display: "update" string for Americans, and "aggiorna" for Italians).
With a simple javavascript I am able to obtain enclosing form (owner of the button), changing the action of the form tag on the fly, then submit the form: in this way, buttons are associated with action.
The <form /> tag will specify the action attribute as an empty string (as it is mandatory): <form action=""/>
The nice thing of having a body of the tag button, is that you can include something inside it, and you are completely free! (you can insert a table, if you like... hey, stop! don't do that!).
For example, an icon with corresponding description:
<my:button action="http://www.google.com/"> <ww:url id="imagesurl" value="'http://it.newinstance.it/wp-content/uploads/2006/10/export.png'" includeParams="'none'" /> <img style="border: 0; vertical-align: middle; margin-right: 5px;" src="<ww:property value="#imagesurl"/>"/> <ww:text name="'application.export.button'" /> </my:button>
And this, executing our custom jsp tag file, will render as:
<button onclick="form.action='http://www.google.com/'; form.submit(); return false" > <img style="border: 0px none; vertical-align: middle; margin-right: 5px;" src="http://it.newinstance.it/wp-content/uploads/2006/10/export.png" /> Export </button>
I won't show here the source code for the button.tag file: it's really trivial, and ... I would have problems with copyright, but the concept is there, and writing a tag that translate the <my:button/> in the source shown, it's really easy.
|« Aug||Oct »|
- Android (3)
- Apple (30)
- Books (7)
- Eclipse (14)
- Errors (5)
- Firefox (7)
- Git (3)
- Hardware (18)
- Horror Code (8)
- Internet (21)
- Java (106)
- Life, universe and everything (45)
- Lifehacks (26)
- Linux (53)
- Opinions (26)
- OSX (11)
- OWNER API (3)
- Python (1)
- Software (35)
- Speeches and Conferences (8)
- Unix (5)
- Web (23)
- Windows (19)
Android apple architecture Bash bsd configuration CSS Development Düsseldorf framework free Git Google Hardware hdr How-To howto Java Karmic library Linux lion MacBook maven opensource Open Source Opinion os x OSX owner owner api patterns Pitfalls Practices properties Software TDD Testing tip tonemapped Tricks Ubuntu unix video Web