Announcement Announcement Module
Collapse
No announcement yet.
passing data to FormView Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • passing data to FormView

    How can I pass a data map to researchInstrView that is a jsp page where I go when I don't pass the validator?
    Code:
    	<bean id="QueryInstrumentValidator" class="org.eLab.FormController.Instrument.QueryInstrumentValidator"/>
    	<bean id="searchInstrumentForm" class="org.eLab.FormController.Instrument.SearchInstrumentForm">
    		<property name="successView"><value>listInstrumentView</value></property>
    		<property name="elab"><ref bean="eLab"/></property>
    		<property name="formView"><value>researchInstrView</value></property>
    		<property name ="commandName"><value>Instrument</value></property>
    		<property name ="commandClass"><value>org.hibernate.JoinedTables.QueryInstrument</value></property>
    		<property name="validator"><ref bean="QueryInstrumentValidator"/></property>
    	</bean>
    How can I send it to a method in the controller instead of a jsp page?

  • #2
    referenceData is always called.

    What would the map contain?

    Comment


    • #3
      I want to pass to the page declared in the FormView property some object in a HashMap like this method in the controller:
      Code:
       public ModelAndView searchInstrumentHandler&#40;HttpServletRequest request, HttpServletResponse response&#41;
          throws ServletException, IOException&#123;
          	Map map = new HashMap&#40;&#41;;
          	map.putAll&#40;elab.getInstrumentsUse&#40;&#41;&#41;;
          	map.putAll&#40;elab.getConcern&#40;&#41;&#41;;
          	map.putAll&#40;elab.getMenuSecondLevel&#40;request.getQueryString&#40;&#41;&#41;&#41;;
              return new ModelAndView&#40;"researchInstrView", "out",map&#41;;
          &#125;
      How can I pass this map to the jsp page where I go after an unsuccesfull validation?

      Comment


      • #4
        Just overload referenceData. The map that is returned from referenceData is included in the model that is passed to the view.

        Also, beaware that
        Code:
        return new ModelAndView&#40;"researchInstrView", "out",map&#41;;
        will result in a model which contains a map under the name "out". This is fine, but you will need to call "${out.whatever}" in your jsp. If you want to add all the elements in your map to the model, then do

        Code:
          return new ModelAndView&#40;viewName&#41;.addAll&#40;map&#41;;

        Comment


        • #5
          I added this code to my validate method to pass the map:
          Code:
          	    protected Map referenceData&#40;HttpServletRequest request&#41;
          	      throws Exception &#123;
          	    	Map out = new HashMap&#40;&#41;; 
          	        out.putAll&#40;elab.getInstrumentsUse&#40;&#41;&#41;; 
          	        out.putAll&#40;elab.getConcern&#40;&#41;&#41;; 
          	        out.putAll&#40;elab.getMenuSecondLevel&#40;request.getQueryString&#40;&#41;&#41;&#41;;
          	    return out;
          	  &#125;
          But now I can't get this map in my FormView,
          I tried with out.listInstrumentsUse.

          Comment


          • #6
            You don't need to dereference it with "out", based on your code, I presume "elab.getInstrumentsUse()" returns a map, assuming that map contains a key "someKey" with a corresponding value of "someValue" then in your jsp you would simply do

            Code:
              My value = $&#123;someKey&#125;
            and it would render to

            Code:
              My value = someValue

            Comment


            • #7
              I called the map out because I reuse the jsp where I pass the map, and I want to pass the same map to it.

              I'll try to be more clear: I have a link in the mený that send me to a method in the controller and then in the jsp page of research.
              In the controller I put the map that I'll pass to the page, the code is this:
              Code:
              public ModelAndView searchInstrumentHandler&#40;HttpServletRequest request, HttpServletResponse response&#41; 
                  throws ServletException, IOException&#123; 
                     Map map = new HashMap&#40;&#41;; 
                     map.putAll&#40;elab.getInstrumentsUse&#40;&#41;&#41;; 
                     map.putAll&#40;elab.getConcern&#40;&#41;&#41;; 
                     map.putAll&#40;elab.getMenuSecondLevel&#40;request.getQueryString&#40;&#41;&#41;&#41;; 
                      return new ModelAndView&#40;"researchInstrView", "out",map&#41;; 
                  &#125;
              In the jsp page I'll access to the fiel in the map with out.FIELD.

              NOW I made a validation on a data in this page, but when the validation fail I'll return to this page, but I want my map again.

              I tried to overload referenceData in the validator:
              Code:
              	    protected Map referenceData&#40;HttpServletRequest request&#41;
              	      throws Exception &#123;
              	    	Map out = new HashMap&#40;&#41;; 
              	        out.putAll&#40;elab.getInstrumentsUse&#40;&#41;&#41;; 
              	        out.putAll&#40;elab.getConcern&#40;&#41;&#41;; 
              	        out.putAll&#40;elab.getMenuSecondLevel&#40;request.getQueryString&#40;&#41;&#41;&#41;;
              	    return out; 
                  &#125;
              But it didn't work....

              I hope I'm clear... :oops:

              Anyone could help?

              Comment


              • #8
                Right, in your jsp, add the following:

                Code:
                Map = $&#123;out&#125;
                and see what that does.

                Comment


                • #9
                  I have the same problem, when I return to the research page I'm without the map with mený and other list! :x

                  The method that fill the map is searchInstrumentHandler which code is in the mail before.

                  I override the reference data in the validator:
                  Code:
                  	    protected Map referenceData&#40;HttpServletRequest request&#41;
                  	      throws Exception &#123;
                  	    	Map out = new HashMap&#40;&#41;; 
                  	        out.putAll&#40;elab.getInstrumentsUse&#40;&#41;&#41;; 
                  	        out.putAll&#40;elab.getConcern&#40;&#41;&#41;; 
                  	        out.putAll&#40;elab.getMenuSecondLevel&#40;request.getQueryString&#40;&#41;&#41;&#41;;
                  	        out.put&#40;"test","prova"&#41;;
                  	    return out;
                  	  &#125;
                  and in the jsp page I try to catch this map with:
                  Code:
                  <input type="text" name="out.instr.model" value="<c&#58;out value="$&#123;out.test&#125;"/>" size="50">
                  or this:
                  Code:
                  							<option value=""><c&#58;out value="$&#123;use.use&#125;"/></option>
                  							<c&#58;forEach var="use" items="$&#123;out.listInstrumentsUse&#125;">
                  							<option value="<c&#58;out value="$&#123;use.use&#125;"/>"><c&#58;out value="$&#123;use.use&#125;"/></option>
                  							</c&#58;forEach>
                  For example this last fragment of code works for the data passed from searchInstrumentHandler.

                  I want to pass the same map of searchInstrumentHandler to the jsp.

                  Comment


                  • #10
                    I'm really confused

                    Post your servlet.xml and your controller, and the two jsps in question.

                    Comment


                    • #11
                      Code:
                      protected Map referenceData&#40;HttpServletRequest request&#41; throws Exception &#123;
                                 final Map out = new HashMap&#40;&#41;;
                                 out.putAll&#40;elab.getInstrumentsUse&#40;&#41;&#41;;
                                 out.putAll&#40;elab.getConcern&#40;&#41;&#41;;
                                 out.putAll&#40;elab.getMenuSecondLevel&#40;request.getQueryString&#40;&#41;&#41;&#41;;
                                 out.put&#40;"test","prova"&#41;;
                                 
                                 final Map referenceData = new HashMap&#40;&#41;;
                                 referenceData.put&#40;"out", out&#41;;
                      
                                 return referenceData;
                      &#125;

                      Comment

                      Working...
                      X