Rick,

It's something I was actually tinkering with and looked at as I added localization to the <s:link tag the other day by pretty much doing the same thing... cloning the Stripes Link tag and adding localization to create my own <a:link tag. But until your reply I thought about putting this aside until later.

In any event, your suggestion was very well detailed and bang on :-) So here is what I did:

#1 Added tagging subclasses LocalizedMessageInfo and LocalizedMessageWarning messages

#2 Cloned MessageTag into MessageWarningTag and MessageInfoTag with minor variations for picking the correct resource bundle keys; the only sizable change was at the end of the getMessages method I filtered the messages for the respective tags to only return a list of messages with its respective subclass. For example:

// Filter out and return only messages that are subclasses of LocalizableMessageInfo
       if (messages != null) {
           List<Message> filteredMessages = new ArrayList<Message>();
           for (Message message : messages) {
               if (message instanceof LocalizableMessageInfo) {
                   filteredMessages.add(message);
               }
           }
           // Swap full message list with the filtered message list
           messages = filteredMessages;
       }
       return messages;


#3 Cloned the stripes resource property blocks to specify "infos" and "warnings" classes respectively

stripes.messages.info.header=<div class="infos">
stripes.messages.info.beforeMessage=<p>
stripes.messages.info.afterMessage=</p>
stripes.messages.info.footer=</div>

stripes.messages.warning.header=<div class="warnings">
stripes.messages.warning.beforeMessage=<p>
stripes.messages.warning.afterMessage=</p>
stripes.messages.warning.footer=</div>


The nice thing about this mechanism is that it piggyback's on top of how Stripes handles messages so it integrates seamlessly (e.g. Stripes adding flash scope when messages added and a redirect performed).

Anyone think this should be incorporated in the Stripes framework?

Much Appreciated Rick!

--Nikolaos



Rick Grashel wrote:
Nikolaos,

It seems like you could easily extend LocalizableMessage and create an InfoMessage and WarningMessage class. Then, you would just need to create an InfoMessagesTag class and a WarningMessagesTag class. Have those classes define before and after properties just like MessagesTag.java does. In fact, copy and paste MessagesTag.java wholesale -- just change getMessages() to return List<InfoMessage> or List<WarningMessage>. Then, define the tags in your TLD file.

Then, in your ActionBean, just instantiate InfoMessages or WarningMessages and put them in the context just like a SimpleMessage. Then, you should easily be able to have a <stripes:warningMessages> and <stripes:infoMessages> tags in your JSPs. You would need to get rid of any <stripes:messages> tags as they don't discern any type of messages to display. Then, everything should work fine.

Honestly, this probably is an hour or so worth of work and it continues to follow Stripes' conventions. It might be worth some consideration.

-- Rick


On Mon, Nov 29, 2010 at 7:18 PM, Nikolaos Giannopoulos <nikol...@brightminds.org <mailto:nikol...@brightminds.org>> wrote:

    Rick,

    No... I get that... the need here is for an Ok / Info type message
    and a Warn type message  e.g. If someone just canceled editing an
    article neither a <X> error icon nor a <checkmark> icon is
    appropriate... a warning is more appropriate via say an <!> icon.

    This is not uncommon in software to provide 3 message states...
    info, warn and error.
    Stripes supports 2 but not everything is black or white sometimes
    its grey... ;-)

    I looked at handling this by making the warning messages special
    cases that would include a little extra HTML (and CSS) as follows:
    cancel.canceledTx=<span class="warn">We canceled the changes you
    were making to this {0}.</p>

    Problem is that this doesn't work very well for the size and
    placement of the warn image (its now inside a span).  Not to
    mention in the overriden warn case we are trying to place the
    image in the span and in the info case we are trying to place it
    in the div.  Just messed up all around.

    Oh well...

    --Nikolaos




    Rick Grashel wrote:
    Nikolaos,

    You can use the following in your StripesResources.properties files:

    The following is for standard messages:

    stripes.messages.header=<br/><div class="checkmark">
    stripes.messages.beforeMessage=
    stripes.messages.afterMessage=
    stripes.messages.footer=</div>

    Notice the 'class="checkmark"' piece.

    The following is for errors:

    stripes.errors.header=<br/><div class="error">The following
    errors occurred:</div><div class="error"><ol>
    stripes.errors.beforeError=<li>
    stripes.errors.afterError=</li>
    stripes.errors.footer=</ol></div>

    This is only one possible example you could use.  Obviously,
    tailor it to your needs.  But do you actually need more than just
    an error CSS class and an information CSS class?  If so, then I'd
    think you need to write your own rendering strategy for messages.

    -- Rick


    On Mon, Nov 29, 2010 at 2:54 PM, Nikolaos Giannopoulos
    <nikol...@brightminds.org <mailto:nikol...@brightminds.org>> wrote:

        Hi,

        So in Stripes we can display messages OR errors to users and
        everything
        seems OK.
        Editing the resource file makes in tandem with CSS appears to
        work well.

        However, what if one wants to display different types of
        messages for
        users like a Warning and Ok (checkmark)?

        e.g. "<checkmark-icon> Your article was saved"
        e.g. "<warn-icon> The language of this Article is English
        however you
        have selected Spanish"

        Is this possible with Stripes?

        --Nikolaos


        
------------------------------------------------------------------------------
        Increase Visibility of Your 3D Game App & Earn a Chance To
        Win $500!
        Tap into the largest installed PC base & get more eyes on
        your game by
        optimizing for Intel(R) Graphics Technology. Get started
        today with the
        Intel(R) Software Partner Program. Five $500 cash prizes are
        up for grabs.
        http://p.sf.net/sfu/intelisp-dev2dev
        _______________________________________________
        Stripes-users mailing list
        Stripes-users@lists.sourceforge.net
        <mailto:Stripes-users@lists.sourceforge.net>
        https://lists.sourceforge.net/lists/listinfo/stripes-users






--
Nikolaos Giannopoulos
Director of Information Technology
BrightMinds Software Inc.
e. nikol...@brightminds.org
w. www.brightminds.org
t. 1.613.822.1700
c. 1.613.797.0036
f. 1.613.822.1915

------------------------------------------------------------------------------
Increase Visibility of Your 3D Game App & Earn a Chance To Win $500!
Tap into the largest installed PC base & get more eyes on your game by
optimizing for Intel(R) Graphics Technology. Get started today with the
Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
http://p.sf.net/sfu/intelisp-dev2dev
_______________________________________________
Stripes-users mailing list
Stripes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/stripes-users

Reply via email to