Announcement Announcement Module
Collapse
No announcement yet.
<fmt:message> tag problem in my JSP document Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • <fmt:message> tag problem in my JSP document

    In my spring MVC application i have provided i18n option by providing a messageSource in the form of a properties file.

    And i am using the keys provided in this properties file in my jsp pages using the jstl's custom tag library having URI : http://java.sun.com/jsp/jstl/fmt, i.e
    with the following syntax :<fmt:message key="key1" />

    Now i am using this in my welcome page as well as one of my forms.

    The problem i am facing is in my welcome.jsp page i am not getting the key1's value instead i am getting the value as ???key1???.

    While in my second form i am getting the key2's value without any problem.

    Can anybody please let me know what is getting wrong??

    Thanks.

  • #2
    Hello j.gohel

    i had the same problem, first check this
    you should have the bold line

    Code:
    <bean id="viewResolver"
       	class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    	<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /> 
        	<property name="prefix" value="/WEB-INF/jsp/" />
        	<property name="suffix" value=".jsp"/>
      	</bean>
    second, try with this uri <%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %> (i work with it) , notice that no has the jsp part, instead of your uri

    While in my second form i am getting the key2's value without any problem.
    maybe this use my uri

    regards

    Comment


    • #3
      Hello,

      I already have that content in bold in my xxx-servlet.xml file for spring application.And i tried second option also but still the problem persists that is in the index page the key's value form the messageSource is not getting displayed while in other form it is..
      How to solve this...

      Thanks.

      Comment


      • #4
        Hello j.gohel

        can you copy your 2 jsp files and the messageSource file?

        it is weird

        regards

        Comment


        • #5
          &lt;fmt:message&gt; tag

          This is my index.jspx page
          Code:
          <?xml version="1.0" encoding="ISO-8859-1" ?>
          <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0" 
          		  xmlns:c="http://java.sun.com/jsp/jstl/core"
          		  xmlns:fmt="http://java.sun.com/jstl/fmt"	>
              <jsp:directive.page language="java"
                  contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" />
              <jsp:text>
                  <![CDATA[ <?xml version="1.0" encoding="ISO-8859-1" ?> ]]>
              </jsp:text>
              <jsp:text>
                  <![CDATA[ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> ]]>
              </jsp:text>
              
          
          	<html xmlns="http://www.w3.org/1999/xhtml">
          	<head>
          	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
          	<title><fmt:message key="indexPageTitle"/></title>
          	</head>
          	<body>
          		<h3>Welcome </h3>
          		<c:set var="url" value="./usermngr.htm"></c:set>
          		<a href="${url}">Users</a>
          	</body>
          	</html>
          </jsp:root>

          This is my another registrationForm.jspx file(In this the keys' values are getting displayed getting ):

          Code:
          <?xml version="1.0" encoding="ISO-8859-1" ?>
          <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0"
          		   xmlns:c="http://java.sun.com/jsp/jstl/core"
          		  xmlns:fmt="http://java.sun.com/jsp/jstl/fmt"	
          		  xmlns:spring="/spring">
          
              <jsp:directive.page language="java"
                  contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" />
              <jsp:text>
                  <![CDATA[ <?xml version="1.0" encoding="ISO-8859-1" ?> ]]>
              </jsp:text>
              <jsp:text>
                  <![CDATA[ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> ]]>
              </jsp:text>
              
          	<html xmlns="http://www.w3.org/1999/xhtml">
          	<head>
          		<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
          	</head>
          	<body>
          		
          		<form action="post" name="userRegistrationForm">
          			<fieldset>
          					<legend><fmt:message key="piLegendLabel"/></legend>
          					<table cellpadding="5%" cellspacing="5%">
          						<tr>
          							<td><fmt:message key="firstNameLabel"/></td>
          									<td> <input type="text" name="emp_firstName" maxlength="100" size="15" /></td>
          								<td><fmt:message key="middleNameLabel"/></td>
          								<td> <input type="text" name="emp_middleName" maxlength="100" size="15" /></td>
          									<td><fmt:message key="lastNameLabel"/></td>
          	<td> <input type="text" name="emp_lastName" maxlength="100" size="15" /></td>
          								</tr>
          			
          	<tr>			
          							<td><fmt:message key="dobLabel"/></td>
          									<td> <input type="text" name="emp_dob" maxlength="11" size="11" readonly="true" /> </td>
          									</tr>
          	</table>
          	</fieldset>
          	</body>
          	</html>
          </jsp:root>

          MessageResourceBundle.properties contents:

          Code:
          indexPageTitle=EIS
          registrationFormTitle=Registration Form
          
          
          #Personal Information Labels
          piLegendLabel=Personal Information
          firstNameLabel=First Name :
          middleNameLabel=Middle Name :
          lastNameLabel=Last Name :
          dobLabel=Date Of Birth :
          Please let me know if anything wrong..

          Thanks

          Comment


          • #6
            ok man

            based in this
            While in my second form i am getting the key2's value without any problem.
            your first jsp use this
            Code:
            xmlns:fmt="http://java.sun.com/jstl/fmt"
            and no works

            and the second use this

            Code:
            xmlns:fmt="http://java.sun.com/jsp/jstl/fmt"
            and works

            well in your case instead of me, your uri work with the jsp, so
            use
            Code:
            xmlns:fmt="http://java.sun.com/jsp/jstl/fmt"
            in your first jsp file

            it should be enough

            regards

            Comment


            • #7
              No changing it also didn't worked.
              Is there any problems related with JSP documents(.jspx file)???I am guessing this because when both of these pages were in.jsp form they worked nicely.

              When i converted to .jspx the problems are arising.This is the same thing i am facing using form tag library in my .jspx page.There is a thread posted by me for the same in this forum for same.The same form tag library when i am using in a .jsp page it is working fine...

              Please let me know are there any problems in using .jspx pages over .jsp
              pages.

              Thanks

              Comment


              • #8
                sorry about that

                i never worked with .jspx files so i cant help you here,

                BTW when you work only with jsp files you said that works, tell me, which uri you use???

                a suggestion, maybe the <bean id="viewResolver" needs a special class for the jspx, really i dont know, i am telling you this, because the examples is for jsp files and not for jspx files, maybe you need one change or add something else

                and i dont know if is correct that 2 jsp files can work with 2 differents uri's, if i try this, i recieve an error message

                regards

                Comment


                • #9
                  Hello ,

                  I thing i got it where problem is .

                  See this is the snippet in my xxx-servlet.xml application configuration file.:

                  Code:
                  <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
                  		<property name="viewClass">
                  			<value>org.springframework.web.servlet.view.JstlView</value>
                  		</property>
                  		<property name="prefix">
                  			<value>/usermodule/jsps/</value>
                  		</property>		<property name="suffix">
                  			<value>.jspx</value>
                  		</property>
                  	</bean>


                  I think the line in the bold is causing index.jspx to not to use internationalization messages.

                  Because i have project structure like this:

                  Code:
                  AppName
                      index.jspx
                      usermodule
                           jsps
                           js
                      WEB-INF
                           classes
                           lib
                           tlds
                  ...

                  So if my guess is correct then how to rectify this thing...
                  Last edited by j.gohel; Jan 30th, 2007, 03:21 AM.

                  Comment


                  • #10
                    J.gohel

                    I think I got the same problem as you describen in this thread.
                    I'm not sure if I understood finally what was the problem and what the solution.
                    Please, tell me if I got it right:
                    - The problem is that ONLY the JSPs that are located in the folder specified in the "prefix" property of the "viewResolver" bean get the <fmt:message> resolved right??

                    - The solution is to place all JSPs under the same folder specified in that property?


                    Thank you in advance,
                    Geez

                    Comment


                    • #11
                      Hi Geez,

                      No my problem is also not resolved.And i also guessed the same problem as mentioned by you:
                      The problem is that ONLY the JSPs that are located in the folder specified in the "prefix" property of the "viewResolver" bean get the <fmt:message> resolved right??
                      But i also didn't got any reply.

                      So if you get this resolved then please let me know.

                      Thanks bye

                      Comment


                      • #12
                        HI J.gohel,
                        I still found no answer fot this issue.

                        But I'm guessing that in my case the problem is:

                        - When I request a JSP directly (it is located in my "home-html"), it doesn't get in the spring-application context because it is not in the mappings in xxx-servlet.xml, and then the <fmt:message> is not solved because the message source is not available (not defined) outside the spring-application.

                        - When I request a form, which is captured by the mappings in xxx-servlet.xml, and internally is managed by my spring-application and redirected to a JSP view (located in my "home-html/WEB-INF/jsps"), then the <fmt:message> is solved OK

                        I guess that the solution must be to also provide the message source to the raw JSPs through a <fmt:bundle> or something. I still could not test this, I'll tell you when I'm done.

                        Does this match the nature of your problem?
                        Tell me if it works for you

                        greetings

                        Comment


                        • #13
                          problem solved

                          my guess in previous post in the thread was right, now it works.

                          The solution to my problem is:

                          In my web application I have two kind of pages:
                          a) static JSP pages with information (located in my "home-html")
                          b) JSP view-forms managed by spring MVC processes (located in my "home-html/WEB-INF/jsps")

                          - When I request a static JSP (a), the <fmt:message> tags are not solved because the message source is not available (not defined) outside the spring-application.
                          - When I request a form, which is captured by the mappings in xxx-servlet.xml, and internally is managed by my spring-application and redirected to a JSP view (b) then the <fmt:message> is solved OK

                          The solution is to provide the message source in the static JSPs (a) through a <fmt:bundle> tag pointing to resource bundle where the messages are located.


                          greetings
                          Geez

                          Comment

                          Working...
                          X