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

  • Validator problem.

    hello! I do a validator for my class login..
    the problem is not know use the validators,
    I have to make sure that the user and pass are the same values, otherwise I should give an error message.
    package springapp.web;

    import org.springframework.web.servlet.mvc.SimpleFormCont roller;
    import org.springframework.web.servlet.mvc.Controller;
    import org.springframework.web.servlet.ModelAndView;
    import org.springframework.web.servlet.view.RedirectView;

    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;

    import springapp.service.PersonaManager;
    import springapp.domain.Login;
    import springapp.domain.Persona;
    import springapp.domain.Prodotto;
    import springapp.schede.User;
    import springapp.service.ProdottoManager;
    import springapp.service.ShoppingCart;

    import java.io.IOException;
    import java.util.Date;
    import java.util.List;
    import java.util.Map;
    import java.util.HashMap;


    public class LoginController extends SimpleFormController{

    private PersonaManager personaManager;
    private List<Persona> persone;
    private Persona persona;



    public LoginController() {
    }





    public ModelAndView onSubmit(Object command)
    throws ServletException {

    Login login = (Login) command;
    String username_tmp = login.getUsername();
    String password_tmp = login.getPassword();
    persone = this.personaManager.getPersone();
    persona = new Persona();

    Map<String, Login> model = new HashMap<String, Login>();

    model.put(getCommandName(), login);
    int c=0;
    int i = persone.size();
    for (int j = 0; j<i; j++)
    {
    persona=persone.get(j);
    persona.setAbilitato(false);
    persone.get(j).setId("null");

    if (username_tmp.equals(persona.getUsername()) && (password_tmp.equals(persona.getPassword())))
    {
    c=j+1;
    persone.get(j).setAbilitato(true);
    persone.get(j).setId(String.valueOf(c));

    return new ModelAndView(new RedirectView(getSuccessView()));
    }



    }

    return new ModelAndView(new RedirectView("home_page.htm"));
    }



    protected Object formBackingObject(HttpServletRequest request) throws ServletException {
    Login login = new Login();


    return login;
    }


    public void setPersonaManager(PersonaManager personaManager) {
    this.personaManager = personaManager;
    }

    public PersonaManager getPersonaManager()
    {
    return personaManager;
    }

    }





  • #2
    you must write something like LoginControllerValidator class which implements Validator.
    make all your validations there.

    Comment

    Working...
    X