Cimande:Create Your First CRUD
From BlueOxygen Wiki
Contents |
[edit] Overview
This is the tutorial to create your first CRUD module for Cimande.
[edit] Preparation
- Cimande SDK Bundle Edition
- MySQL
- Eclipse WTP
- Java 6.0 SDK
[edit] Importing SDK to Eclipse
- Extract the SDK
- Import to Eclipse and you will get a WTP Dynamic Web Project
[edit] Create JPA Entity
- Create 'org.blueoxygen.workshop.Item', don't forget to extend DefaultPersistance
- 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; }
- Register the class inside hibernate.cfg.xml (used for generate database schema)
<mapping class="org.blueoxygen.workshop.entity.Item"/>- Add the class in applicationContext-hibernate.xml (use to run the module)
<value>org.blueoxygen.workshop.entity.Item</value>
[edit] Create ItemForm
- Create a class name 'org.blueoxygen.workshop.item.ItemForm'
- 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>(); }
- add protected PersistenceManager manager;
- add protected SessionCredentials sessionCredentials;
- create get-set for manager and sessionCredentials
- add this.manager = persistenceManager inside setPersistanceManager
- 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
- Create a class name 'org.blueoxygen.workshop.item.SaveItem'
- extend ItemForm
- map all the http post data
- save the data using manager.save(getItem());
- add return SUCCESS; if the save success
- look to the database, is the new data inside?
[edit] Create Velocity Template
- Create folder /viwe/module/workshop
- Create form.vm and filter.vm, form.vm is for create new content, and filter is for searching
[edit] Mapping the Template - Action
- Create 'cimande-core.xml', save in folder java (/src/java)
- Create <package name="workshop" extends="default" namespace="/module/workshop">
- Add <action name="create" class="org.blueoxygen.workshop.item.ItemForm"> .. </action>
- Add between action, <result name="success" type="velocity">/view/module/workshop/form.vm</result>
