Panel | ||
---|---|---|
| ||
This section describes how error, warning, and question messages are created.
What does this section cover?
|
The following document describes how error, warning and question messages are developed in our system. Generally, a certain procedure is been followed, starting from constructing a method which calls the message statement or throw an exception message whilst metadata and translation files should be changed accordingly to show the appropriate messages on the screen. Although, we are going to discuss three different illustrative examples below.
Error Messages
...
Error Messages
In order for an error message to appear on screen, a java exception must be created and thrown.
- Create the Exception class.
All exception classes must extend com.crm.exception.CRMValidationException. All exception methods should have a com.crm.exception.CRMValidationException object as an input parameter and use setMessage method of com.crm.exception.CRMException class
To create the exception method:
- Use com.crm.businessobject.CRMSession object as an input parameter and any other String input parameters needed.
- Put all String input parameters in a String ArrayList.
- Use setMessage method of com.crm.exception.CRMException class to construct the exception message.
Code Block | ||||
---|---|---|---|---|
| ||||
public class AccountTerminationException extends CRMValidationException {
/**
* You are not allowed to terminate the Accounts Receivable %1. This is only allowed for Active or Suspended accounts.
*
* @param crmSession - the session object
* @param value - the exception value
* @throws Exception
*/
public AccountTerminationException(CRMSession crmSession, String value) throws Exception {
super();
ArrayList<String> parameters = new ArrayList<String>();
parameters.add(value);
try
{
setMessage(this.getClass().getName().toUpperCase(), crmSession, parameters);
}
catch (Exception e)
{
e.printStackTrace();
}
}
} |
2. Define the exception in the messages.xml file. Use a unique key for the expression tag.
Code Block | ||||
---|---|---|---|---|
| ||||
<messages>
<message>
<code>COM.CRM.EXCEPTION.ACCOUNTS.ACCOUNTTERMINATIONEXCEPTION</code>
<expression>key_com_crm_exception_accounts_accountterminationexception</expression>
<description>You are not allowed to terminate the accounts receivable. This is only allowed for Active or Suspended accounts.</description>
</message>
.
.
.
</messages> |
3. Define the exception in the properties file, by using the expression tag key defined in metadata messages file as the entry key, and specifying the exception message. Use %<number> where the input parameters should be placed. Note that <number> is their index+1 in parameters array list.
Code Block | ||||
---|---|---|---|---|
| ||||
<properties>
<entry key="key_com_crm_exception_accounts_accountterminationexception">You are not allowed to terminate the accounts receivable %1. This is only allowed for Active or Suspended accounts.</entry>
.
.
.
</properties> |
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
package com.crm.exception.accounts; import java.util.ArrayList; import com.crm.businessobject.CRMSession; import com.crm.exception.CRMValidationException; public class InvalidAccountCreditPeriodException extends CRMValidationException { private static final long serialVersionUID = 1L; /** * Invalid Credit period %1 based on definition (%2 % 3). * * @param crmSession - the session object * * @param value1 - the first exception value * @param value2 - the second exception value * @param value3 - the third exception value * * @throws Exception */ public InvalidAccountCreditPeriodException(CRMSession crmSession, String value1, String value2, String value3) throws Exception { super(); ArrayList<String> parameters = new ArrayList<String>(); parameters.add(value1); parameters.add(value2); parameters.add(value3); try { setMessage(this.getClass().getName().toUpperCase(), crmSession, parameters); } catch (Exception e) { e.printStackTrace(); } } } |
...