Announcement Announcement Module
Collapse
No announcement yet.
message if login fails Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • message if login fails

    I'm new to Spring and Im playing around with an example similar to jpetstore.

    I have a LoginFormController ( extends SimpleFormController) which evaluates the user login data and returns a RedirectView on the FormView if the login fails otherwise the SuccessView.

    Code:
    return new ModelAndView(new RedirectView(getFormView()), "messageLogin", "login failed");
    In my jsp page I want to display the error message:
    Code:
    <c&#58;out value="$&#123;messageLogin&#125;"/>
    This way doesn't work. No message is displayed for messageLogin

    What is the best way to do something like this?

  • #2
    try this

    Code:
            pErrors.rejectValue&#40;"userName", "login failed", null, "login failed"&#41;;
             return showForm&#40;pRequest, pResponse, pErrors&#41;;

    Comment


    • #3
      If you want the message to not be tied to a field then do followings.

      Code:
      pErrors.reject&#40;"loginFailure","Login failed"&#41;;
      In your resource bundle add a field for login failure.
      Code:
      loginFailure=Login failed!!
      In your jsp make the necessary changes.
      Code:
      <spring&#58;bind path="command">
        <FONT color="red">
          <B><c&#58;out value="$&#123;status.errorMessage&#125;"/></B>
        </FONT>
      </spring&#58;bind>

      Comment


      • #4
        Normally you would do it like you do, e.g. push your message in the request. However, since you are using a redirect view, those parameters are added to the request uri (I think, I dont use redirect view). So you can either store it in the session and retrieve it the way you did or use the way to get it from the parameters e.g
        <c:out value="${param.loginFailure}"/>

        Hope this helps

        Gr
        Ronald

        Comment


        • #5
          Hi,
          I'm having the same problem you're discussing.
          Could you please tell me how could this problem be solved using session.
          Thanks in Advance.
          Sherihan.

          Comment


          • #6
            Originally posted by sherihan
            Hi,
            I'm having the same problem you're discussing.
            Could you please tell me how could this problem be solved using session.
            Thanks in Advance.
            Sherihan.
            Hi!

            I did it this way:

            My SimpleFormController returns following

            Code:
            return new ModelAndView&#40;new RedirectView&#40;getFormView&#40;&#41;&#41;, "messageLogin",  getMessageSourceAccessor&#40;&#41;.getMessage&#40;"login.datanotok"&#41;&#41;;
            my jsp page corresponding to the FormView displays the message:

            <tr>
            <td></td>
            <TD><span class="fieldError"><c:out value="${param.messageLogin}"/> </span> </TD>
            </tr>

            Comment

            Working...
            X