Results 1 to 5 of 5

Thread: dynamic jsp: help in view-validator-successView

  1. #1
    Join Date
    May 2007
    Posts
    3

    Default dynamic jsp: help in view-validator-successView

    Hi all,

    It's the first time I try to make a server side validation of my web-pages.
    I created a test webapp and that works perfectly:

    ->FormController (extends SimpleFormController) uses a validator to display the currentView page (page by default and when errors), and the successView after onSubmit -> no problem (both jsps exist already in the WEB-INF/jsp).

    My current project has to create dynamically .jsp (through a database).
    my problem is that my jsp webforms are empty.
    workflow:
    go to the database -> pageController (implements Controller) -> jsp -> browser.

    Using a SimpleFormController doesn't allow me to create the jsp compare to the Controller's handleRequest method.
    So, how can I do to implement the validation process if the currentView is not already populated at the FormController step?

    I hope you visualize what I mean.
    Thanks for any clarification.

  2. #2
    Join Date
    Feb 2005
    Posts
    217

    Default

    My current project has to create dynamically .jsp (through a database).
    Do you mean have the JSP files themselves created dynamically? That seems a little bit weird. What you want to do is create your JSP and put in code/jsptags/whatever in there to dynamically display your content.

    Or do you mean to display a different JSP based on some user inputs? You'll want to return a different "viewName" in your ModelAndView, ie:
    Code:
      return new ModelAndView(
        (req.getParameter("foo") != null) ? "fooView" : "nonFooView");
    If your code doesn't explicitly return a "ModelAndView" then you're going to use the default formView and successView that you defined in your XML.

  3. #3
    Join Date
    May 2007
    Posts
    3

    Default

    Hi,
    my jsp is dynamically populated/displayed Indeed :
    Code:
    <html>
       <%-- .............................. --%>
      <c:forEach items="${Item}" var="item">
      <center>
        <<c:out value="${item.html}"escapeXml="false"/>>
      </center>
      </c:forEach>
      </form>
      </body>
    </html>
    here my actual controller:
    Code:
    public class GenericFormController extends SimpleFormController {
    
        public ModelAndView onSubmit(Object command)
                throws ServletException {
    
            return new ModelAndView(new RedirectView(getSuccessView()));
        }
    
        protected Object formBackingObject(HttpServletRequest request) throws ServletException {
    
            Test test = new Test();
             /*...........*/
            return test;
    
        }
    and my xml:
    Code:
        <bean id="test" class="bean.Test"/>
    
        <bean id="testVal" class="validator.TestVal">
            <property name="test">
                <ref bean="test"/>
            </property>
        </bean>
    
        <bean id="genericFormController" class="web.GenericFormController">
            <property name="sessionForm"><value>true</value></property>
            <property name="commandName"><value>bean</value></property>
            <property name="commandClass"><value>bean.Test</value></property>
            <property name="validator"><ref bean="testVal"/></property>
            <property name="formView"><value>test</value></property>
            <property name="successView"><value>done.html</value></property>
    
            <property name="dataSource">
                <ref bean="dataSource"/>
            </property>
        </bean>
    
        <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
            <property name="mappings">
                <props>
                    <prop key="test.html">genericFormController</prop>
                    <prop key="done.html">sqlController</prop>
                </props>
            </property>
        </bean>
    Without a validator I just used to use a Controller to connect to the data base, put the information into a Object's List than display the jsp:
    Code:
    public class GenericController extends AbstractController
    {
        DataSource dataSource;
    
    
        HashMap<String, Object> map;
    
        public GenericController()
        {
        }
    
        public void setDataSource(DataSource dataSource){
            this.dataSource = dataSource;
        }
    
        public ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse httpServletResponse) throws Exception
        {
    
            map = new HashMap<String, Object>();
    
            PageQuery pq = new PageQuery(dataSource);
            Page p = pq.runQuery(1);
            map.put("Page",p);
    
            ItemQuery iq = new ItemQuery(dataSource);
            ArrayList items = iq.runQuery(1);
            map.put("Item",items);
    
            return new ModelAndView("test", map);
        }
    
    }
    Right now, I catch test.html which launches 'genericFormController', validator and the formView (test.jsp) is displayed, but I have a blank page.
    So, I think you better understood that I would like to add a step to populate dynamically my test.jsp via one other Controller before being displayed.

    I tried to create a such Controller, but the xml file doesn't like me to assign something else than:
    Code:
    <property name="formView"><value>test</value></property> 
    <!-- 'test' here is test.jsp  -->
    I tried to set the bean of the new Controller (which populate AND Display the jsp) as a value of "formView" but I got an error.

    Thanks for your help.

  4. #4
    Join Date
    May 2007
    Posts
    3

    Default Problem of jsp interpretation in the browser

    hi,

    I managed to skip (but not exactly the behavior I expected) the problem I exposed above setting the formView to a jsp which redirects to the controller which populate the jsp via with database data and create a ModelAndView.

    But now, I get the form page ok except for this:

    I use jstl tag to have access to the bean information.
    my jsp:
    Code:
    ...
      <c:forEach items="${Item}" var="item">
      <center>
        <<c:out value="${item.html}"escapeXml="false"/>>
      </center>
    ...
      </c:forEach>
    but some 'item.html' contain other jstl and spring form tag (like spring:bind).
    exemple:
    Code:
    html = "spring:bind path="+springBind+">\n" +
              "<span>"+label+"</span>\n<input type=text id="+nameRef+" name="+nameRef+" value=\"<c:out value=${"+springBind+"}\" />"+szClass+function+"/>\n"+
              "</spring:bind";
    so, I got the following html code:
    Code:
    send to browser:
       <spring:bind path=bean.f1_1_1>
       <span>Patient #</span>
       <input type=text id=f1_1_1 name=f1_1_1 value="<c:out value='${bean.f1_1_1}' />"/>
       </spring:bind>
    
    browser's interpretation:
       <spring:bind _moz-userdefined="" path="bean.f1_1_1">
       <span>Patient #</span>
       <input id="f1_1_1" type="text" value="<c:out value=${bean.f1_1_1} />" name="f1_1_1"/>
      </spring:bind>
    So, my problem here is that <c: out isn't interpreted but just considered as a String.
    Anyone has any idea to reload the jsp interpretation process?
    Do have I to split the process into: first create a first jsp (to obtain only html code except the <c: out expressions, store it and then send it back to the browser? but if yes, how??

  5. #5
    Join Date
    Feb 2005
    Posts
    217

    Default

    If you want to use "<c : out...>" you must import the taglib, but you could also just do a "${item.html}" without the c tag.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •