Many a times people are confused that how to show error message in the custom portlet. Liferay allows to show custom error messages on the JSP inside custom portlet.
There are two simple steps available to configure it:
1) Modify JSP to use liferay-ui taglib
2) Modify controller class to add the error key inside SessionError
Here are the detailed steps:
1) Modify JSP to use liferay-ui taglib
Here is JSP snippet
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
<liferay-ui:error key="error" message="Error occured while processing your request!" />
<liferay-ui:message key="sucess" />
Here we have used "liferay-ui" tablib. Upon loading the JSP key will be compared with the key available inside the "SessionError" if matching key is
found then the message written under "message" will be shown on the JSP else not.
2) Modify controller class to add the error key inside SessionError
public void getFirstStudentDetails(ActionRequest actionRequest,
ActionResponse actionResponse) throws IOException, PortletException {
try {
//Perform Some Action
} catch(Exception e) {
//Add "error" key inside SessionError
SessionErrors.add(actionRequest, "error");
throw e;
}
//Default success message
SessionMessages.add(actionRequest, "message");
}
Now, build and deploy your portlet. Next time when "getFirstStudentDetails" is called and if any error comes then inside "catch" blok
error key i.e. "error" will be added inside "SessionErrors" and during rendering of the JSP below line will show the error message to the user.
<liferay-ui:error key="error" message="Error occured while processing your request!" />
Cheers! You are done.
Cheers!
Henal Saraiya
(Senior Consultant)
CIGNEX Datamatics
There are two simple steps available to configure it:
1) Modify JSP to use liferay-ui taglib
2) Modify controller class to add the error key inside SessionError
Here are the detailed steps:
1) Modify JSP to use liferay-ui taglib
Here is JSP snippet
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
<liferay-ui:error key="error" message="Error occured while processing your request!" />
<liferay-ui:message key="sucess" />
Here we have used "liferay-ui" tablib. Upon loading the JSP key will be compared with the key available inside the "SessionError" if matching key is
found then the message written under "message" will be shown on the JSP else not.
2) Modify controller class to add the error key inside SessionError
public void getFirstStudentDetails(ActionRequest actionRequest,
ActionResponse actionResponse) throws IOException, PortletException {
try {
//Perform Some Action
} catch(Exception e) {
//Add "error" key inside SessionError
SessionErrors.add(actionRequest, "error");
throw e;
}
//Default success message
SessionMessages.add(actionRequest, "message");
}
Now, build and deploy your portlet. Next time when "getFirstStudentDetails" is called and if any error comes then inside "catch" blok
error key i.e. "error" will be added inside "SessionErrors" and during rendering of the JSP below line will show the error message to the user.
<liferay-ui:error key="error" message="Error occured while processing your request!" />
Cheers! You are done.
Cheers!
Henal Saraiya
(Senior Consultant)
CIGNEX Datamatics
No comments:
Post a Comment