3

I want to retrieve a message with a specific key from the tag of Stripes framework.

In the action bean I have this:

    switch (result) {
            case REG_ALREADY_REGISTERED:
                getContext().getMessages().add(new LocalizableMessage("consumer.already.registered"));
                redirect = getContext().getSourcePageResolution();
                break;

In the JSP page:

<stripes:messages key="consumer.already.registered"/>

but the above code does not seem to work. If I am putting only the "<stripes:messages/>" it shows stripes's default way of printing messages. i.e, with "ul li" thing. I want to give my kind of presentation to the messages. Is there anything possible with JSP like as follows:

<c:if test="${not empty actionBean.context.messages}">
    <c:out value="${actionBean.context.messages......"/> //This is the place where I am unsure
</c:if>
kaushik
  • 2,308
  • 6
  • 35
  • 50

1 Answers1

3

There is a feature request filed to have additional tags for displaying messages : http://www.stripesframework.org/jira/browse/STS-245.

If what you don't like is the default messages headers and footers, you just have to change them through the properties as described in the documentation: http://stripes.sourceforge.net/docs/current/taglib/stripes/messages.html. This will change the headers and footers for all your pages, though. If you want to change them for one specific page, There is no other way, AFAIK, than doing something like this:

<c:if test="${not empty actionBean.context.messages}">
    <c:forEach var="message" items=${"actionBean.context.messages}">
        ${myFn:getMessageText(message, getPageContext.request.locale)}
    </c:forEach>
</c:if>

Where myFn:getMessageText would be a function defined like this:

public static String getMessageText(Message message, Locale locale) {
    return message.getMessage(locale);
}
JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • Can you please tell me, what is that "key" in **** stands for ? – kaushik Jul 02 '11 at 13:05
  • Thanks man for considering this question. I am going to use some boolean value to check whether the user is registered or not and display the message using – kaushik Jul 02 '11 at 13:19
  • The documentation of the tag (it helps to read the documentation, BTW: http://stripes.sourceforge.net/docs/current/taglib/stripes/messages.html) says: The name of the request or session attribute that the tag will use to find messages for display. It's thus useful when you have to print a messages list which is not the default messages list, but another, different messages list, that you might have created yourself and stored in the request or session. – JB Nizet Jul 02 '11 at 13:21
  • Note that consumer.already.registered looks more like an error than like a message to me. And stripes has more flexible tags to deal with error messages. – JB Nizet Jul 02 '11 at 13:23
  • There is also a problem. I have already used the "****" with a specific css styling. Now I want to give the user a message like this: "You are already registered. Use **forgot** password" with another styling – kaushik Jul 02 '11 at 13:58
  • Use and to display the other error message with a different styling. – JB Nizet Jul 02 '11 at 14:07
  • field is the same "consumer.consumerId", in both cases – kaushik Jul 02 '11 at 14:17