웹 응용 프로그램에 Spring MVC를 사용하고 있으며 클라이언트 선택과 연락처 정보 표시를 다루는 간단한 양식으로 작업하고 있습니다.java.lang.NumberFormatException - 데이터 바인딩 오류
내가 겪고있는 문제 중 하나는 클라이언트를 처음 선택하면 정보를 끌어 올릴 수 있지만 두 번째로는 실망 스럽습니다. 이전 클라이언트의 정보가 표시됩니다.
나는 로깅하고있는 것에 대해 더 많은 것을 보았고 데이터 바인딩 오류가 발생하여 내 콘솔에서 다음과 같이 모두 익숙한 출력을보고있었습니다. 오류 출력에 표시되는 경우
Failed to convert property value of type [java.lang.String[]] to required type [java.lang.Integer] for property 'clientId'; nested exception is java.lang.NumberFormatException: For input string: "3349,4182"
그것을 참조하는 3349의 경우
...for string: "3349,4182"
양식이 4182 게시 선택한 첫 번째 고객의 클라이언트 ID 보여줍니다은의 클라이언트 ID입니다 둘째.
나는 약간의 연구를했으며 새로운 ClientID를 복용하는 것에 반대하는 것으로 [3349,4182]의 배열로 두 숫자를 처리하는 것으로 뭔가를하고 있다고 말한 사람들을 만났습니다.
감사합니다,
편집
public class ClientContactModel implements Serializable { private String searchText; private Integer clientId; public ClientContactModel() { } public String getSearchText() { return searchText; } public void setSearchText(String searchText) { this.searchText = searchText; } public Integer getClientId() { return clientId; } public void setClientId(Integer clientId) { this.clientId = clientId; } }
다음은 NumberFormatException이 던지고 전화
clientId = Integer.valueOf(request.getParameter("clientId"));
인을 다음과 같이 지원 객체입니다는
<pre><code><tr>
<td align="center">
<form:select path="clientId">
<form:option value="">Select a client...</form:option>
<form:options items="${clientUsers}" itemValue="id" itemLabel="username" />
</form:select>
<input type="button" name="selectButton" id="selectButton" value="Go" onclick="selectContact();">
</td>
</tr>
<tr>
<td align="center">
Display clients who have not updated their contact information since
<input name="month" type="text" id="textfield2" value="MM" size="4">
<input name="day" type="text" id="textfield3" value="DD" size="4">
<input name="year" type="text" id="textfield4" value="YY" size="4">
<input type="submit" name="notUpdatedButton" id="notUpdatedButton" value="Go">
</td>
</tr>
도 함께
조금 JS가있다, 그래, 나는 SimpleFormController 같은 다음UI를 코드가 클라이언트에 관련되어 사용하고, 첫 번째 질문에 대답하려면
function selectContact() {
document.getElementById("searchText").value = "";
document.getElementById("clientContactObj").submit();
}
SimpleFormController를 사용하고 계십니까? FormBackingObject는 어떻게 생겼습니까? –
드롭 다운을 사용하는 경우 multiple = true가 있습니까? clientId에 대한 모든 UI 코드가 도움이 될 것입니다. –
글쎄, 전문가는 아니지만 문제는 귀하의 양식에 있다고 생각합니다 : multiple = false를 설정해야합니다. 이유는 스프링이 문자열을 전달해야 할 때 Spring이 String []을 전달하려고하기 때문이라고 생각합니다. –