package votorola.a.web.wic; // Copyright 2008, 2012-2013, Michael Allan. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Votorola Software"), to deal in the Votorola Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Votorola Software, and to permit persons to whom the Votorola Software is furnished to do so, subject to the following conditions: The preceding copyright notice and this permission notice shall be included in all copies or substantial portions of the Votorola Software. THE VOTOROLA SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE VOTOROLA SOFTWARE OR THE USE OR OTHER DEALINGS IN THE VOTOROLA SOFTWARE. import org.apache.wicket.*; import org.apache.wicket.feedback.*; import org.apache.wicket.markup.html.*; import org.apache.wicket.markup.html.basic.*; import org.apache.wicket.markup.html.link.*; import org.apache.wicket.markup.repeater.*; import votorola.g.lang.*; import votorola.g.locale.*; import votorola.g.web.wic.*; /** A general purpose message page for displaying messages outside their page of origin. * This is intended for exceptional messages that can suffer a generic presentation * removed from the context of the source page. * * @see WP_Message.html */ public @ThreadRestricted("wicket") final class WP_Message extends VPageHTML { // It cannot be stateless. It is normally preconstructed and set as the response page // (a redirect). Therefore it is held in the session and is stateful. /** Constructs a WP_Message that displays the session's feedback messages and then * clears them. */ public WP_Message() { final VRequestCycle cycle = VRequestCycle.get(); // add( new WC_NavigationHead( "navHead", WP_Message.this, cycle )); // add to all constructors /// but using its login facility lands user back on this page, which says "Something is wrong" // Title // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - { final String title = cycle.bunW().l( "a.web.wic.WP_Message.sessionFeedbackDump" ); add( new Label( "title", title )); add( new Label( "titleH", title )); } // Messages // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - messagesDiv = new WebMarkupContainer( "messages" ); add( messagesDiv ); final RepeatingView repeating = new RepeatingView( "messageRepeating" ); final FeedbackMessages mm = VSession.get().getFeedbackMessages(); for( Object o: mm.messages( /*filter*/null )) { final FeedbackMessage m = (FeedbackMessage)o; final WebMarkupContainer y = new WebMarkupContainer( repeating.newChildId() ); // final Label body = new Label( "messageRepeating-body", m.getMessage().toString() ); final Label body = new Label( "messageRepeating-body", m.toString() ); // if( message.isWarning() ) VPageHTML.appendStyleClass( label, "invalid" ); body.setRenderBodyOnly( true ); y.add( body ); repeating.add( y ); } mm.clear(); // or ought I call Session.cleanupFeedbackMessages()? messagesDiv.add( repeating ); // Links // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - init(); } /** Constructs a WP_Message that displays the specified messages. */ public WP_Message( final String title, final Object... messages ) { final VRequestCycle cycle = VRequestCycle.get(); // Title // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - add( new Label( "title", title )); add( new Label( "titleH", title )); // Messages // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - messagesDiv = new WebMarkupContainer( "messages" ); add( messagesDiv ); final RepeatingView repeating = new RepeatingView( "messageRepeating" ); for( Object o: messages ) { final WebMarkupContainer y = new WebMarkupContainer( repeating.newChildId() ); y.add( new Label( "messageRepeating-body", o.toString() ).setRenderBodyOnly( true )); repeating.add( y ); } messagesDiv.add( repeating ); // Links // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - init(); } private void init() { add( linkRepeating ); } // ------------------------------------------------------------------------------------ /** Adds links to the bottom of the page. The ID of each link must be 'link'. * * @return this message page. */ public WP_Message addLinks( final AbstractLink... links ) { for( AbstractLink link: links ) { assert "link".equals( link.getId() ); final WebMarkupContainer y = new WebMarkupContainer( linkRepeating.newChildId() ); y.add( link ); linkRepeating.add( y ); } return WP_Message.this; } /** Sets preformatted styling, effectively displaying the messages in 'pre' tags as * opposed to 'p'. * * @return this message page. */ public final WP_Message pre() { appendStyleClass( messagesDiv, "pre" ); return WP_Message.this; } private final RepeatingView linkRepeating = new RepeatingView( "linkRepeating" ); private final WebMarkupContainer messagesDiv; }