Announcement Announcement Module
Collapse
No announcement yet.
Binding Date Attribute Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Binding Date Attribute

    Hi all!
    i have the following problem:
    in my jsp i have one date field that i need to make whriteble, here is what i have written:
    Code:
    <tr>
     <td colspan="2">RP Date</td>
     <td>
      <Spring:bind path="fxRate.fr_rpd_rp_date">
       <input type="text" name="fr_rpd_rp_date" size="10" value="${status.value}"/>
      </Spring:bind>
     </td>
     <td>
      <input type="button" value="Calendar" onclick="displayCalendar(fr_rpd_rp_date, 'yyyy-mm-dd',this)">
     </td>
    </tr>
    ....
    ....
    ....
    <tr>
     <td colspan="4">
      <input type="submit" name="add" value="+ Add +"/>
     </td>
    </tr>
    With this displayCalendar i can change this pre-defined field to yyyy-mm-dd too, but it seems that then the date in the form is not modified, and even onSubmit code from my controlles is not called:

    Code:
    public class FxRateFormController extends SimpleFormController {
    
        protected final Log logger = LogFactory.getLog(getClass());
        private FxRateService fxRateS;
        private FxRateTypeService fxRateTypeS;
    
        public FxRateService getFxRateS() {
            return fxRateS;
        }
        public void setFxRateS(FxRateService fxRateS) {
            this.fxRateS = fxRateS;
        }
        
        public FxRateTypeService getFxRateTypeS() {
          return fxRateTypeS;
    	  }
    	  public void setFxRateTypeS(FxRateTypeService fxRateTypeS) {
    	      this.fxRateTypeS = fxRateTypeS;
    	  }
    
        public ModelAndView onSubmit(HttpServletRequest request,
                                     HttpServletResponse response, Object cmd,
                                     BindException errors) throws Exception {
        	
        	FxRate fxRate = (FxRate) cmd;
          
          if (null != request.getParameter("delete")) {
              fxRateS.removeFxRate(fxRate);
              return this.getHomeFxRateTypePage(cmd);
              
          } else if (null != request.getParameter("update")) {
          	fxRate.setFr_user_modified(((UserWeb)request.getSession().
          			getAttribute(UserWeb.KEY)).getName());
          	fxRate.setFr_date_modified(new Date(new java.util.Date().getTime()));
          	fxRateS.updateFxRate(fxRate);
          	return this.getHomeFxRateTypePage(cmd);
          	
          } else if (null != request.getParameter("add")) {
          	xRate.setFr_date_created(new Date(new java.util.Date().getTime()));
          	fxRate.setFr_user_created(((UserWeb)request.getSession().
          			getAttribute(UserWeb.KEY)).getName());
          	fxRate.setFr_date_modified(null);
          	fxRate.setFr_user_modified(null);
          	fxRateS.insertFxRate(fxRate);
          	return this.getHomeFxRateTypePage(cmd);
          }
          return new ModelAndView(new RedirectView(getSuccessView()));
        }
        
    	protected ModelAndView getHomeFxRateTypePage(Object cmd){
    	    List data = new ArrayList();
    	    FxRateType type = new FxRateType();	    
    	    FxRate fxRate = (FxRate) cmd;
    	    
    	    int id = fxRate.getFr_frt_id().intValue();
      		type = fxRateTypeS.findFxRateTypeById(id);
    	  	data.add(0, type);
    	  	data.addAll(1, fxRateS.findFxRatesByFxRateTypeId(id));
    	    return new ModelAndView("fxRate/FxRates", "data", data);
        }
    
          protected Object formBackingObject(HttpServletRequest request) throws
                ServletException {
    
    	request.setAttribute("orderedBy","date_created");
        	
        	String id = request.getParameter("fr_id");    	
        	if (null != id && !id.equals("")) {
        		FxRate answer = fxRateS.findFxRateById(Integer.parseInt(id));
        		return answer;
        	}
        	
        	String frt_id = request.getParameter("frt_id");
        	if (null != frt_id && !frt_id.equals("")) {
        		FxRate answer = new FxRate();
        		answer.setFr_frt_id(Integer.parseInt(frt_id));
        		answer.setFr_rpd_rp_date(fxRateS.getLastReportDay());
        		return answer;
        	} 
        	return new FxRate();
        }
    		
    	protected Map referenceData(HttpServletRequest request) throws Exception {
    		String fr_id = request.getParameter("fr_id");
    		String frt_id = request.getParameter("frt_id");
    	
        	if ( (null != fr_id && !fr_id.equals("")) || (null != frt_id && !frt_id.equals("")) ) {
        		Map<String, List> reference = new HashMap<String, List>();				reference.put("types", fxRateTypeS.getAllFxRateTypes());
    	  	return reference;
        	}
        	else return null;
    }
    i would very apprishiate any help!

  • #2
    Resuming: i am sure that the onSubmit is not called because spring do not undersand my code, failing somewhere on validation... how can i bind one text field with Date date?
    thks

    Comment

    Working...
    X