jsp - Struts 2 s:if with getText -
i want see if message key presented in message bundles. tried below none of them worked:
<s:if test=" gettext('site.message') == 'site.message'"> <s:if test=" gettext('site.message').equals('site.message')"> <s:if test=" %{gettext('site.message').equals('site.message')}">
but workaround works fine:
<s:text name="site.message" var="test"/> <s:if test=" #test=='site.message'"> please consider: <s:text name="site.message"/> </s:if>
so possible omit #test variable , works in s:if
it's possible if use body of <s:text>
default message instead of body of <s:if>
tag. docs page
if named message not found in property file, the body of tag used default message. if no body used, stack searched, , if value returned, written output. if no value found on stack, key of message written out. use key set default message.
the equivalent code
<s:text name="site.message"><s:text name="error.message"/></s:text>
also consider default value of gettext(string atextname, string defaultvalue)
.
gets message based on key, or, if message not found, supplied default value returned.
then can use
<s:if test="gettext('site.message','') != ''"> please consider: <s:text name="site.message"/> </s:if> <s:else> <s:text name="error.message"/> </s:else>
or check key haskey(string key)
checks if message key exists.
<s:if test="haskey('site.message')"> please consider: <s:text name="site.message"/> </s:if> <s:else> <s:text name="error.message"/> </s:else>
Comments
Post a Comment