KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > turbine > modules > screens > error > InvalidState


1 package org.apache.turbine.modules.screens.error;
2
3 /*
4  * Copyright 2001-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License")
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import org.apache.ecs.ConcreteElement;
20 import org.apache.ecs.ElementContainer;
21
22 import org.apache.ecs.html.A;
23
24 import org.apache.turbine.modules.Screen;
25 import org.apache.turbine.util.RunData;
26 import org.apache.turbine.util.parser.ParameterParser;
27 import org.apache.turbine.util.uri.TurbineURI;
28
29 /**
30  * Users will get this screen if the screen on their browser is in an
31  * invalid state. For example, if they hit "Back" or "Reload" and
32  * then try to submit old form data.
33  *
34  * If you want one of your screens to check for invalid state
35  * then add a hidden form field called "_session_access_counter"
36  * with the value currently stored in the session. The
37  * SessionValidator action will check to see if it is an old
38  * value and redirect you to this screen.
39  *
40  * @author <a HREF="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
41  * @author <a HREF="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
42  * @version $Id: InvalidState.java,v 1.7.2.2 2004/05/20 03:03:54 seade Exp $
43  */

44 public class InvalidState
45     extends Screen
46 {
47     /**
48      * Build the Screen.
49      *
50      * @param data Turbine information.
51      * @exception Exception, a generic exception.
52      */

53     public ConcreteElement doBuild(RunData data)
54             throws Exception JavaDoc
55     {
56         ElementContainer body = new ElementContainer();
57         ElementContainer message = new ElementContainer();
58
59         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
60         sb.append("<b>There has been an error.</b>")
61                 .append("<p>")
62                 .append("- If you used the browser \"Back\" or \"Reload\"")
63                 .append(" buttons please use the navigation buttons we provide")
64                 .append(" within the screen.")
65                 .append("<p>")
66                 .append("Please click ");
67
68         message.addElement(sb.toString());
69         ParameterParser pp;
70         pp = (ParameterParser) data.getUser().getTemp("prev_parameters");
71         pp.remove("_session_access_counter");
72
73         TurbineURI back = new TurbineURI(data,(String JavaDoc) data.getUser().getTemp("prev_screen"));
74         back.addPathInfo(pp);
75         message.addElement(new A().setHref(back.getRelativeLink()).addElement("here"));
76
77         message.addElement(" to return the the screen you were working on.");
78
79         body.addElement(message);
80         return body;
81     }
82 }
83
Popular Tags