View Full Version : dojo and spring form tags?
lumpynose
Nov 7th, 2007, 12:29 AM
Dojo adds 'dojoType' tags to the form tags, like so:
<input type="text" name="name" dojoType="dijit.form.TextBox" /> Is there any way to use this with the spring form tags?
pmularien
Nov 7th, 2007, 08:11 AM
No, unfortunately you can't use Dojo/Dijit that way with Spring's form tags (and many/most other JSP taglib-type tags). You'll have to look at setting up the Dijit tags programmatically via Javascript (http://www.dojotoolkit.org/book/dojo-book-0-9/part-3-programmatic-dijit-and-dojo/manipulating-widgets-through-code/displaying-w). Good luck!
lumpynose
Nov 7th, 2007, 01:13 PM
Ok. Thanks for pointing me in the right direction.
lumpynose
Nov 7th, 2007, 01:35 PM
Peter, do I understand this correctly? Would I put in my jsp file the usual spring colon form tags to make my text input boxes and then also have the following javascript code which would replace them when the page is loaded:
new dijit.form.TextBox({"class":"large"}, dojo.byId("someSpringFormInput")); where my spring colon form tag had the id of someSpringFormInput?
And if so, does dojo put back whatever attributes Spring may have put on the form input tag? I.e., nothing gets lost by the replacement.
Thanks
pmularien
Nov 7th, 2007, 01:46 PM
Well, keep in mind that I've not tried this myself, but yes, what you posted looks like it should work.
does dojo put back whatever attributes Spring may have put on the form input tag? I.e., nothing gets lost by the replacement.
I believe this is accurate.
lumpynose
Nov 7th, 2007, 03:18 PM
Ok, thanks. I'll have to give it a try.
Marten Deinum
Nov 7th, 2007, 03:22 PM
Wouldn't it be easier to use the 'old' spring bind tags instead of the form tags?
lumpynose
Nov 7th, 2007, 03:30 PM
I dunno. That was my first thought as well but the amount of xml you need to write with the old spring colon bind tags is considerable.
The other thing that's discouraging, to me at least, is that I can't find any online example and howto documentation for the old spring colon bind tags. Luckily I have the Spring MVC and Webflow book which explains how to use them.
Marten Deinum
Nov 7th, 2007, 03:42 PM
How to use the bind tags is still explained in the reference guide... (Edit: just checked it indeed has been removed from the reference guide)
You either write some additional tags or create javascript to modify your created tags...
DBoy001
Dec 30th, 2008, 02:15 PM
I just ran into the same problem and solved it this way :
<form:input path="name"/>
<script type="text/javascript">
dojo.addOnLoad( function() {
var name = dojo.byId("name");
name.setAttribute("dojoType", "dijit.form.TextBox");
dojo.parser.parse(name.parent);
});
</script>
The advantage of using the parser to create the widget is that it'll read all the DOM attributes so you won't have to manually assign the "name", "id", "value" attributes and so on... they'll be parsed from the DOM element...
Hope this helps someone, someday (cause I searched a long time for it).
fastmap
Dec 20th, 2010, 11:43 AM
Great post DBoy001. This did help me.
Powered by vBulletin® Version 4.1.12 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.