-
Notifications
You must be signed in to change notification settings - Fork 77
Success message posting
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 methodshowSuccessMessage( boolean show );
- The
BaseAction.java
class looks for a URL parameterforward=success
and places the attributesuccess=true
in the request. - In the standard footer pages, e.g.
saveCancelFooterButtons.jsp
checks for the abovesuccess
attribute in the request and calls theshowSuccessMessage( 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.
-
In the struts file, i.e.
struts-globalOpenElis.xml
, in aforward
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" />
-
In your Action class where you would normally do
return mapping.findForward(forward);
use instead the BaseAction methodgetForwardWithParameter
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 );
}
<% } %>
});