- This topic has 7 replies, 2 voices, and was last updated 14 years, 4 months ago by
Greg Soulsby.
-
AuthorPosts
-
Greg SoulsbyMemberhaving generated my first app from a database now would like to enhance the user interface.
I see the following in main.jsp
<script type=”text/javascript” src=”${pageContext.request.contextPath}/resources/dojo/dojo.js” djconfig=”parseOnLoad: true” ></script>
<script type=”text/javascript” src=”${pageContext.request.contextPath}/resources/spring/Spring.js”></script>
<script type=”text/javascript” src=”${pageContext.request.contextPath}/resources/spring/Spring-Dojo.js”></script>
<script type=”text/javascript”>dojo.require(“dojo.parser”);</script>But where is dojo.js? Cant find it anywhere, although seems visible in Firebug.
When I try
dojo.require(“digit.form.Form”);
dojo.require(“digit.form.TextBox”);get a “could not load error”.
what should I use for
dojo.require(“digit.form.Form”);
?Thanks
davemeurerMemberHello,
The dojo stuff is packaged in a jar provided by the Spring framework. In 8.6.1 using Spring 3.0, find the Spring MVC 3 Libraries classpath container in your project (Project Explorer). Expand it and then expand spring-js-2.0.7.RELEASE.jar. You’ll find the dojo files under META-INF. Spring Javascript uses dojo in the background.
Regarding requiring a Form – are you trying to validate certain form elements? If so, when you scaffold CRUD, the generation includes Spring Javascript decorations (dojo) that do some validation.
If not, let me know what you are trying to do.
Kind regards,
Dave
Greg SoulsbyMemberDave,
Thanks for the prompt reply, it realy helps.
The purpose of the form is to ask the user for some simple input. So it is something new / clean, not related to a CRUD or even the tables.
The books I have on dojo are saying the format is to do a
dojo.require(“digit.form.Form”);
dojo.require(“digit.form.TextBox”);then give the markup of your form using the digits you have made available with the requires.
They say that dojo.require works relativly from the location of digit.js
But that is not working for me.
Greg
davemeurerMemberThanks for the explanation, Greg.
I’ll do some research today and see why that isn’t working.
In the meantime, to do this with Spring Javascript, you would add decorations to the text box and button:
Here are some examples:
After Text Box:<script type="text/javascript">Spring.addDecoration(new Spring.ElementDecoration({elementId : "office_officecode",widgetType : "dijit.form.ValidationTextBox",widgetAttrs : {promptMessage: "Office Code is required", required : true}})); </script>
After Button:
<script type="text/javascript">Spring.addDecoration(new Spring.ValidateAllDecoration({elementId:'save', event:'onclick'}));</script>
I’ll post back with what I find on the dojo side.
Kind regards,
Dave
davemeurerMemberHi Greg,
I was able to get my test ME4S app working with straight dojo, and the dojo.require commands you specified.
Here’s the body code of my test page. It’s in a scaffolded application, so sitemesh wraps the main.jsp around it with the dojo includes:
<script type="text/javascript"> dojo.require("dijit.form.ValidationTextBox"); dojo.require("dojo.parser"); dojo.require("dijit.form.Button"); dojo.require("dijit.form.Form"); </script> <form action="${pageContext.request.contextPath}/showsimpletext" method="post"> <input name="simpletext" id="simpletext" type="text" size="15" value="${simpletext}" dojoType="dijit.form.ValidationTextBox" required="true" invalidMessage="Field is required" /> <button dojoType="dijit.form.Button" type="submit" name="submitButton" value="Submit"> Submit </button> </form>
Let me know if this helps. Can you tell if the page you are creating contains the sitemesh wrapped main.jsp around it?
Kind regards,
Dave
Greg SoulsbyMemberGreat, thanks Dave, I now have a better mental model of this works. But it is still a flawed model.
I have taken your code and converted it to so my button now injects into the page the form and sets up the dojo programatically. Otherwise I would require a round trip to the server, right? Bypasses Spring however.
When they click the button on this injected form it executes dojo.xrhPost to send the form to a web controller with a @RequestMapping for the Model And View processing. It injects the returned data into the page with a document.getElementById(“message”).innerHTML.
But I see you could predict the problem: the data returned is a whole page, wrapped in main.jsp, not just the simple <p>Result here</p> I am looking for.
Can you advise as to options?
A) somehow get a results from a model and view controler without returning the result wrapped in main.jps. If this is a good option, how to?
B) use a web service to execute the code?
C) other?Regards
davemeurerMemberHi Greg,
A) somehow get a results from a model and view controler without returning the result wrapped in main.jps. If this is a good option, how to?
To return a result that won’t be decorated with site mesh, you can add exclusions to the decorators.xml file. You can use a quick scaffolded app as an example. Here’s the code it emits:
<excludes> <pattern>/j_spring_security_logout</pattern> <pattern>/pages/logout-redirect.jsp</pattern> </excludes>
The patterns can be general, like
<pattern>/validation*</pattern>
I’m thinking this would be better/easier to implement then trying to create a web service to execute the code, but you can always create a web service very quickly with the JAX-WS annotator in MyEclipse for Spring.
HTH,
Dave
Greg SoulsbyMemberDave, very cool, many thanks. This is taking me months to get up to speed on, but I see it is very worthwhlie.
-
AuthorPosts