Skip to content

Success message posting

Paul Schwartz edited this page Jun 10, 2015 · 3 revisions

After a user saves a entered data openELIS will display a "Success" message at the top of the page. This explains how the feature is added to a page

##Background

  • The Tile Page actionSuccess.jsp actually displays the message. This page also contains a javascript method showSuccessMessage( boolean show );
  • The BaseAction.java class looks for a URL parameter forward=success and places the attribute success=true in the request.
  • In the standard footer pages, e.g. saveCancelFooterButtons.jsp checks for the above success attribute in the request and calls the showSuccessMessage( true );

##What the developer needs to do

###Include the message tile

In the struts tile definition file, e.g. tile-globalOpenELIS.xml, the message tile can be included in any tile definition by placing it in the preSelectionHeader (we weren't using this section for anything else and it's in the right place on the standard page).

<definition name="..." extends="baseDefinition">
     <put name="preSelectionHeader" value="/pages/common/actionSuccess.jsp" />
     ...
</definition>

###Tell the page to display the message To trigger the BaseAction to find the URL parameter and thus get the included tile to display the success message you have two choices.

  1. In the struts file, i.e. struts-globalOpenElis.xml, in a forward element add an extra URL parameter to any other action forwarding successfully to the page; see below. This method requires very little extra declaration.

     <forward name="success" path="/ManageInventory.do?forward=success" />
    
  2. In your Action class where you would normally do return mapping.findForward(forward); use instead the BaseAction method getForwardWithParameter i.e. return getForwardWithParameters(mapping.findForward(forward), params ); with a parameter of "forward" with a value of "success". This method is particularly useful when one action forwards to another action and there is no page URL onto which to append the extra parameter.

###Clear the message when it's no longer needed.

We don't want the message to stay at the top of the page as the user is working on it. As soon as they start entering more information the message should be removed

To clear the message whenever the user starts to type add a call to showMessageSuccess whenever something new happens. For example, if you always call makeDirty() in every fields onChange, 'onChange="...' makeDirty()"', your 'makeDirty()' method might look like the following

function makeDirty(){
    dirty = true;
        // do other work 
    if( typeof(showSuccessMessage) != 'undefinded' ){
	showSuccessMessage(false); //refers to last save
    }
}

###If it doesn't seem to work Most of the pages already have the hooks built into to make this work but if it does not make sure that the javascript for displaying the message is on the generated page. If you look at the source of the page on the client and does not have showSuccessMessage( true ) then add the following (check to see if $jq(document).ready(....) exists)

$jq(document).ready(function(){
    <%if( request.getAttribute(IActionConstants.FWD_SUCCESS) != null &&
    ((Boolean)request.getAttribute(IActionConstants.FWD_SUCCESS)) ) { %>
    if( typeof(showSuccessMessage) != 'undefined' ){
        showSuccessMessage( true );
    }
    <% } %>
});
Clone this wiki locally