19 abril 2009

Taylor

Classpath

Now lets setup the classpath before browsing the code.

Open the Eclipse preferences and add a M2_REPO classpath variable that points to your Maven repository [${user.home}/.m2/repository]

  • Or use maven: mvn -Declipse.workspace= eclipse:add-maven-repo


Open a command window, navigate to your master project directory, and run 'mvn install' and then 'mvn eclipse:eclipse' to generate the .project and .classpath files for all of the projects.

NOTE: If this is the first time you are running this it will take a while to download all the necessary jars. You may have to repeat it several times. It will also fail when it reaches the web project, but that is OK, we will come back to that later.

  • If you want to use WTP with the web project then use mvn eclipse:eclipse -Dwtpversion=1.5 in the web and pdf project directories
  • JSF Support


Now, go back to Eclipse and switch to the Java perspective. Then select all the projects and press F5 to refresh.

Now browse the code to see what was generated. The high-lights are discussed below.



Enumerations

Also give creating an Enumeration a try. And add some Literals. Then create a status property on the entity bean with a type of Status.

Now lets run some helper utilities to make some bulk changes to the model. Right-click on the net.taylor.tutorial.entity package and select Utilities > JPA and then run:

  • Add Temporal Stereotypes and
  • Add Enumeration Stereotypes

JSF Support

This will probably be fixed in a future version of the eclipse plugin.

Add the following to .settings/org.eclipse.wst.common.project.facet.core.xml

  

Types to Java and JSF Mapping

NOTE: Change the type of the description property to types.Text so that a Text Area will be generated in the facelet.

String String JSF Input Text
Text String Text Area - TinyMCE Editor
Date Date Seam Date Picker
Boolean Boolean JSF Check Box
Integer Long RichFaces Spinner
Decimal Double JSF Decimal
Currency BigDecimal JSF Currency
Percentage Double JSF Percentage
Byte[] byte[] Seam File Upload
Image String JSF Image
Link String JSF Link
Enumeration your Enum JSF SelectOne
Many to One Association your Class JSF SelectOne
Double Double deprecated - use Decimal, Currency, or Percentage
Long Long deprecated - use Integer



JPA Utilities

  • Cleanup Associations
    • For each association, default the mappedBy and cascade properties
  • Add Embedded Stereotypes
  • Add Temporal Stereotypes
    • For each property of type Date, Time, or Timestamp add the stereotype and set the value accordingly.
  • Add Enumeration Stereotypes
    • For each property with an Enumeration type add the stereotype and set the value to STRING
  • Add Index Stereotype to ManyToOne Properties
  • Add Join Table Stereotypes
  • Switch Inheritance Types
  • Switch Id Generators
  • Add Table Stereotypes
  • Add Column Stereotypes
  • Add Attribute Override Stereotypes


Unit Tests

From Taylor

Three types of JUnit tests are generated: Service, Seam, and JasperReports.


Seam

A Seam junit test is generated in the Ejb3 project for each entity. These tests verify that the Finder and Editor SFSBs and the Facelets expressions (EL) are working properly.

  • You might need to tweak the default values for properties.
  • Association tests are also not generated.

Possible Compilation Errors

After generating the code and setting up the classpath you may notice that some of the code might have compile errors. This could happen for several reasons:

  1. Something might be missing from the model. Fix the model and regenerate.
  2. Various TreeNode and EditorBean methods assume there is a property called 'name' that is used for display. Change these to the property you would like to display.
    1. For example, in the tutorial the Ticket entity has a 'title' property instead of a 'name' property.
  3. You added an Interceptor from a third party that needs to be added to the Maven pom.xml dependencies section. Or you added an Interceptor that you need to implement.
  4. The session bean operations need to be implemented because they did not match one of the default implementations: save, get, delete, query.
  5. You defined a operation named query that does not match the default signature. See below.

This is the default signature for operations named query. You will want to define more specialized query operations for the service, but using this signature is a good way to get a prototype up and running quickly. So, either change the model or implement the query as you see fit. Another good option is to use the NamedQuery stereotype to define your queries. It is a good practice to name these the same as the operation that will use them.

 
public List query(SomeEntity example, Long first, Long max, String orderBy) {
}





Facelets Customization


The generated facelets are meant to be customized. Generating an
Entity bean is very straight forward because there are well defined
rules and only so many variations. On the other hand, the user
interface is the place where different applications can differentiate
themselves.

To this end, the generated facelets are meant to give you a jump start. The following sections outline possible modifications.


Editor


For the most part the UI can be customized by making changes to the EditorBeans.


  • Implement isEditable()
  • Change the various isRendered methods
  • Implement isRendered(String name) and isDisabled(String name) to control individual fields
  • Modify Many2One and Many2Many association methods to change
    what fields are displayed and add filters. See TODO tags placed in the
    code.
  • Change createInstance() to initialize properties.
  • Add additional actions like submit() and schedule(). Examples have been generated.

Finder


  • getSearchFields()
  • Add Chart methods

Menus


The default-object.xml file defines how pages will be displayed in
JBoss Portal. You will probably want to add and remove pages from this
file. Alternatively, you can do this online in JBoss Portal.

You can also create additional *-object.xml files.


UI Facelets


This is were you might make the most changes, such as rearranging fields, changing input types, and adding buttons.

The Facelets use the standard Portlet CSS Styles, so you can accomplish a lot by changing the Portal Theme.

Facelets templates and tags are leveraged also. When the
Web project is built for the first time the Taylor-Tags library will be
expanded into your project. You can then change the following files to
make global changes across your application:


  • webapp/web-inf/jsf/templates
  • webapp/web-inf/jsf/tags
  • webapp/web-inf/pdf/templates
  • webapp/web-inf/pdf/tags

Report Facelets


The generated Seam PDF files are just Facelets so the same things apply as for the UI facelets.



Seam Tests

Taylor Commons contains a port of the Seam TestNG libraries to JUnit. Seam junit tests are generated for each Entity in the model to test the generated CRUD Editor and FInder classes. You will need to tweak the default values for some fields like dates and enumerations.


Version Control

Check in the model, diagrams, and generated code and descriptors into your version control system. I typically generate the code, then tweak it enough to compile, and then check it in. Then I do any major modifications and check that in before iterating again through the model and regenerating.


Package and Deploy


Setup

  • Copy the necessary configuration files generated in your Ear project's jboss\deploy directory to the server\all\deploy directory.
    • For example, to setup a datasource copy tutorial-hsqldb-ds.xml
  • Setup the JBOSS_HOME system property to point to your JBoss installation
    • SET JBOSS_HOME=C:\jboss-4.2.0.GA

Build

  • Change directories to your master project run mvn clean install to clean, compile, test, package, and install all the sub-projects: jpa, ejb, web, pdf, app, doc, etc.

Deploy

  • The App project's pom.xml has the logic to copy the Ear file to your JBoss server.
  • Alternatively, you can still use the jboss-maven-plugin
    • Run mvn clean install jboss:harddeploy to deploy your Ear to JBoss.

Packaging

  • Run mvn site to generate the project website with javadoc, xref, and test reports.
  • Run mvn assembly:assembly to package everything into zip and tar files.


Other Useful Maven Plugins

The templates could be changed to generate some of these:

Reports

Packaging


Customize Code Templates


Templates can be overridden by placing a new version in the directory you specify under Window/Preferences/Taylor. This is useful for overriding the copy right Header template or for fixing template bugs. The templates are found in plug-ins such as net.taylor.mda.ejb3gen.

I typically do the following:

  1. Create a templates folder next to the model folder.
  2. Set the preferences to point to this folder.
  3. Create a Header.jetinc file in this folder.
  4. Check in the custom template so everyone else has access.
  5. As the project progresses we will put additional customized templates here as well. NOTE: The path has to match the path specified in the particular plugin.xml file so that the engine finds them.

Custom Plugins

Additional templates can be added by placing them in your own plugin and adding the following extension point to its plugin.xml.





Additional information can be found under Architecture.

A good JET Template Editor can be found at http://www.eclipse.org/emft/projects/jeteditor/

No hay comentarios: