Announcement Announcement Module
Collapse
No announcement yet.
#springShowErrors velocity does not work !!! Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • nidhin
    started a topic #springShowErrors velocity does not work !!!

    #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")

  • roberto.bouza
    replied
    Fixed.

    I fixed it. Thanks for your help.

    It is as simple as you need to bind to the item on the form to display the error with #springBind or you just put the springShowErrors close the item and it gets display when the view is being processed.

    An example:

    Code:
    <html>
      <head>
      	<title>#springMessage("category.add")</title>
      	<style>
        	.error { color: red; }
      	</style>
      </head>
      <body>
        <h1>#springMessage("category.add")</h1>
        <form method="POST">
        	#springFormHiddenInput("categoryModel.id")
    		Name: #springFormInput("categoryModel.name") - #springShowErrors("<br>" "error")<br/>
    		Key: #springFormInput("categoryModel.key") <br/>
    		Description: #springFormTextarea("categoryModel.description") <br/>
    		
    	    <input type="submit" value="submit"/>
    	    <input type="button" value="Cancel" onclick="document.location='#springUrl('/categories/list')';"/>
        </form>
        <br>
      </body>
    </html>

    Leave a comment:


  • gnandiga
    replied
    I think i had a configuration error. Once the configuration error was resolved, i got to see the errors in a normal manner.

    roberto.bouza: can you post your code, to see if there is a problem.

    Thanks

    Leave a comment:


  • roberto.bouza
    replied
    Gnandiga,

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

    Thank you.

    Leave a comment:


  • roberto.bouza
    replied
    Nidhin

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

    Leave a comment:


  • gnandiga
    replied
    Was this resolved

    Hello nidhin,

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

    Leave a comment:


  • nidhin
    replied
    thanks
    for your help

    Leave a comment:


  • gehel
    replied
    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

    Leave a comment:


  • nidhin
    replied
    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, 05:33 AM.

    Leave a comment:


  • gehel
    replied
    We need still more informations !

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

    Leave a comment:


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

    Leave a comment:


  • gehel
    replied
    You will need to tell us a bit more ...

    How doesnt it work ? What error do you have ?

    Leave a comment:

Working...
X