Intro - Part 1 - Part 2 - Part 3 - Part 4 Part 2: Kick-start the development cycleIntroIn the first part you did the hard (and maybe confusing) stuff: setting it all up! Now comes the easy bit which is adding some functionality. Typically for a development cycle, you add a feature, then test it, and add more functionality, test again, ... Change the .mlg fileTo add a new task the following steps need to be executed: 1) get the next sequence value for the id 2) make up a a rank (sort order): add 1 to the maximum existing rank 3) insert the above values, together with the new task description into the db Get the next sequence methodAdd the method getNextSequenceValue() to the service definition in your Todo.mlg file as follows:
The method to get the highest rankAlso add this method, to the same TodoService definition in Todo.mlg :
Define the method to insert into the tableAdd this method to Todo.mlg too.
The java methodThe above 3 methods need to be called in 1 servercall, and that happens in this Java method:
So also add the above method to your Todo.mlg file. It should now look like this. You probably noticed it already: to differentiate a method with a SQL-body from a method with a Java body you have to use the .. notation. Why double curly braces and why not single ? Just a convention, and to remind you that it's not PURE java you are writing here, there are things lacking like the public/private/protected modifiers, exeception handler,... etc. One final thing to do now is to have amalegeni regenerate the bean(s) and service classes.
After doing that, hit the F5 button in Eclipse to refresh the src directory. Add code to Todo.java codeChange onModuleLoad()As you have probably noticed, we had an 'Add' button, but no action attached to it. Let's correct that by adding a click-handler. Add the following line to the onModuleLoad() method:
Add new method addRandomNewTask()This method gets a random task from method getRandomTask, defined in the next section, and contains callback code, that I copied from the cut-and-paste.txt file (and modified a bit).
Add method getRandomTaskThis method just returns a random task.
Note: when you let Eclipse sort out your import statements ensure that the Random is this one: com.google.gwt.user.client.Random All should be ready now.... so fire up your Todo app, and hit that 'Add' button. For your convenienceHere are the source files that have above changes applied: Next stepProceed now to part 3. |