Trace:
Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
jvx:firstapp [2018/01/25 08:32] admin |
jvx:firstapp [2018/01/29 13:43] admin |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ~~Title: First application ~~ | ||
+ | |||
In the following paragraphs, we will show you how to create your first JVx application with minimal effort and code. | In the following paragraphs, we will show you how to create your first JVx application with minimal effort and code. | ||
Line 15: | Line 17: | ||
* [[#application|Application]] | * [[#application|Application]] | ||
* [[#workscreen|Work screen]] | * [[#workscreen|Work screen]] | ||
- | * Business object | + | * [[#workscreen|Business object]] |
- | * Database connection | + | * [[#database|Database connection]] |
{{anchor:application:}} | {{anchor:application:}} | ||
Line 144: | Line 146: | ||
|createMenuItem|Provided by the super class to create menu entries. The first parameter contains the name of the method which is to be called when the menu entry is selected. The second parameter contains the command (ActionCommand) which plays no role in our case. The text of the menu entry is to be defined in the third parameter, and lastly the image for the entry is passed over.| | |createMenuItem|Provided by the super class to create menu entries. The first parameter contains the name of the method which is to be called when the menu entry is selected. The second parameter contains the command (ActionCommand) which plays no role in our case. The text of the menu entry is to be defined in the third parameter, and lastly the image for the entry is passed over.| | ||
|createToolBarButton|Similar to ''createMenuItem'', except that this method creates a button which adapts to the layout of the toolbar.| | |createToolBarButton|Similar to ''createMenuItem'', except that this method creates a button which adapts to the layout of the toolbar.| | ||
- | |UIImage.getImage|Provides a predefined image from the JVx image library. For ease of use, we use a predefined image.| | + | |UIImage.getImage|Provides a predefined image from the JVx image library. \\ For ease of use, we use a predefined image.| |
|doOpenDBEdit|This method is called when the menu or the toolbar button are pressed and calls the corresponding work screen.| | |doOpenDBEdit|This method is called when the menu or the toolbar button are pressed and calls the corresponding work screen.| | ||
|configureFrame|This method is provided by the super class and ensures that all frames look the same. This includes the menu icon.| | |configureFrame|This method is provided by the super class and ensures that all frames look the same. This includes the menu icon.| | ||
Line 263: | Line 265: | ||
|InitializeUI|Layouting of the work screen.| | |InitializeUI|Layouting of the work screen.| | ||
|createSubConnection|We create a separate connection to the server. This has the advantage that a separate business object is used on the server. This object contains all objects needed by the work screen. Once the work screen is closed, the used memory is released. Moreover, each connection can have special parameters and time outs. \\ The requested business object is defined with the following class: ''apps.firstapp.frames.DBEdit''. \\ \\ The class will be created later on.| | |createSubConnection|We create a separate connection to the server. This has the advantage that a separate business object is used on the server. This object contains all objects needed by the work screen. Once the work screen is closed, the used memory is released. Moreover, each connection can have special parameters and time outs. \\ The requested business object is defined with the following class: ''apps.firstapp.frames.DBEdit''. \\ \\ The class will be created later on.| | ||
+ | |||
+ | ^ Member ^ Description ^ | ||
+ | |connection|The connection to the server, specially for the work screen. A special communication protocol is used in the background. In our case, it mirrors the ''DirectServerConnection'' class.| | ||
+ | |dataSource|This is the data source and looks after the transfer of data between the client and the server. The connection is used for the transfer.| | ||
+ | |rdbContacts|The model and the controller for data display. \\ The name contacts defines under which name the server-side business object can be found.| | ||
+ | |||
+ | {{anchor:business:}} | ||
+ | == Create a business object == | ||
+ | |||
+ | Once we have created the client, we need the corresponding business object on the server, so as to define the source of the data more precisely. To do so, we use the following code: | ||
+ | |||
+ | <file java DBEdit.java> | ||
+ | package apps.firstapp.frames; | ||
+ | |||
+ | import javax.rad.persist.IStorage; | ||
+ | |||
+ | import com.sibvisions.rad.persist.jdbc.DBStorage; | ||
+ | |||
+ | import apps.firstapp.Session; | ||
+ | |||
+ | /** | ||
+ | * The LCO for the DBEdit WorkScreen. | ||
+ | * <p/> | ||
+ | * @author René Jahn | ||
+ | */ | ||
+ | public class DBEdit extends Session | ||
+ | { | ||
+ | //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
+ | // User-defined methods | ||
+ | //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
+ | |||
+ | /** | ||
+ | * Returns the contacts storage. | ||
+ | * | ||
+ | * @return the contacts storage | ||
+ | * @throws Exception if the initialization throws an error | ||
+ | */ | ||
+ | public IStorage getContacts() throws Exception | ||
+ | { | ||
+ | DBStorage dbsContacts = (DBStorage)get("contacts"); | ||
+ | | ||
+ | if (dbsContacts == null) | ||
+ | { | ||
+ | dbsContacts = new DBStorage(); | ||
+ | dbsContacts.setDBAccess(getDBAccess()); | ||
+ | dbsContacts.setFromClause("CONTACTS"); | ||
+ | dbsContacts.setWritebackTable("CONTACTS"); | ||
+ | dbsContacts.open(); | ||
+ | |||
+ | put("contacts", dbsContacts); | ||
+ | } | ||
+ | | ||
+ | return dbsContacts; | ||
+ | } | ||
+ | | ||
+ | } // DBEdit | ||
+ | </file> | ||
+ | |||
+ | ^ Description ^ | ||
+ | |The class mirrors the business object for the ''DBEditFrame'' work screen. The objects can only be accessed via the SubConnection of the work screen. \\ Through the class derivation of ''apps.firstapp.Session'', it is very easy to access all objects of the Session and the ''Application''.| | ||
+ | |||
+ | ^ Method ^ Description ^ | ||
+ | |getContacts|Enables the access to the database tablee ''CONTACTS''. The method name must match the object name of the RemoteDataBook: ''contacts => getContacts''. \\ \\ Exception handling is taken over by the server.| | ||
+ | |||
+ | {{anchor:database:}} | ||
+ | == Create a database connection == | ||
+ | |||
+ | In the business object, we referred to the data source with the method ''getDBAccess()''. In our case we use a HyperSQL database. We define the database connection in the following class: | ||
+ | |||
+ | <file java Session.java> | ||
+ | package apps.firstapp; | ||
+ | |||
+ | import com.sibvisions.rad.persist.jdbc.DBAccess; | ||
+ | import com.sibvisions.rad.persist.jdbc.IDBAccess | ||
+ | |||
+ | /** | ||
+ | * The LCO for the session. | ||
+ | * <p/> | ||
+ | * @author René Jahn | ||
+ | */ | ||
+ | public class Session extends Application | ||
+ | { | ||
+ | //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
+ | // User-defined methods | ||
+ | //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
+ | | ||
+ | /** | ||
+ | * Returns access to the database. | ||
+ | * | ||
+ | * @return the database access | ||
+ | * @throws Exception if a connection error occurs | ||
+ | */ | ||
+ | public IDBAccess getDBAccess() throws Exception | ||
+ | { | ||
+ | DBAccess dba = (DBAccess)get("dBAccess"); | ||
+ | | ||
+ | if (dba == null) | ||
+ | { | ||
+ | dba = new HSQLDBAccess(); | ||
+ | |||
+ | dba.setUrl("jdbc:hsqldb:hsql://localhost/firstappdb"); | ||
+ | dba.setUsername("sa"); | ||
+ | dba.setPassword(""); | ||
+ | dba.open(); | ||
+ | |||
+ | put("dBAccess", dba); | ||
+ | } | ||
+ | | ||
+ | return dba; | ||
+ | } | ||
+ | |||
+ | } // Session | ||
+ | </file> | ||
+ | |||
+ | ^ Method ^ Description ^ | ||
+ | |getDBAccess|Opens a new connection to a HSQL database, if this has not yet occurred. \\ \\ Exception handling is taken on by the server.| | ||
+ | \\ | ||
+ | The application is now fully implemented and ready to run. To be able to work with the application we need the database including the ''CONTACTS'' table which we want to access. It has already been created in the Eclipse project and can be started with ''../JVxFirstApp/db/startHSqlDB.bat''. | ||
+ | |||
+ | == The first JVx application == | ||
+ | |||
+ | Once the database has been started, the application can be started via the Run menu in Eclipse. The finished application should now look as follows: | ||
+ | |||
+ | {{:jvx:app_finished.png?nolink|}} | ||
+ | |||
+ | You can find more details about the components of a JVx application as well as step by step instructions for Eclipse under [[jvx:firstapp_step-by-step|Step by step introductions to the JVx application]]. |