Search code examples
jspstruts-1

How to check if <bean:message> return NULL


In my application I am using struts 1.3. In my login page, I am showing a label which is fetched from property file. I am using below code for same -

<bean:message key="key.label1" bundle="msg.bundle1">

In case the key "key.label1" doesn't exist in property file, is there any way to detect that?

Thanks, Kartic


Solution

  • As per my knowledge, there is no way to know if the key under some resource file exist or not.
    You may require to write your custom class to achieve this.
    However, if you want that your JSP should not display any exception, if key does not exist you can do this by;

    <message-resources parameter="com.uks.hms.properties.labels"
        key="label" null="false"/>
    

    providing null=false, will guide struts not to prompt any exception if the key does not exist in the resource file. Instead, it will display the key name itself.