View Full Version : to show sucess/error messages in the same page
Deepti_raju
Feb 5th, 2008, 05:55 AM
Hi,
We have jsp page with a table containg rows of data and radio button against each row. When the user selects a row with radion button and clicks on the delete button at the bottom of the page to delete the selected row, I would like to show a message in the same page as "the data is deleted".
I am using a SimpleFormController and JSLT in jsp. I am able to do the deleting part, but i need some help on the message part.
Thanks,
Deepti
Tilak
Feb 5th, 2008, 06:31 AM
Hi Raju,
Can you please be clear on ur requirement.
regards,
Tilak
Hi,
We have jsp page with a table containg rows of data and radio button against each row. When the user selects a row with radion button and clicks on the delete button at the bottom of the page to delete the selected row, I would like to show a message in the same page as "the data is deleted".
I am using a SimpleFormController and JSLT in jsp. I am able to do the deleting part, but i need some help on the message part.
Thanks,
Deepti
gehel
Feb 5th, 2008, 06:46 AM
If I understand correctly, you should be able to add a message to the ModelAndView and display it in your JSP :
Add the message :
mav.addObject("message", "the line has been deleted");
Display :
<c:if test="${not empty message}">
${message}
</c:if>
Deepti_raju
Feb 6th, 2008, 09:23 AM
Thanks a lot for the solution. But i would like to know how to implement <fmt:message>. I tried an example
Below is my jsp code
I am using jstl 1.0 and have downloaded the corresponding tlds also. When the i run the code, i get the output as
message=hello ???helloWorldLabel??? hello
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<html>
<head>
<title>Formate example</title>
</head>
<body>
<%
if(request.getAttribute("message")!=null)
{
String msg = (String)request.getAttribute("message");
System.out.println("message= "+msg);
out.println("message= "+msg);
}
%>
<fmt:setLocale value="label_en"/>
<fmt:setBundle basename="internalization"/>
<fmt:message key="helloWorldLabel"/>
<c:out value="${message}"/>
</body>
</html>
web-inf.xml- the path is rite for tld files.
<taglib id="TagLibRev_JSTL_fmt">
<taglib-uri>http://java.sun.com/jstl/fmt</taglib-uri>
<taglib-location>/WEB-INF/tld/fmt.tld</taglib-location>
</taglib>
<taglib id="TagLibRev_JSTL_fmt_rt">
<taglib-uri>http://java.sun.com/jstl/fmt_rt</taglib-uri>
<taglib-location>/WEB-INF/tld/fmt-rt.tld</taglib-location>
</taglib>
<taglib id="TagLibRev_JSTL_core">
<taglib-uri>http://java.sun.com/jstl/core</taglib-uri>
<taglib-location>/WEB-INF/tld/c.tld</taglib-location>
</taglib>
<taglib id="TagLibRev_JSTL_core_rt">
<taglib-uri>http://java.sun.com/jstl/core_rt</taglib-uri>
<taglib-location>/WEB-INF/tld/c-rt.tld</taglib-location>
</taglib>
Controller
public class FormatController implements Controller {
/* (non-Javadoc)
* @see org.springframework.web.servlet.mvc.Controller#han dleRequest(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
public ModelAndView handleRequest(
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
// TODO Auto-generated method stub
return new ModelAndView("formatEx","message","hello");
}
Inside the /WEB-INF/classes/internationalization is the label_en.properties and the contents are
helloWorldLabel=Hello World!
Please let me know what is the problem with my code
Thanks,
Deepti
gehel
Feb 6th, 2008, 09:50 AM
Please use
tags when posting code.
You can find the documentation for fmt at http://java.sun.com/products/jsp/jstl/1.1/docs/tlddocs/index.html.
I think that instead of
<fmt:setLocale value="label_en"/>
<fmt:setBundle basename="internalization"/>
<fmt:message key="helloWorldLabel"/>
you should have :
[code]<fmt:setLocale value="en"/>
<fmt:setBundle basename="internalization.label"/>
<fmt:message key="helloWorldLabel"/>
Deepti_raju
Feb 6th, 2008, 10:59 PM
Hello,
Hey this didn't work either, i have also added the following code in the serverlt.xml file
<bean id="messageSource" class="org.springframework.context.support.ResourceBundle MessageSource">
<property name="basename">
<value>internalization.label</value>
</property>
</bean>
gehel
Feb 7th, 2008, 01:29 AM
How doesnt it work ? Error message ? Same output as before ?
If you want to use Spring MessageSource, you need to use Spring message tags : http://static.springframework.org/spring/docs/2.5.x/reference/spring.tld.html#spring.tld.message.
Deepti_raju
Feb 7th, 2008, 03:52 AM
I am still getting the same error, like ???helloworldLabel???
thanks,
Deepti
gehel
Feb 7th, 2008, 05:02 AM
actually, the <fmt:message/> has to be inside the <fmt:bundle/> tag. Have a look at http://www.onjava.com/pub/a/onjava/2002/09/11/jstl2.html?page=2.
By the way, I mainly use the spring:message tag, and not fmt:message ... so take my advices with a grain of salt ;-)
Deepti_raju
Feb 7th, 2008, 05:24 AM
Hi,
Hey this too didn't work. If i use spring:message, do you have a complete example for to implement ?
Thanks,
Deepti
gehel
Feb 7th, 2008, 06:17 AM
I dont have the code at hand. I can try to send it tomorrow. But it seemed pretty straight forward ...
Powered by vBulletin® Version 4.2.1 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.