3

I have requirement that:

  • After submitting the request, Liferay displays the message

Your request processed successfully

  • Instead of that I have to add custom messages and display them like course created successfully, course deleted successfully, course modified successfully etc..

Is it possible? Is there any way to display the success or failure message?

<%@page import ="javax.portlet.PortletURL" %>
<%@ page import="javax.portlet.RenderResponse" %>
<%@ page import="javax.portlet.ActionRequest" %>
<%@ page import="com.liferay.portal.kernel.util.Validator" %>
<% 

PortletURL searchCourseURL=renderResponse.createActionURL(); 

searchCourseURL.setParameter(ActionRequest.ACTION_NAME,"findCourses"); 

%>
<script type="text/javascript" src="/html/js/jquery/jquery.js"></script>

<form action="<%=searchCourseURL%>" method="post">
<div class="label1">Enter Course Name</div><input type="text" id="cname" name="cname" value=" "/>
<input type="submit" name="submit" value="Submit"/>
</form>

In the above example, after submitting the request it displays like request process successfully instead I have to display the message:

search is completed

VC1
  • 1,660
  • 4
  • 25
  • 42
ASR
  • 3,289
  • 3
  • 37
  • 65
  • For failure messages check this question, it happens to be my answer :): http://stackoverflow.com/questions/11032229/how-to-show-error-message-in-liferay-portal/11034587#11034587 – Jonny Sep 03 '13 at 07:25

1 Answers1

8

Success messages

In the JSP:

<liferay-ui:success key="key" message="message" />
<liferay-ui:success key="key1" message="message1" />

In Language.properties file

message=search is completed...
message1=search is completed...

In Controller

SessionMessages.add(request, "key");
SessionMessages.add(request, "key1");

Error (failure) messages

In the JSP:

<liferay-ui:error key="error-key" message="error-message" />
<liferay-ui:error key="error-key1" message="error-message1" />

In Language.properties file:

error-message=search couldn't be completed...
error-message1=search couldn't be completed...

In Controller:

SessionErrors.add(request, "error-key");
SessionErrors.add(request, "error-key1");
evaldeslacasa
  • 582
  • 6
  • 17
Laxman Rana
  • 2,904
  • 3
  • 25
  • 37
  • if i want to add it for multiple requests with various messages will it work? if it work then how to write? – ASR Sep 02 '13 at 09:55
  • where i have to use this ? in jsp – ASR Sep 03 '13 at 08:05
  • i added but its not showing any message.what i did is: in jsp below the form in the action method i have written SessionMessages.add(request, "key"); next i modified message=search is completed... – ASR Sep 03 '13 at 11:12
  • 1
    String successMsg = "Course added Successfully!"; SessionMessages.add(request, "request_processed", successMsg); i added like this in my action method. its working! thanks a lot for all u for helping! – ASR Sep 06 '13 at 05:52