Struts 2 refactoring code to avoid OGNL static method access

后端 未结 1 1310
借酒劲吻你
借酒劲吻你 2020-12-20 01:56

Struts 2, 2.3.20 mentioned that

Support for accessing static methods from expression will be disabled soon, please consider re-factoring your applic

1条回答
  •  庸人自扰
    2020-12-20 02:48

    In your code you are using a static method call. The best way is to create a method in the action class that wraps a static methods and use it in OGNL.

    public class Wrapper {
      public boolean isValidAmount(amount){
         return foo.barr.isValidAmount(amount);
      }
      public Object sampleMethod(Object property1){
         return foo.barr.sampleMethod(Object property1);
      }
    
    }
    

    As soon as action bean is in the value stack you can use

    @ExpressionValidator(
     expression = "isValidAmount(amount)",
     key = "validate.amount.is.not.valid"),
    

    or in JSP

    
    

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