-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Spring Roo 1.1 Cookbook
In some scenarios, you may want to set the focus of your commands to a particular Java type. For instance, you may want the Roo shell to execute field commands on a particular Java type, so that you don't need to specify the class argument in your field commands.
Start the Roo shell from the C:\roo-cookbook\ch01-recipe directory, which contains the flight-app Roo project.
Spring Roo provides a focus command, which lets you change the target of your commands to a different Java type. The following sequence of steps shows how we can use the focus command to switch from one type to another:
Execute the following focus command to specify that you want to work with the flight-app project. This will change the Roo prompt to reflect the top-level package name of Roo project:
roo> focus --class ~
Create FlightDesc class using the class command. Use ~ to denote that you are specifying the package name for the class with respect to the top-level package of the project. This will change the Roo prompt to refer to the FlightDesc type, shown as follows:
sample.roo.Flightapp roo> class --class ~.domain.FlightDesc --rooAnnotations Created SRC_MAIN_JAVA\sample\roo\flightapp\domain\FlightDesc.java
Create a Flight class using the class command. This will change the Roo prompt from FlightDesc type to refer to the newly created Flight type, as shown here:
~.domain.FlightDesc roo> class --class ~.domain.Flight --rooAnnotations Created SRC_MAIN_JAVA\sample\roo\flightapp\domain\Flight.java
Use a focus command to switch to the FlightDesc type. This will change the Roo prompt from referring to Flight type to FlightDesc type, as shown here:
~.domain.Flight roo> focus --class ~.domain.FlightDesc
Add from_city and to_city attributes to the FlightDesc class as shown here. As the currently referred type by Roo prompt is FlightDesc, you don't need to specify the class argument:
~.domain.FlightDesc roo> field string from_city ~.domain.FlightDesc roo> field string to_city
Without changing focus to the Flight class, add a flight_Id attribute to the Flight class by using the field command along with the class argument, as shown here. The class argument specifies that the target of the command is the Flight class and not the currently referred FlightDesc class:
~.domain.FlightDesc roo> field number --fieldName flight_Id --type java.lang.Integer --class ~.domain.Flight
The class argument of the focus command lets you specify the fully-qualified name of the Java type with which you want to work. The ~ symbol is used to indicate the top-level package of the Roo project that you specified during creation of the Roo project.
The use of the ~ symbol simplifies providing the value of any argument that expects a fully-qualified name of a Java type in your Roo project.
The use of the focus command is mainly to simplify writing commands targeting a particular Java type. If you don't want to use the focus command in a situation, then you can always use the class argument of the command to specify the target Java type of the command.
The Creating a Java class recipe shows how to create a Java class using Spring Roo
The Adding attributes to a Java class recipe shows how to add attributes to a Java class using Spring Roo
Change the font size
Change margin width
Change background colour