Announcement Announcement Module
Collapse
No announcement yet.
Tiles and spring form tags Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Tiles and spring form tags

    Hello to everyone, I'm a new user of spring, and I'm making my second application with it (the first one was Hello world ;P ). I'm working with tiles, my question is simple, I have a jsp called login.jsp which is composed by 4 tiles (header, footer, menu and body) , the body tile contains the login, I mean it asks the user name and the password, I want to use the form tags from spring, can I put the <form:input> and <form:form> tags inside the body.jsp???
    I've been traying to do it, but it doesn't work. (I have my tiles-def.xml file and without the form tag everything works fine)
    please help!

  • #2
    I found out the solution, thanks anyway!

    Comment


    • #3
      I was wondering if you could provide me with information on how you resolved this issue?

      Comment


      • #4
        Just adapt this to your needs

        In the viewResolver, you just need to specify that you are using TilesJstlView

        And in the second bean you just need to load you tiles file

        <bean id="viewResolver"
        class="org.springframework.web.servlet.view.Intern alResourceViewResolver">
        <property name="prefix">
        <value>/WEB-INF/jsp/</value>
        </property>
        <property name="suffix">
        <value>.jsp</value>
        </property>
        <property name="viewClass">
        <value>org.springframework.web.servlet.view.tile s.TilesJstlView</value>
        </property>
        <property name="order">
        <value>1</value>
        </property>
        </bean>

        <bean id="tilesConfigurer"
        class="org.springframework.web.servlet.view.tiles. TilesConfigurer">
        <property name="definitions">
        <list>
        <value>/WEB-INF/config/tiles-defs.xml</value>
        </list>
        </property>
        </bean>

        Comment


        • #5
          Form tags

          I believe I have everything configured correctly. My problem is to do with importing the spring forms tab library reference.
          I have a template page, which I extend to insert a body jsp. I would like to define all my tag libraries in this template page. However, when I use the spring form tag, this approach does not work. Instead, I have to define it in my body page in order for it to resolve the form tags.
          I was wondering if there was a way to configure the tiles setup so that I can define the spring forms tag library in the parent template page?

          Comment


          • #6
            Please check this jsp, which I have named layout.jsp, this is the page where everything gets injected. Im replacing the content for this page and also the title.

            <html>
            <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title><tiles:getAsString name="title"/></title>
            <link rel="stylesheet" href="/springwebapp/styles/master.css" type="text/css">
            </head>
            <body>
            <div class="container">
            <tiles:insert attribute="header"/>
            <tiles:insert attribute="navigation"/>
            <tiles:insert attribute="content"/>
            <tiles:insert attribute="footer"/>
            </div>
            </body>
            </html>

            And here you have the tiles-defs.xml file which is the file where you specify which content will you override for the content in the layout page. With this information and the one I have provided you in the last post, i think you should be done, dont forget to add the struts.jar to your classpath

            <?xml version="1.0" encoding="ISO-8859-1" ?>

            <!DOCTYPE tiles-definitions PUBLIC
            "-//Apache Software Foundation//DTD Tiles Configuration 1.1//EN"
            "http://jakarta.apache.org/struts/dtds/tiles-config_1_1.dtd">

            <tiles-definitions>

            <definition name=".layout" path="/WEB-INF/common/Layout.jsp">
            <put name="title" value="SpringWebApp"/>
            <put name="header" value="/WEB-INF/common/Header.jsp" type="page"/>
            <put name="navigation" value="/WEB-INF/common/Navigation.jsp" type="page"/>
            <put name="content" value="nothing" type="string"/>
            <put name="footer" value="/WEB-INF/common/Footer.jsp" type="page"/>
            </definition>

            <definition name="/WEB-INF/jsp/welcome.jsp" extends=".layout">
            <put name="title" value="SpringWebApp - Welcome"/>
            <put name="content" value="/WEB-INF/jsp/welcome.jsp" type="page"/>
            </definition>

            </tiles-definitions>

            Comment


            • #7
              I have an almost identical configuration as to what you describe.

              At the top of my layout.jsp, I import a tag library , see below as an example :
              <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
              <html>
              <head>
              <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
              <title><tiles:getAsString name="title"/></title>
              <link rel="stylesheet" href="/springwebapp/styles/master.css" type="text/css">
              </head>
              <body>
              <div class="container">
              <tiles:insert attribute="header"/>
              <tiles:insert attribute="navigation"/>
              <tiles:insert attribute="content"/>
              <tiles:insert attribute="footer"/>
              </div>
              </body>
              </html>


              In the my welcome.jsp, I reference the spring form tag library. However it isnt
              resolved at runtime and prevents the form from functioning.

              If I import this tag library locally in the welcome.jsp, then everything works fine.

              I just wanted to know if there is way that I can get the welcome.jsp to inherit the imported tag libraries defined in the layout.jsp. Are you aware if there is anyway of configuring this through spring and struts? It would be handy to be able to define a list of commonly used tag libraries in the parent template.

              Thanks for your help.

              Comment


              • #8
                just create a jsp file and name it as you like and include all the tags that you need
                <!--Taglibs.jsp-->
                <%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
                <%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
                <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
                <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
                <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
                <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
                <%@ taglib uri="http://www.springmodules.org/tags/commons-validator" prefix="validator" %>


                then import the taglibs in each page where you might need them
                <!--Welcome.jsp-->
                <%@ include file="/WEB-INF/common/taglibs.jsp" %>
                Last edited by Shearer; Oct 30th, 2007, 03:39 PM.

                Comment


                • #9
                  SO what is it?

                  Comment

                  Working...
                  X