Change Struts 2, i18n classes behavior when key is not found

前端 未结 1 946
北荒
北荒 2021-01-21 11:34

We used getText in actions, setMessageKey in validators and in jsp files for an i18n application.

When Struts 2 cou

1条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-21 11:37

    You need to create custom implementation of TextProvider and override getText methods in it.

    1) Create class (e.g. EmptyDefaultTextProvider) extending one of TextProvider existing implementations (e.g. TextProviderSupport).

    2) Override all getText methods like that:

    public String getText(String key, String defaultValue) {
         return super.getText(key, "");
    }
    

    3) Use your custom class as the default text provider. Put below in struts.xml.

    
    
    
    

    0 讨论(0)
提交回复
热议问题