How to display the back-end error message in the foreground page using spring Webflow

Source: Internet
Author: User
Tags call back cas ticket

Just contact with spring Webflow, the relevant information is not many, and most of the kind of introduction of the. xml file configuration.

The latest 4.0 version of CAs used is the Web-flow stream, and the front page uses a form submission. So I ran into a problem, and the problem was described as follows:

The first time you enter the wrong user name password prompt user name password error, the second time entered the correct user name and password still error, check does not pass.

Login page before using CAS if you enter the user name and password incorrectly, the alert prompt will pop up, which is implemented using AJAX requests. Ajax requests are typically the kind of spring MVC controller that can be asynchronously returned based on the return value. But the source of the CAs used is the form submission, form submission is not asynchronous, so unless the IFRAME, otherwise can not callback function to refresh the page. There are many changes after the IFrame is added, and the subsequent workload is not evaluated. (Why do I have to call back, because there is not only user name and password input box in the CAS page form, there is a nasty hidden element: Loginticket and Flowexecutionkey,cas process each request requires a re-generation of a Loginticket ticket).

Thinking of several solutions, just beginning to webflow and MVC integration, two ways:

1. Modify the Externalredirect in the end-state tag in login-webflow.xml to one of my controller and take the error message in the parameter, the controller returns an object to the front end (usually code:-1; Msg: "";d the form of a JSON string such as ate:****). Then the front-end Ajax Call Login This webflow, will redirect to my definition of this controller, and get the controller's return value for callback.

<end-state id= "redirectview" view= "externalredirect:http://user/res?code=-1& msg= "Error" " />

However, there is a problem, after pop-up alert box Click OK, the alert box disappears, and then re-enter the correct user name and password, will still error, because the Loginticket verification failed. About the Loginticket check, you can see from the source of the CAS:

authenticationviaformaction: Public FinalEvent Submit (FinalRequestContext context,Finalcredential credential,FinalMessagecontext Messagecontext)throwsException {//Validate Login Ticket        FinalString Authoritativeloginticket =Webutils.getloginticketfromflowscope (context); FinalString Providedloginticket =webutils.getloginticketfromrequest (context); if(!authoritativeloginticket.equals (Providedloginticket)) {Logger.warn ("Invalid login Ticket {}", Providedloginticket); Messagecontext.addmessage (NewMessagebuilder (). Code ("Error.invalid.loginticket")). Build ()); returnnewevent (ERROR); } ...

is to take the LT in the flow stream and compare it to the ticket in the request. However, the notes in the form are not updated to the latest, and the error message returned after my webflow is over, which naturally does not get the notes generated in the Webflow.

Let's leave this question aside and say the second way to integrate MVC:

Add Output,output in the end-state tag to output a pair of images;

The third kind: Inherit the Abstractflowhandler method,

 Public class extends Abstractflowhandler {    public  String handleexecutionoutcome (flowexecutionoutcome outcome, HttpServletRequest request,            httpservletresponse response) {        if (Outcome.getid (). Equals (" Redirectview ")) {            return "/user/loginres?code= "+ outcome.getoutput (). Get (" Bookingid " );         Else {            return "/hotels/index";}}    }

But none of this solves my problem. Because it's always wrong to get it out of that Webflow container.

So how do you return the error message to the foreground page in the Login-webflow this closed loop?

Find a way: http://docs.spring.io/spring-webflow/docs/2.3.x/reference/htmlsingle/#end-state-element

Use a ViewState to display the popup dialog box:

<view-state id= "Changesearchcriteria" view= "entersearchcriteria.xhtml" popup= "true" >

But this viewstate will have to redirect to Login's viewstate after adding this.

Finally I used the scheme:

To modify login ViewState:

    <view-state id= "Viewloginform" view= "/platform/login" model= "credential" >        <binder>            < Binding property= "username"/>            <binding property= "password"/>        </binder>        <on-entry >            <set name= "requestscope.messages" value= "messagecontext.allmessages"/><set name=            " Viewscope.commandname "value=" ' Credential ' "/>        </on-entry>        <transition on=" Submit "  bind = "true" validate= "true" to= "Realsubmit" >            <evaluate                expression= " Authenticationviaformaction.dobind (Flowrequestcontext, flowscope.credential) "/>        </transition>    </view-state>

Add the Green Line, this view in the render to the Velocity page, the requestscope in the messages to put in, the front control, if the messages is empty, do not show, if not empty, show it.

<style= "float:left; display:inline-block; font-size:12px; color:red; text-decoration : none; margin:5px 0; " >                                     #foreach (${message} in ${messages})                                    #if (${message.text} = = "Invalid credentials.")                                        User name, password or CAPTCHA error!                                    #end                                    #end                                    </label>

done!

So look at the effect:

Entering the correct username and password will not report the error of the Loginticket verification failure and can successfully log in to the system.

Insufficient is, in fact obviously see the page refresh a bit.

How to display the back-end error message in the foreground page using spring Webflow

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.