Announcement Announcement Module
Collapse
No announcement yet.
using refData in WizardFormController Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • using refData in WizardFormController

    Hi all,

    I'm trying to write a form that in first page user have to select his/her country and then cities that belong to that country should come in second page at last user will enter the address.

    How can i use selected country on second page and fill in referenceMap.
    The code is below
    Best Regards.

    Code:
    	
    	protected Map referenceData(HttpServletRequest request, int page) throws Exception {
    	    if (page == 0) {
    			Map countryMap = new HashMap();
    			countryMap.put("countries", countryService.findAllCountries());
    			return countryMap;
    	    }
    	    if (page == 1) {
    	        Country country = (Country) request.getSession().getAttribute("country"); //this is the place where i've been stucked
    	        Map cityMap = new HashMap();
    	        cityMap.put("cities", cityService.findCityByCountry(country));
    	        return cityMap;
    	    }
    }

  • #2
    I think the main problem is address only knows city not his/her country. In my model class address has city but not country. Is there any way to retrieve city by selecting country and put it into model. Cuz if i add another variable as country it seems working but i don't want to add it.

    Cheers
    HaLLoWeD

    Comment


    • #3
      Just use the method that gives you the command:

      referenceData(HttpServletRequest request, Object command, Errors errors, int page)

      Then put a country field in your command object and read that back in your referenceData method.

      Looks like the perfect candidate for useing an xmlHttpRequest object to me, though. You should evaluate that option also. That's what I just did recently for a State/City chooser.

      Comment


      • #4
        Hi wiggles,

        Where should i set the command object ? Or please could you post your codes about formController, servlet and jsp related rows with this issue.
        Cheers

        Code:
           protected Map referenceData(HttpServletRequest request, Object command, Errors errors, int page) throws Exception { 
               if (page == 0) { 
                 Map countryMap = new HashMap(); 
                 countryMap.put("countries", countryService.findAllCountries()); 
                 return countryMap; 
               } 
               if (page == 1) { 
                   Country country = (Country) command;
                   Map cityMap = new HashMap(); 
                   cityMap.put("cities", cityService.findCityByCountry(country)); 
                   return cityMap; 
               } 
        }

        Comment


        • #5
          Well, I can't post the code that I wrote because it's not mine, but I'm glad to help. You set the command object using:

          setCommandClass(Class commandClass)

          and set it's name by using

          setCommandName(String commandName)

          This is usually done in your servlet context xml:

          Code:
          <bean id="controller" class="com.website.MyController">
              <property name="commandName"><value>bean</value></property>
              <property name="commandClass"><value>com.website.MyBean</value></property>
          </bean>
          You'll want to take a look at the reference docs. This is all very well documented.

          Comment

          Working...
          X