1

ModelAttribute名前付きを使用してビューにバインドするオブジェクトがありますSurveyDetail。そのオブジェクトには、 と という名前の 2 つの属性がidありsurveyYearます。メソッドの値にアクセスするために、POST属性ごとに隠しフィールドを用意しています。調査年値はコントローラーで正しく返されますが、id は null を返します。それらは両方ともsurveyDetailの一部であり、なぜsurveyYearには正しくバインドされ、idにはバインドされないのか理解できませんか? エラーはスローされず、初期GET値では id フィールドに正しい値が含まれていますが、id 値に到達するとすぐにPOSTnull が返されます。また、 request.getParameter("id") を実行すると正しい値が返されますが、バインドされたパスを参照しようとすると null が返されますsurveyDetail.getId. 私が間違っていることを理解できないのを助けてください。id フィールドはページのどこにも存在しません。null はどこから来ているのでしょうか?

コントローラーのPost方法:

@RequestMapping(method=RequestMethod.POST)
public String submit(@ModelAttribute(WebConstants.SURVEY_DETAIL) SurveyDetail surveyDetail, BindingResult result, HttpServletRequest request, HttpServletResponse response) throws IOException
{   

    if (LOGGER.isDebugEnabled())
        LOGGER.debug(surveyDetail.getId()  + " Year : " + surveyDetail.getSurveyYear());    

    if (LOGGER.isDebugEnabled())
        LOGGER.debug("REQUEST PARAMETER: " + request.getParameter("id"));

     return WebConstants.SELECT_STATES_VIEW_REDIRECT; 

}   

JSP フォーム:

<sf:form method="POST" name="form1" id="form1" modelAttribute="surveyDetail">  

    <table width="100%" border="0" cellpadding="0" cellspacing="0" id="workTable-full">       

        <tr>
            <td colspan="4">&nbsp;
                <sf:input type="hidden" path="surveyYear" id="year" cssClass="inputbox-survey" maxlength="100" size="10" />             
                <sf:input type="hidden" path="id" id="id" cssClass="inputbox-survey" maxlength="100" size="10" />   
            </td>
        </tr>   

        <tr>
            <td colspan="4"><input type="submit" class="small-short inner2" value="Enter Data" alt="Enter Data" title="Enter Data" id="cr8StateTable" name="cr8StateTable"/> <strong>- Click this button to start entering individual State data</strong>
            </td>
        </tr>

   </table>              

4

0 に答える 0