Announcement Announcement Module
Collapse
No announcement yet.
Configuring theme source in the dispatcher servlet configuration file Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Configuring theme source in the dispatcher servlet configuration file

    Hi,

    Can anyone tell me how to configure theme source (.css files and images)using class org.springframework.ui.context.support.ResourceBun dleThemeSource in the configurationn files?

    thanks
    Prabhat
    [email protected]

  • #2
    Refer to the Theme documentation on which ThemeResolver strategy you wish to use. http://static.springframework.org/sp...-themeresolver

    Here's a sample theme definition.

    Code:
    <bean id="themeResolver" class="org.springframework.web.servlet.theme.FixedThemeResolver">
            <property name="defaultThemeName">
                <value>theme</value>
            </property>
        </bean>
        <bean id="themeSource" class="org.springframework.ui.context.support.ResourceBundleThemeSource"></bean>
    Where there is a properties file name theme.properties in the root of the classpath containing properties you wish to create themes around.

    Comment


    • #3
      not displaying the Images

      Hi,
      Thanks for ur reply.
      There is a small problem coming with my code. Dispatcher servlet is reading the theme.properties file and writting the values to the jsp page but in the response to the browser it is not displaying the images.
      JSP code:

      <%@ taglib prefix="spring" uri="/WEB-INF/tld/spring.tld" %>
      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
      "http://www.w3.org/TR/html4/loose.dtd">

      <html>
      <head>
      <title>Furniture Shop</title>
      <link rel="stylesheet" href="<spring:theme code="styleSheet"/>" type="text/css"/>
      </head>
      <body background="<spring:theme code="background"/>">

      <table width="760" border="0" cellspacing="0" cellpadding="0" align="center">
      <tr><td><img class="banner" src="<spring:theme code="bannerImage"/>" alt="Image not available."></td></tr>
      </table>
      </body>
      </html>

      Bean definition in the configuration file is:

      <bean id="themeResolver" class="org.springframework.web.servlet.theme.Fixed ThemeResolver">
      <property name="defaultThemeName">
      <value>theme</value>
      </property>
      </bean>

      <bean id="themeSource" class="org.springframework.ui.context.support.Reso urceBundleThemeSource"/
      >

      Can anyone tell me where the mistake is?

      Thanks

      Comment


      • #4
        Can you also post you theme.properties? What is the resulting HTML when you do a view source in the browser? Guess what I'm trying to say is what is in the src attribute of your img tag. Is it blank or does it have a value. If it has a value I would speculate that the path to your image is the problem, not the theme.

        Comment


        • #5
          HTML page and theme.properties file

          This is a HTML age generated by the code:

          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
          "http://www.w3.org/TR/html4/loose.dtd">

          <html>
          <head>
          <title>Furniture Shop</title>
          <link rel="stylesheet" href="./themedata/candy.css" type="text/css"/>
          </head>
          <body background="/themedata/Att.jpg">

          <table width="760" border="0" cellspacing="0" cellpadding="0" align="center">
          <tr><td><img class="banner" src="/themedata/Banner.jpg" alt="Image not available."></td></tr>
          </table>
          </body>
          </html>


          theme.properties file:

          styleSheet=./themedata/candy.css

          bannerImage=/themedata/Banner.jpg

          background=/themedata/Att.jpg

          Comment


          • #6
            Is the directory themedata publicly accessible via a browser (not in WEB-INF)? It looks like the theme support is working since it is putting the values from your theme.properties into the html content sent down to the browser.

            Comment


            • #7
              Directory

              Hi,

              the path of the themedata directory is:

              /WEB-INF/jsp/themedata/

              Thanks

              Comment


              • #8
                Need to move this out of WEB-INF into the root of you WebContent directory (directory that contains WEB-INF). The problem is everything in WEB-INF is consider protected and will not be served up to a Web browser directory.

                Directory structure should look like below.

                Code:
                WebRoot
                    index.jsp
                    WEB-INF
                            web.xml
                            jsps
                    themedata
                       candy.css
                       Att.jpg
                       Banner.jpg
                    META-INF

                Comment


                • #9
                  Sorry; again not working

                  Hi,

                  its not working now as well.
                  now i am giving some more details:

                  when my project runs index.jsp redirect the request to the /WEB-INF/jsp/index.jsp page which is using the theme properties to display the images.

                  I have done that you told but it is not displaying the images.

                  thanks

                  Comment


                  • #10
                    Again, this is not a Spring theme problem. This is problem with where you have the files. If you cannot go to a browser and enter in the path of the image and see the image in the browser you don't have the file(s) in the correct location.

                    What does you current directory structure look like?

                    Comment


                    • #11
                      Directory Structure

                      WEB
                      META-INF
                      WEB-INF
                      classes
                      theme.properties
                      jsp
                      tld
                      applicationContext.xml
                      dispatcher-servlet.xml
                      web.xml
                      themedata
                      candy.css
                      Att.jpg
                      Banner.jpg
                      index.jsp

                      Comment


                      • #12
                        Can't tell from you post the hierarchy. Is themedata folder directly in the WEB folder?

                        Comment


                        • #13
                          Sorry: this is the hierarchy

                          WEB
                          META-INF
                          WEB-INF
                          classes
                          theme.properties
                          jsp
                          tld
                          applicationContext.xml
                          dispatcher-servlet.xml
                          web.xml
                          themedata
                          candy.css
                          Att.jpg
                          Banner.jpg
                          index.jsp

                          Comment


                          • #14
                            This is the correct hierarchy. Should be working now. Have you republished your application to your test server?

                            Can you go to a browser and enter http://localhost:8080/yourappcontext...ata/Banner.jpg

                            Assuming your server starts up on port 8080.

                            Comment


                            • #15
                              Displaying image

                              well it is showing the image by accessing direct to the server

                              http://localhost:8080/FurnitureShop2...ata/Banner.jpg

                              but i am sorry this file is not diaplaying when i run the project.


                              thanks

                              Comment

                              Working...
                              X