Announcement Announcement Module
Collapse
No announcement yet.
Am I going crazy? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Am I going crazy?

    I'm sorry for this stupid question, but I think I'm going nuts. I'm using spring 1.2.8. The API for AbstractWizardFormController claims that there is a postProcessPage method.

    However, eclipse doesn't seem to think so (it doesn't show up when I ask to override/implement a method, for example), and when I run the application, it never gets called. Am I going crazy?

    Here's how I define postProcessPage:
    Code:
    protected void postProcessPage(HttpServletRequest request,
                Object command,
                Errors errors,
                int page){
    		logger.info("in postProcessPage");
    
    ...
    }
    I double checked that the API was for 1.2.x, so that's not it. I guess if nobody corrects my (probably very stupid) oversight, I'll try 2.0, but I'd rather stick with the stable version.

    Anyway, thanks.
    Dave

  • #2
    If you've upgraded Spring recently, check your Eclipse is using the 1.2.8 version.

    Comment


    • #3
      Originally posted by katentim
      If you've upgraded Spring recently, check your Eclipse is using the 1.2.8 version.
      Naw, I recently reinstalled my OS, so everything is a clean install. I never used anything but 1.2.8.

      And yet... eclipse insists that method doesn't exist, and my log file indicates that it never runs.

      Again, I'm sure it's something simple, but I can't figure it out...

      Dave

      Comment


      • #4
        Are you sure you have imported the correct objects? Have you imported the correct Errors, HttpServletRequest etc.

        If you are using JDK1.5 you can use an @Override annotation which should give a compilation error.

        Comment


        • #5
          Originally posted by yatesco
          Are you sure you have imported the correct objects? Have you imported the correct Errors, HttpServletRequest etc.

          If you are using JDK1.5 you can use an @Override annotation which should give a compilation error.
          Not using JDK1.5. Don't have a choice, unfortunately.

          Here's the whole she-bang:

          Code:
          package org.gibby.tammystamales.web;
          
          import java.util.HashMap;
          import java.util.Iterator;
          import java.util.List;
          import java.util.Map;
          
          import javax.servlet.http.HttpServletRequest;
          import javax.servlet.http.HttpServletResponse;
          
          import org.apache.commons.logging.Log;
          import org.apache.commons.logging.LogFactory;
          import org.gibby.tammystamales.bus.MenuItem;
          import org.gibby.tammystamales.bus.Order;
          import org.gibby.tammystamales.bus.OrderManager;
          import org.springframework.validation.BindException;
          import org.springframework.validation.Errors;
          import org.springframework.web.servlet.ModelAndView;
          import org.springframework.web.servlet.mvc.AbstractWizardFormController;
          import org.springframework.web.servlet.view.RedirectView;
          
          public class MenuController extends AbstractWizardFormController {
          	
          	OrderManager om;
          	protected final Log logger = LogFactory.getLog(getClass());
          
          	public MenuController(){
          		setPages(new String[] { "menu", "menu_edit", "payment" });
                  setCommandName("items");
          	}
          	public OrderManager getOrderManager() {
          		return om;
          	}
          
          	public void setOrderManager(OrderManager om) {
          		this.om = om;
          	}
          	protected void validatePage(Object command, Errors errors, int pageNum) {
          		logger.info("validating page "+pageNum);
          		// TODO Auto-generated method stub
          		
          	}
          	protected ModelAndView processFinish(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception {
          		//TODO: Add a call to OrderManager.saveOrder
          		return new ModelAndView("thankyou");
          	}
          	
          	protected ModelAndView processCancel(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception {
          		return new ModelAndView(new RedirectView("frontpage.htm"));
          	}
          	
          	protected Object formBackingObject(HttpServletRequest request) throws Exception {
          		Order order = new Order();
          		order.setMenuItems(om.getMenuItems());
          		for(Iterator i=order.getMenuItems().iterator();i.hasNext();){
          			MenuItem item = (MenuItem)i.next();
          			order.getOrderedItemMap().put(new Integer(item.getId()).toString(), "0");
          		}
          		return order;
          	}
          
          	protected void postProcessPage(HttpServletRequest request,
                      Object command,
                      Errors errors,
                      int page){
          		logger.info("in postProcessPage");
          		Order order = (Order)command;
          		Map map = order.getOrderedItemMap();
          		for(Iterator i = map.keySet().iterator();i.hasNext();){
          			String id = (String)i.next();
          			Integer num = (Integer)order.getOrderedItemMap().get(id);
          			
          			for (int j=0;j<num.intValue();j++)
          				order.addOrderedItem(om.newOrderedItemById(Integer.parseInt(id)));
          			
          		}
          	}
          }
          Did I do something stupid? I hope so, so I can get on with my project :o

          Thanks for your help

          Dave

          Comment


          • #6
            No idea then. You do know it is not displayed when cancelling/finishing. Not sure if it is called when there are validation errors either....

            It is weird that Eclipse is claiming not to know about it....

            Comment


            • #7
              Originally posted by yatesco
              No idea then. You do know it is not displayed when cancelling/finishing. Not sure if it is called when there are validation errors either....

              It is weird that Eclipse is claiming not to know about it....

              Yeah, eclipse not knowing about it was my first clue that it just wasn't being recognised. Both the override/implement utility and the package explorer don't list that method.

              Frustrating.

              How polished is the 2.0 version?

              Dave

              Comment


              • #8
                Well, I swapped the spring.jar from spring-1.2.8-with-dependancies with the spring.jar in spring-1.2.8, and now it seems to work.

                I don't understand, but I'm not going to think about it too hard or else it might suddenly stop working again.



                Dave

                Comment


                • #9
                  Both the override/implement utility and the package explorer don't list that method
                  I tried it and it worked OK for me.

                  Well, I swapped the spring.jar from spring-1.2.8-with-dependancies with the spring.jar in spring-1.2.8, and now it seems to work.
                  Maybe the file was corrupted (treated as CVS text file?) - I checked the CRC32 from both releases and it is 5643 CCD3 in both.

                  Comment


                  • #10
                    if you have myeclipse installed, that comes with spring 1.2 libraries, that could have something to do with it.

                    Comment


                    • #11
                      I had a similar problem, but I fixed it -- Errors vs BindException

                      I was having a similar problem, not so much to do with Eclipse not recognizing the methods, but they were never invoked when my wizard was being used.

                      After I had given up and reworked my code to just use the onBind() method, and checking the result of getCurrentPage() to figure out which page I was on, I re-checked the JavaDoc API for AbstractWizardFormController.

                      The problem was that I had defined my validatePage() and postProcessPage() methods using a parameter of type BindException, instead of a parameter of type Errors. I used a call to super.validatePage() and super.PostProcessPage() to verify that I had the right method signatures that I was overriding, but this poor man's trick did not catch the problem because BindException implements Errors.

                      Once I used an argument of type Errors, voila, my methods were getting invoked. Although I decided not to undo the workaround I had done earlier, so I'm not actually using those methods, which is a pity because they are exactly what I had wanted to do.

                      Comment


                      • #12
                        I had a similar problem -- BindException vs Errors

                        Well I just wrote a lengthy post about this but I guess I took too long to write it, because when I hit Sumbit Reply it asked me to log in again, and then of course my posting was lost. This was a bummer. [Actually it was not lost, but I thought it was. Just goes to show, I am an idiot.]

                        So this time I will cut to the chase. I too was confused about why validatePage() and postProcessPage() were not being invoked, until I triple-checked the API and saw that the parameter called "errors" is supposed to be of type Errors, not of type BindException as I had written my methods.

                        Once I changed the type of my parameter, the methods were invoked. Such a simple thing, and yet so frustrating when I could not get it to work.

                        When overriding a method foo(), I often call super.foo() with the same arguments, both so that I don't miss out on any desired behavior in the superclass and so that I can verify that I am in fact overriding a method. (I haven't learned much about the @Override attribute in java 1.5. If it's similar to the overrides keyword in .NET, then it will be a good thing, and would have saved me some time here.) But this trick did not help me out in this case, because BindException implements Errors, so my call to super.validatePage() went through fine.

                        Comment

                        Working...
                        X