开发者

How to retrieve a message with a specific key from <stripes:messages> of Stripes Framework

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>


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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜