Difference between revisions of "Developing codeunits"
old>Admin |
old>Admin |
||
Line 56: | Line 56: | ||
=== User session variables === | === User session variables === | ||
Acces the ''' | Acces the '''sessionValues''' attribute in the '''Security''' object | ||
* boolean hasSessionValue(String name) | * boolean hasSessionValue(String name) | ||
* void setSessionValue(String name, boolean value) | * void setSessionValue(String name, boolean value) | ||
Line 67: | Line 67: | ||
All variables her are serilizable and will survive server restarts. | All variables her are serilizable and will survive server restarts. | ||
It is also possible to store objects in the '''sessionObjects''' in the '''Security''' object | |||
* Methods as per Hashtable | |||
* Data are transient and will not survive server restarts | |||
Certain special user properties can also be accessed from the '''Security''' object | Certain special user properties can also be accessed from the '''Security''' object |
Revision as of 16:50, 15 September 2018
Steps for creating a new codeunit
- Create a new Java project in your favorite IDE
- Import the p2eShared.jar in the project
- Create a new class:
- The abstract parts are found in: dk.p2e.blanket.codeunit
- Implement all abstract methods
- Code the method bodies (normally "execute")
- Compile and build
- Deploy to webservser: [Application]\WEB-INF\lib
After first test of the codeunit a server reboot is needed for each redeployment, as there is no way of removing the loaded classes from memory.
Error handling
Exceptions are handled by themselves using the errorRegistration(Exception e) method.
In case the errors are not caught by the codeunit itself, the generic error handler takes over
- Logs the error in the eventlog
- Returns a standard error page to the user
Other debugging options include log4j and specialized TempusServa Systemout.print functions (yes, the class name is "Systemout").
Systemout.println( "hello world" ); Systemout.printSql( myStatment );
Configuration / parameters
Parameters are delivered through the method call, packed in a nice <String> Hashtable for easy access. Please note that values are sent as-is, so make sure to escape values before DB operations using
DbConnection.escapeSql(String s);
Configurations can be stored using the getConfiguration methods of the command object. These values can be editedthrough the designer, depending on the Codeunit type
- System configurations: Designer > Modules > Static content
- Solution configurations: Designer > [Solution] > Advanced > Configurations
Value names will be prefixed with Class simple name - example + "."
dk.tempusserva.MyExampleCodeunit.myParameter
Session variables
Variables can have a cope of either
- Request
- User session
- Application
For permanent variables user server configurations.
Request variables
Request scope variables should be stored in the Hashtable sharedObjects in the Command object.
Note that the HTTP request parameters are stored in requestParameters.
User session variables
Acces the sessionValues attribute in the Security object
- boolean hasSessionValue(String name)
- void setSessionValue(String name, boolean value)
- int getSessionInteger(String name, int defaultValue)
- int getSessionInteger(String name)
- void setSessionInteger(String name, int value)
- String getSessionString(String name, String defaultValue)
- String getSessionString(String name)
- void setSessionString(String name, String value)
All variables her are serilizable and will survive server restarts.
It is also possible to store objects in the sessionObjects in the Security object
- Methods as per Hashtable
- Data are transient and will not survive server restarts
Certain special user properties can also be accessed from the Security object
- boolean hasProperty(String name)
- String getProperty(String name)
Application variables
Application variables are persistent and accessed through the Command object
Their storage position depends on wether theres is a solution context or not:
- Solution present: Variables are saved to the solution Configurations
- None (SagID = 0): Variables are saved to the Static content
Access the the variables goes through get methods with default values.
- String getConfigurationValue(String name)
- String getConfigurationValue(String name, String defaultValue)
If the variable does not exist it will be created, and set to the default value (if present).
Note that it is possible to force the use of Statis content by explicitly calling
- String getSystemConfigurationValue(String name)
- String getSystemConfigurationValue(String name, String defaultValue)
Different codeunit types
Please read the: Codeunit reference
Most likely you will need to create a Codeunit/Formevents that will allow specific changes for a solution, during views, updates or exports.
Most interactions wil require interaction with the following objects
- Security
- Command
- DbConnection
- EventHandler