Cimande:Create Your First CRUD

From BlueOxygen Wiki

Jump to: navigation, search

Contents

[edit] Overview

This is the tutorial to create your first CRUD module for Cimande.

[edit] Preparation

  1. Cimande SDK Bundle Edition
  2. MySQL
  3. Eclipse WTP
  4. Java 6.0 SDK

[edit] Importing SDK to Eclipse

  1. Extract the SDK
  2. Import to Eclipse and you will get a WTP Dynamic Web Project


[edit] Create JPA Entity

  1. Create 'org.blueoxygen.workshop.Item', don't forget to extend DefaultPersistance
  2. Create variable code, name, description and price, also the JPA annonation.
@Entity
@Table(name="workshop_item")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
public class Item extends DefaultPersistence {
 
	private String code;
	private String name;
	private String description;
	private int price;
 
}
  1. Register the class inside hibernate.cfg.xml (used for generate database schema)
<mapping class="org.blueoxygen.workshop.entity.Item"/>
  1. Add the class in applicationContext-hibernate.xml (use to run the module)
<value>org.blueoxygen.workshop.entity.Item</value>

[edit] Create ItemForm

  1. Create a class name 'org.blueoxygen.workshop.item.ItemForm'
  2. extends ActionSupport, and implements PersistenceAware, SessionCredentialsAware
public class ItemForm extends ActionSupport 
		implements PersistenceAware, SessionCredentialsAware{
 
	protected PersistenceManager manager;
	protected SessionCredentials sessionCredentials;
	private Item item = new Item();
	private List<Item> items = new ArrayList<Item>();
 
}
  1. add protected PersistenceManager manager;
  2. add protected SessionCredentials sessionCredentials;
  3. create get-set for manager and sessionCredentials
  4. add this.manager = persistenceManager inside setPersistanceManager
  5. add this. sessionCredentials = sessionCredentials; inside setSessionCredentials
public void setPersistenceManager(PersistenceManager persistenceManager) {
 
		this.manager = persistenceManager;
	}
 
	public void setSessionCredentials(SessionCredentials sessionCredentials) {
 
		this. sessionCredentials = sessionCredentials;
	}

[edit] Create Item Action

  1. Create a class name 'org.blueoxygen.workshop.item.SaveItem'
  2. extend ItemForm
  3. map all the http post data
  4. save the data using manager.save(getItem());
  5. add return SUCCESS; if the save success
  6. look to the database, is the new data inside?

[edit] Create Velocity Template

  1. Create folder /viwe/module/workshop
  2. Create form.vm and filter.vm, form.vm is for create new content, and filter is for searching

[edit] Mapping the Template - Action

  1. Create 'cimande-core.xml', save in folder java (/src/java)
  2. Create <package name="workshop" extends="default" namespace="/module/workshop">
  3. Add <action name="create" class="org.blueoxygen.workshop.item.ItemForm"> .. </action>
  4. Add between action, <result name="success" type="velocity">/view/module/workshop/form.vm</result>
Personal tools