Search code examples
liferay-6

Liferay error message does not show file size?


I used liferay-ui:error to display error message when users upload a file:

in action method:

SessionErrors.add(actionRequest, UserPortraitSizeException.class.getName());

in jsp:

<liferay-ui:error exception="<%= UserPortraitSizeException.class %>"
        message="please-enter-a-file-with-a-valid-file-size-no-larger-than-x" />

It worked. The message was showed, except the limit size that I set in portal-ext.properties [users.image.max.size=307200] does not appear

The message was:

Please enter a file with a valid file size no larger than {0}k. 

Am I missing something? (I am using lifera 6.1)


Solution

  • You have to format your message using LanguageUtil.java's utility method . I.e. LanguageUtil.format(themeDisplay.getLocale()," please-enter-a-file-with-a-valid-file-size-no-larger-than-x",Propsutil.get(" users.image.max.size "))

    Just another information for language messages having {n}, where n is number.

    This is used when you want to have message with some custom dynamic attribute, and you have to provide dynamic attribute as arguments of liferay-ui:message tag.

    For Example:

    <liferay-ui:message key="abc" arguments='<%=new Object[]{"King","Thanks"}%>'/>
    

    and in language properties file you have, abc= You are {0}, {1}

    then it will result in message "You are King, Thanks"

    Regards,