Documentation

Trace:

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
jvx:code_snippets [2019/05/03 09:23]
admin
jvx:code_snippets [2020/07/01 13:46] (current)
cduncan [Remote Calls to JVx Without UI]
Line 1: Line 1:
 ~~NOTRANS~~ ~~NOTRANS~~
-~~Title: JVx code snippets~~+~~Title: JVx Code Snippets~~
  
 We have a list of useful code snippets for you. Simply use them for your application. All snippets are free to use and licensed under [[https://​www.apache.org/​licenses/​LICENSE-2.0|Apache 2.0]]. We have a list of useful code snippets for you. Simply use them for your application. All snippets are free to use and licensed under [[https://​www.apache.org/​licenses/​LICENSE-2.0|Apache 2.0]].
  
-==== Test DBStorages ​without ​Lifecycle ​objects ​====+==== Test DBStorages ​Without ​Lifecycle ​Objects ​====
  
-Access a DBStorage without JVx Server, Lifecycle Object, Security e.g. for Unit tests+Access a DBStorage without JVx Server, Lifecycle Object, Securitye.g.for unit tests.
  
 <file java ContactsAutoFrame.java>​ <file java ContactsAutoFrame.java>​
Line 39: Line 39:
 </​file>​ </​file>​
  
-==== A custom ​Application ​without menutoolbar... ====+==== A Custom ​Application ​Without MenuToolbaretc. ====
  
-Sometimes we need an application without overhead, e.g for Vaadin UI.+Sometimes we need an application without overhead, e.g., for Vaadin UI.
  
 <file java SimpleApplication.java>​ <file java SimpleApplication.java>​
Line 117: Line 117:
 </​file>​ </​file>​
  
-==== Test your business logic with JUnit ====+==== Test Your Business Logic With JUnit ====
  
-Tests our business logic without ​an application server, but with our Lifecycle objects. We test our server code without specific configuration or modifications for unit tests.+Tests our business logic not with an application server, but with our Lifecycle objects. We test our server code without specific configuration or modifications for unit tests.
  
-Business ​Object:+Business ​object:
  
 <file java UserRegistration.java>​ <file java UserRegistration.java>​
Line 166: Line 166:
 </​file>​ </​file>​
  
-A standard ​Lifecycle Object:+A standard ​life cycle object:
  
 <file java Session.java>​ <file java Session.java>​
Line 232: Line 232:
 </​file>​ </​file>​
  
-Unit Test:+Unit test:
  
 <file java> <file java>
Line 289: Line 289:
 </​file>​ </​file>​
  
-==== A very simple ​AbstractMemStorage ​implementation ​====+==== A Very Simple ​AbstractMemStorage ​Implementation ​====
  
-A server side memory storage with the column names: ID, NAME, PATH. The column PATH is not visible on the client-side, but is important for server-side. If "​error"​ is set as NAME, an Exception ​is thrown!+A server-side memory storage with the column names: ID, NAME, PATH. The column PATH is not visible on the client side, but is important for server side. If "​error"​ is set as NAME, an exception ​is thrown!
  
 <file java SimpleMemStorage.java>​ <file java SimpleMemStorage.java>​
Line 366: Line 366:
 </​file>​ </​file>​
  
-==== Change XML files very fast ====+==== Change XML Files Quickly ​====
  
-Our XML file+Our XML file:
  
 <file xml> <file xml>
Line 392: Line 392:
 </​file>​ </​file>​
  
-==== EventHandler ​without ​Listener ​interface ​====+==== EventHandler ​Without ​Listener ​Interface ​====
  
 Event definition: Event definition:
Line 446: Line 446:
 </​file>​ </​file>​
  
-==== EventHandler ​with Listener ​interface ​====+==== EventHandler ​With Listener ​Interface ​====
  
 The interface: The interface:
Line 535: Line 535:
 </​file>​ </​file>​
  
-Dispatch ​Events:+Dispatch ​events:
  
 <file java> <file java>
Line 651: Line 651:
 </​file>​ </​file>​
  
-==== Remote ​calls to JVx without ​UI ====+==== Remote ​Calls to JVx Without ​UI ====
  
-JVx is a full stack application framework, but all parts are independent. It is no problem to use only the communication classes or the Swing controls without GenUI. This snippet shows how it is possible to use JVx only on server side. You have full session handling and the client is built with your preferred UI or you client has no UI.+JVx is a full-stack application framework, but all parts are independent. It is no problem to use only the communication classes or the Swing controls without GenUI. This snippet shows how it is possible to use JVx only on server side. You have full session handling and the client is built with your preferred UI or if your client has no UI.
  
-Use JVx on server-side as usual. Integrate it into an application server like Tomcat or use it standalone.+Use JVx on server side as usual. Integrate it into an application server like Tomcat or use it standalone.
  
-Use the communcation ​classes to access server objects and actions. A simple object call could be implemented like the following snippet.+Use the communication ​classes to access server objects and actions. A simple object call could be implemented like the following snippet.
  
 Get the source code for a specific class via Server Object: Get the source code for a specific class via Server Object:
Line 693: Line 693:
 Use rdbContacts to insert/​update/​delete records. Use rdbContacts to insert/​update/​delete records.
  
-==== Use JVx Swing controls without ​JVx UI ====+==== Use JVx Swing Controls Without ​JVx UI ====
  
-JVx's Swing controls are independent of JVx UI. It is no problem to use a table that shows some database or in-memory records. It is also possible to use 3-tier or 2-tier architecture.+JVx's Swing controls are independent of JVx UI. It is no problem to use a table that shows some database or in-memory records. It is also possible to use three-tier or two-tier architecture.
  
-=== In-Memory ​data === +=== In-Memory ​Data === 
  
 Use JVxTable and integrate it in your Swing application. Use it like a standard JTable. Use JVxTable and integrate it in your Swing application. Use it like a standard JTable.
Line 750: Line 750:
 You have all JVx features like link cell editors, image choice editors - in your Swing application! You have all JVx features like link cell editors, image choice editors - in your Swing application!
  
-=== 2-tier data (database) ===+=== Two-Tier Data (Database) ===
  
 Replace the MemDataBook with following code: Replace the MemDataBook with following code:
Line 792: Line 792:
 </​file>​ </​file>​
  
-=== 3-tier data (database) ===+=== Three-Tier Data (Database) ===
  
 Remote DBAccess, DBStorage and DirectObjectConnection and replace the MasterConnection with following code: Remote DBAccess, DBStorage and DirectObjectConnection and replace the MasterConnection with following code:
Line 806: Line 806:
 </​file>​ </​file>​
  
-==== Example for automatic link cell editors ​===+==== Example for Automatic Link Cell Editors ​===
  
 The client code: The client code:
Line 1190: Line 1190:
  
    //​~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    //​~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-   // Interface ​implementation+   // Interface ​Implementation
    //​~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    //​~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  
Line 1210: Line 1210:
        
    //​~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    //​~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-   // User-defined methods+   // User-Defined Methods
    //​~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    //​~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        
Line 1585: Line 1585:
 </​file>​ </​file>​
  
-==== Encrypt ​passwords ​====+==== Encrypt ​Passwords ​====
  
-We don't encrypt passwords on client-side ​and not in the database. We use our middleware for that. It's super easy with server-side triggers/​events:​+We don't encrypt passwords on client-side ​nor in the database. We use our middleware for that. It's super easy with server-side triggers/​events:​
  
 Add the method: Add the method:
Line 1625: Line 1625:
 </​file>​ </​file>​
  
-to your life-cycle ​object e.g. Session.java.+to your lifecycle ​objecte.g.Session.java.
  
 Add an event to your storage Add an event to your storage
Line 1655: Line 1655:
 Choose one of the following algorithm: MD2, MD4, MD5, SHA, SHA-256, SHA-384, SHA-512. Choose one of the following algorithm: MD2, MD4, MD5, SHA, SHA-256, SHA-384, SHA-512.
  
-==== Fetch data with DBStorage ====+==== Fetch Data With DBStorage ====
  
-Sometimes you want to use DBAccess and DBStorage without JVx server and life-cycle ​objects. This is very easy because JVx was designed as library. Simply use DBStorage and DBAccess in your Servlets, applications, ​...+Sometimes you want to use DBAccess and DBStorage without JVx server and lifecycle ​objects. This is very easy because JVx was designed as library. Simply use DBStorage and DBAccess in your Servlets, applications, ​etc.
  
 The following example uses DBAccess and DBStorage to check if a user exists in the database and if an email address doesn'​t exist. The following example uses DBAccess and DBStorage to check if a user exists in the database and if an email address doesn'​t exist.
Line 1683: Line 1683:
 </​file>​ </​file>​
  
-==== 50% width with FormLayout ====+==== 50% Width With FormLayout ====
  
-If you have two components, e.g. GroupPanels and if you want that each group is 50% of the parent width, you could use following code:+If you have two components, e.g.GroupPanelsand if you want that each group is 50% of the parent width, you could use following code:
  
 <file java> <file java>
Line 1706: Line 1706:
 </​file>​ </​file>​
  
-==== Search ​column ​in condition ​====+==== Search ​Column ​in Condition ​====
  
 If you create your own IStorage impelementation,​ it could be useful to know how to find the value for a specific column: If you create your own IStorage impelementation,​ it could be useful to know how to find the value for a specific column:
Line 1738: Line 1738:
 </​file>​ </​file>​
  
-Above method tries to find the first Equals ​condition with the given column name.+The above method tries to find the first equals ​condition with the given column name.
  
 The method doesn'​t work with recursion because usually this is not necessary. If you want to know the different condition types, simply check ''​toString()''​ of ''​javax.rad.model.condition.BaseCondition''​. The method doesn'​t work with recursion because usually this is not necessary. If you want to know the different condition types, simply check ''​toString()''​ of ''​javax.rad.model.condition.BaseCondition''​.
  
-==== Connection ​property changed listener ​====+==== Connection ​Property Changed Listener ​====
  
 It's easy to listen on connection property changed events: It's easy to listen on connection property changed events:
Line 1757: Line 1757:
 </​file>​ </​file>​
  
-Above listener will be invoked whenever the connection property **Application.mode** will be changed.+The above listener will be invoked whenever the connection property **Application.mode** will be changed.
  
 It's also possible to listen on all properties, with following snippet: It's also possible to listen on all properties, with following snippet:
Line 1772: Line 1772:
 </​file>​ </​file>​
  
-==== Test UI with simple ​JUnit Test ====+==== Test UI With Simple ​JUnit Test ====
  
 Sometimes you want a JUnit test case for a specific UI feature. If you need an application frame for your test, you could use following implementation:​ Sometimes you want a JUnit test case for a specific UI feature. If you need an application frame for your test, you could use following implementation:​
Line 2180: Line 2180:
 </​file>​ </​file>​
  
-==== Authentication/​User ​logging ​====+==== Authentication/​User ​Logging ​====
  
 Some applications need detailed information about successful or failed user logins. If you have such requirement,​ you could create a custom security manager to solve the problem. The security manager will be used for user authentication,​ so it's the right place to start. Some applications need detailed information about successful or failed user logins. If you have such requirement,​ you could create a custom security manager to solve the problem. The security manager will be used for user authentication,​ so it's the right place to start.
Line 2343: Line 2343:
 </​file>​ </​file>​
  
-==== Detect Production ​mode ====+==== Detect Production ​Mode ====
  
 If you use the DBSecurityManager,​ it's possible to set the environment. The environment is a marker for the database connection, e.g.: If you use the DBSecurityManager,​ it's possible to set the environment. The environment is a marker for the database connection, e.g.:
Line 2368: Line 2368:
  
 The marker will be used as postfix for the detection of datasource credentials. In the example, the postfix is **prod** and the **username_prod** will be used instead of **username**. If not tag with environment postfix is available, the standard tag will be used.  The marker will be used as postfix for the detection of datasource credentials. In the example, the postfix is **prod** and the **username_prod** will be used instead of **username**. If not tag with environment postfix is available, the standard tag will be used. 
 +
 +If you want to use the environment in your source code, simply call:
 +
 +<file java>
 +String env = SessionContext.getCurrentSessionConfig().getProperty("/​application/​securitymanager/​environment"​);​
 +</​file>​
This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information