Error setting expression 'spa.amount' with value '[Ljava.lang.String;@10dd65e' )

后端 未结 1 1610
刺人心
刺人心 2020-12-11 12:15

I am trying following code to get data in spa object fields. Thus, I am using the following code but it is showing null values and giving the follo

相关标签:
1条回答
  • 2020-12-11 12:48

    According to the error

    Error setting expression 'spa.amount' with value '[Ljava.lang.String;@10dd65e'
    

    seems that OGNL is trying to set a value of type String[] to amount property of spa bean.

    Reading further

    ognl.OgnlException: target is null for setProperty(null, "amount", [Ljava.lang.String;@10dd65e)  
    

    looks like spa reference is null, so OGNL is unable to set a value to a null because it will throw a null pointer exception.

    To resolve the issue you should initialize the reference of spa.

    Next the problem arises because you use a model driven. The model driven interceptor pushes a model on top of the value stack, which is an OGNL root. And you have initialized the instance of spa. Seems that OGNL even if searches from the top of the value stack down the stack can't find the instance of spa. So, to access action properties directly you can use technique described in this answer Passing parameters to action through ModelDriven in Struts 2.3.16.

    The method expected by OGNL on reference of spa is

    public void setAmount(String[] amounts) {
       this.amounts = amounts;
    }
    

    You don't have such method and you probably not expected to receive an array of strings. But the problem is that you are doing it. Because parameters with the same name are packaged into String[]. To have different names corresponding to each iterated object you should use indexed property names. You can find an example if indexed properties in this answer Repopulate an ArrayList from JSP with Struts 2.

    Your properties are available directly from the model because your action is model driven and it should have a List<SupplierPaymentDetails> paidList that is iterated. You can use this property to populate the submitted values or use another with the same type.

    ModelDriven example you can learn, but it doesn't use indexed properties. To use it properly you can use this answer How to pass a Map<ObjectA, List<ObjectB>> to action in Struts 2.

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