Wednesday, August 19, 2009

BeanUtils.populate Issue Struts

I had an issue with the BeanUtils.populate exception. This issue is usually caused because the jsp page is trying to populate a Form and for some reason, it isn't able to do it. If you receive this error, go through your code carefully to make sure that the form will populate correctly and that all of your property values are correct. One way to debug the page is to take all the tags out and insert them back in the page one by one. This way you can narrow down which tag is incorrect.

javax.servlet.ServletException: BeanUtils.populate org.apache.struts.util.RequestUtils.populate(RequestUtils.java:497)

My code looks like this:


<nested:iterate property="wpcSummaryList">
<tr <%if ((count%2)==0){ %>class="odd"<%}%>>
<td class="colwidth_5">
<nested:checkbox property="checked" />
<input type="hidden" id="searchResultsConfigurator[<%=count %>].wpcSummaryList[<%=subcount %>].checked" name="searchResultsConfigurator[<%=count %>].wpcSummaryList[<%=subcount %>].checked" value="" />
</td>
</nested:iterate>

The hidden tag is there to allow the user to unselect the checkbox. However, I really didn't need it here and it threw the BeanUtils.populate error when trying to set the value to empty because the id and name values were incorrect.

Another issue that caused this for me was when a user removed an item from the page and then pressed the back space from the browser and re-submitted the form. The item that was removed was no longer in the form so it threw this error. There could be some issues with the backspace so you should take that into consideration when building your application.

0 comments: