Client sending String[] instead of Bigdecimal to server when changing

Asked

Viewed 217 times

2

When it’s a re-registration works peacefully, the problem is in the alteration.

I own an object To who is the master, another object B which is a ArrayList and detail of the master To and finally, an object C that is ArrayList and detail of the object B.

When I send the information to the server and the index of the object B is equal to 0 and the detail that is the object C is not null works properly without complaining to convert String[] for BigDecimal.

But when I send the information and the index of the object B is larger that 0 and the detail that is the object C is not null is accused who is trying to convert String[] for BigDecimal and returns error.

org.springframework.validation.Beanpropertybindingresult: 3 errors Field error in Object 'A' on field 'B[1]. C[0]. attribute': Rejected value [190.67,190.67]; ...(Other errors not listed, but not different from the one that occurred since it is a detail).

How is the element in JSP which I fill using Angularjs when the user clicks to generate a new item in detail C:

name='B[{{B.index}}].C[{{C.index}}].atributo'

As it is in the model:

@Column(name = "ATRIBUTO")
@NotNull(message = "{validate.required.atributo}")
@NumberFormat(pattern = "0.00")
private BigDecimal atributo;

Prints of how Javascript is in the event Submit of form:

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

Error that returns to the user in the client layer:

Failed to Convert Property value of type java.lang.String[] to required type java.math.Bigdecimal for Property B[1]. C[0]. attribute; nested Exception is java.lang.Numberformatexception

Any solution to this problem? Apparently I believe the definition in the attribute name to properly generate the objects in the server layer is correct, even more that it is saved in the database when it is a new record, the problem occurs when we enter changing and when the object B will possess the attribute C which will not be null, is in an index greater than 0 causing the appearance of a String vector in the attribute as you noticed by the error message since it seems to have been multiplied by so many elements that exist in the detail B.

The question is, how to fix it when apparently it’s right?

  • It seems that the angular is transforming a number into a string and then the error occurs. See if you can print the data before sending it to the server.

  • Rejected value is actually an invalid string: '190.67,190.67' (since you defined in the interface that the expected format is string[]). The correct one would return as individualized elements - ['190.67','190.67'].

  • I put an Alert in an event before giving Submit in the form in one of the elements of the third detail, namely the object C in the change and returned a numerical value, not a String. And what you expect on the server is an element of Bigdecimal type, I edited the question by putting the model.

  • The first value you pass in the vector is the value ancient and the second value is the new which should replace the ancient.

1 answer

1

For his Mistake:

org.springframework.validation.Beanpropertybindingresult: 3 errors Field error in Object 'A' on field 'B[1]. C[0]. attribute': Rejected value [190.67,190.67]; ...(Other errors not listed, but not different from the one that occurred since it is a detail).

The problem is that you are treating your entire vector as a string. See how you are sending before the values of this your vector, making the unit conversion.

["190.67", "190.67", ...]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.