Develop > Presentation layer > Work with JSP pages > WebSphere Commerce JSP programming best practices
JSP programming best practice: Use the StoreErrorDataBean data bean for error handling
To display store-specific error messages in JSP pages, use the StoreErrorDataBean data bean.
This data bean provides getter methods to:
- Retrieve the store error key, <ECMessageKey>.<Error Code>
- Retrieve the error message parameters, that is, the substitution parameters used in the error messages
In mapping error codes to error messages, the StoreErrorDataBean data bean relies on the existence of the store error message properties file...
WC_EAR/Stores.war/WEB-INF/classes/ storedir/storeErrorMessages_locale.propertiesThe store error message properties file should contain error message definitions, such as the following:
# UserRegistrationAddForm.jsp
_ERR_CMD_INVALID_PARAM.2020 = Type an e-mail address in the E-mail address field.
_ERR_CMD_INVALID_PARAM.2050 = Type the password in the Password field.
# UserRegistrationUpdateForm.jsp
_ERR_AUTHENTICATION_MINIMUMLENGTH_PASSWORD.2200 = The password you have entered contains fewer than {0} characters. Ensure that your password is at least {0} characters in length, including {1} digit(s) and {2} letter(s), and try again.
The following is an example of the StoreErrorDataBean use:
<wcbase:useBean id="storeError" classname="com.ibm.commerce.common.beans.StoreErrorDataBean" scope="page"> <c:set target="${storeError}" property="resourceBundleName" value="${sdb.jspStoreDir}/storeErrorMessages" /> </wcbase:useBean> <c:if test="${!empty storeError.key}"> <c:set var="errorMessage" value="${storeError.message}" /> </c:if>
Related concepts
WebSphere Commerce framework overview
Related tasks
Related reference
JSP programming best practice: Use the Commerce-specific tag for bean activation
WebSphere Commerce JSP programming best practices