Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: #springShowErrors velocity does not work !!!

  1. #1
    Join Date
    Dec 2007
    Location
    Kerala, India
    Posts
    66

    Unhappy #springShowErrors velocity does not work !!!

    public void validate(Object object, Errors errors) {

    LoginBean login = (LoginBean) object;
    if(login.getName().equals("test"))
    errors.rejectValue("name","error.nottest");



    }


    and i want to show errors in velocity temple using macro #springShowErrors("<br>" "error")

  2. #2
    Join Date
    Jul 2005
    Location
    Geneva (Switzerland)
    Posts
    304

    Default

    You will need to tell us a bit more ...

    How doesnt it work ? What error do you have ?

  3. #3
    Join Date
    Dec 2007
    Location
    Kerala, India
    Posts
    66

    Default

    The template page is showing with no my error messages
    and i added it to propperties file
    error.nottest=required

  4. #4
    Join Date
    Jul 2005
    Location
    Geneva (Switzerland)
    Posts
    304

    Default

    We need still more informations !

    How do you call the validator ? Could you post the code of your controller ?

  5. #5
    Join Date
    Dec 2007
    Location
    Kerala, India
    Posts
    66

    Default

    Code:
    @Controller
    public class LoginController extends SimpleFormController{
        
        private final ImageDatabase imageDatabase;
        
        
        @Autowired
        /** Creates a new instance of LoginController */
        public LoginController(ImageDatabase imageDatabase) {
            
            this.imageDatabase=imageDatabase;
        }
        
         public ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors)
        throws ServletException {
             LoginBean login = (LoginBean) command;
             String name = login.getName();
             String password =login.getPassword();
             
                 List<UserDescriptor> user = this.imageDatabase.isValidUser(name,password);
            if( !user.isEmpty()) {
               .
               .
               .
               .
                         
          return   loginModel;
              }
          
           return new ModelAndView("/login");
         }
    And My configration
    PHP Code:
    <bean id="loginController" name="/login" class="org.springframework.samples.imagedb.web.LoginController">
                 <
    property name="sessionForm" value="true"/> 
                <
    property name="commandName" value="loginValidator"/>
                <
    property name="commandClass" value="org.springframework.samples.imagedb.web.LoginBean"/>
                <
    property name="validator"><bean class="org.springframework.samples.imagedb.web.LoginValidator"/></property
                <
    property name="formView" value="login"/>
       
            </
    bean
    Last edited by nidhin; Jan 18th, 2008 at 04:33 AM.

  6. #6
    Join Date
    Jul 2005
    Location
    Geneva (Switzerland)
    Posts
    304

    Default

    I'm not an expert on SpringMVC, so no definitive answer from me, but a couple of pointers :

    • You could try to follow the Spring Step by Step tutorail (http://www.springframework.org/docs/...ep-Part-3.html).
    • I dont think the use of the @Controller annotations is usefull, as it seems that you declare the bean explicitly anyway (though you might find that using those annotations makes the intent of the class more clear to the reader).
    • If you just want to redirect to the success view, you should override the method "void doSubmitAction(Object command)" instead of "onSubmit(...)".
    • Could you put some logging code in your Validator to check if it is called at all ?
    • Could you send us the velocity template of the "login" view ?


    And please, could you use [code] as described in http://forum.springframework.org/mis...do=bbcode#code

  7. #7
    Join Date
    Dec 2007
    Location
    Kerala, India
    Posts
    66

    Default

    thanks
    for your help

  8. #8
    Join Date
    Oct 2006
    Posts
    100

    Default Was this resolved

    Hello nidhin,

    were you able to resolve this problem, if yes how?

  9. #9

    Default

    Nidhin

    How did u solve this? I'm still having the same issue.

  10. #10

    Default

    Gnandiga,

    If you also have a solution culd you please let me know.

    Thank you.

Posting Permissions

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