Você está na página 1de 5

Contents

1 Introduction ................................
................................................................................................
.........................................................................................2
2 Creating A Simple Application................................
................................................................................................
................................................................2
2.1 Creating the Beans ................................
................................................................................................
.......................................................................2
2.2 Adding annotations ................................
................................................................................................
......................................................................2
2.3 Generating CRUD pages ................................
................................................................................................
...............................................................3
3 Appendix A: Source Code for the Employee Bean ................................................................
...................................................................4

Open-tides Documentation Page 1 of 5


1 INTRODUCTION
The goal of this tutorial
utorial is to demonstrate to software developers and aspiring programmers how quick and easy
it is to create a simple java application using the Open-Tides
Tides framework.
This tutorial uses the Apache Ant build tool within the Eclipse IDE.
IDE If another build tool or IDE is to be
used, adjust accordingly.

2 CREATING A SIMPLE APPLICATION


This section describes the procedure
procedures for creating a simple application.. The Open-tides
Open framework makes
creating an application a three
three-step process:: create the java bean, add the annotations, and generate the CRUD
pages.
As an example, let us create a simple application that handles employee management
management—creating, reading,
updating and deleting employees.

2.1 Creating the Beans


Create the java bean packages, if needed. Create the beans.
In the employee management example, we create the employee bean.
1) Create the java bean that extends the BaseSortableEntity
Entity superclass and implements the
BaseCriteria interface. Your bean should generally look like this:

package com.otdefault.bean;

import org.opentides.bean.BaseCriteria;
import org.opentides.bean.Base
org.opentides.bean.BaseSortableEntity;

public class Employee extends Base


BaseSortableEntity
Entity implements BaseCriteria
{

2) Define the fields of your bean and create getters and setters for each one.

private String employeeId;


private String fname;
private String lname;
private String gender;
private String civilStatus;

// getters and set


setters of the fields go here

2.2 Adding annotations


The Open-tides
tides framework provides a set of annotations to easily and quickly apply the appropriate behaviors to
particular bean field types. Refer to the javadoc API documentation for more details.
In our example, we distinguish the fields as follows:
1) employeeId, fname and lname are all of TextField types,
2) gender is a RadioButton type, and
3) civilStatus is a DropDown type.
To properly annotate the bean,
ean, we do the following:
1) Add the standard JPA annotations needed by your bean.
2) Add the Open-Tides
Tides annotations below to set the bean to automatically create the DAO, service,
controller and JSP page of the bean.
• @Dao
This creates the dao and dao implementa
implementation
tion classes for the bean. In the ex
ample above, the EmployeeDao.class and EmployeeJpaDaoImpl.class are created.

Open-tides Documentation Page 2 of 5


• @Service
This creates the service and service implementation classes for the bean. In the example above, the
Service.class and EmployeeServiceImpl.class
EmployeeService Impl.class are created.
• @Controller
This creates the controller classes for the bean. In the example above, the
Controller.class is created.
EmployeeController
• @Page
This creates the form, list and refresh pages for the bean. In the example above, the employee-
employee-list.jsp and employee-refresh.jsp
form.jsp, employee efresh.jsp pages are created.

:
:
import javax.persistence.ManyToOne;
import org.hightides.annotations.DropDown;
import org.hightides.annotations.RadioButton;
import org.hightides.annotations.TextField;
:
:
@Dao
@Page
@Service
@Controller
@SuppressWarnings
@SuppressWarnings("serial")
public class Employee extends BaseSortableEntity
Entity implements BaseCriteria{
BaseCriteria

@TextField
private String employeeId;

@TextField (re
(requiredField=true, label="First
"First Name")
Name"
private
te String fname;

@TextField (r
(requiredField=true, label="Last Name")
Name"
private String lname;

@ManyToOne
@RadioButton (options={"male", "female"})
private String gender;

@ManyToOne
@DropDown (category=
(category="SYSTEMCODES_STATUS")
private String civilStatus;
:
:

The whole employe


ee.class is attached as Appendix A.

2.3 Generating CRUD pages


Once the bean is created and the proper annotations are in place, the final step is to generate the CRUD pages.
To do so, you only need to do two major tasks:
1) Include the servlet
servlet-api.jar library in the Java Build Path of the project, if it has not yet been
included. Ot-default
default requires HttpServletRequest.class,
HttpServletRequest.class which is located within that library.
Alternatively, the Apache Tomcat Server Runtime library contains that necessary file, and that
whole .jar file can be included instead.
2) Open build.xml using the A P A C H E A N T build tool and run generate.
generate
or, alternatively,
Open the A P A C H E A N T V I E W , click on A D D B U I L D F I L E S and choose build.xml under O T - D E F A U L T .
After the code generation is finished, your simple application is ready to run.

Open-tides Documentation Page 3 of 5


3 APPENDIX A: SOURCE CODE FOR THE EMPLOYEE BEAN
package com.otdefault.bean;

import org.opentides.bean.BaseCriteria;
import org.opentides.bean.Base
org.opentides.bean.BaseSortableEntity;
import javax.persistence.ManyToOne;
import org.hightides.annotations.DropDown;
import org.hightides.annotations.RadioButton;
import org.hightides.annotations.TextField;

@Dao
@Page
@Service
@Controller
"serial")
@SuppressWarnings("serial
public class Employee extends BaseSortableEntity
Entity implements BaseCriteria{
BaseCriteria

@TextField
private String employeeId
employeeId;

@TextField (requiredField=
quiredField=true, label="First
"First Name")
Name"
private String fname
fname;

@TextField (requiredField=
equiredField=true, label="Last Name")
Name"
private String lname
lname;

@ManyToOne
@RadioButton (options={
(options={"male", "female"})
private String gender
gender;

@ManyToOne
@DropDown (category=
(category="SYSTEMCODES_STATUS")
private String civilStatus
civilStatus;

/**
* @return the employeeId
*/
public String getEmployeeId() {
return employeeId
employeeId;
}
/**
* @param employeeId the employeeId to set
*/
public void setEmployeeId(String employeeId) {
employeeId = employeeId;
this.employeeId
}
/**
* @return the fname
*/
public String getFname() {
return fname;
;
}
/**
* @param fname the fname to set
*/
public void setFname(String fname) {
this.fname = fname;
}
/**
* @return the lname
*/
public String getLname() {
return lname;
}

Open-tides Documentation Page 4 of 5


/**
* @param lname the lname to set
*/
public void setLname(String lname) {
lname = lname;
this.lname
}
/**
* @return the gender
*/
public String getGender() {
return gender;
}
/**
* @param gender the gender to set
*/
public void setGender(String gender) {
gender = gender;
this.gender
}
/**
* @return the civilStatus
*/
public String getCivilStatus() {
return civilStatus;
}
/**
* @param civilStatus the civilStatus to set
*/
public void setCivilStatus(String civilStatus) {
civilStatus = civilStatus;
this.civilStatus
}
}

Open-tides Documentation Page 5 of 5

Você também pode gostar