开发者

JSP page not populating the formBean property associated with <html:select> <html:option>

开发者 https://www.devze.com 2023-04-09 01:52 出处:网络
<html:select property=\"fileLocation\"> <% ArrayList uploadLocationLookUp = null; uploadLocationLookUp = (ArrayList) request.getSession().getAttribute(\"uploadLocation\");
<html:select property="fileLocation">
  <%
    ArrayList uploadLocationLookUp = null;
    uploadLocationLookUp = (ArrayList) request.getSession().getAttribute("uploadLocation");
    if (uploadLocationLookUp.size() != 0) {
        for (int i = 0; i < uploadLocationLookUp.size(); i++) {
            LookUpBean lookUpBeanItems = (LookUpBean) uploadLocationLookUp.get(i);
  %>
    <html:option value="<%=lookUpBeanItems.getLookUpCode()%>">
      <%= lookUpBeanItems.getLookUpCode() %>
    </html:option>
  <% }} %>
</html:select>

I'm using the LookUpBean to populate the options in the select tag which is associated with a formBean with property fileLocation.

While all other properties are populating property in the formBean this one is not. I also tried getting to it using request.getParameter("fileLocation") in my action class but it just wont work.

Can anyone eyeball this chunk 开发者_StackOverflow中文版of code and point out any silly mistake that might have been missed? Are there other areas/issues that I might have run into? A quick response would be much appriciated. Thanks


It worked :) Don't know why though :(

All I did was refactor my code and rearranged the input elements on my form. Once I placed the rogue <html:select> after a piece of java code on my jsp, it worked like a charm. Can anyone give pointers to something wrong that I did and why it worked after I rearranged my form elements?


I don't see anything obviously wrong with this code, provided that both the fileLocation and lookUpCode properties are Strings.

One tip, you should be able to eliminate the scriptlet code by using the html:options tag:

<html:select property="fileLocation">
    <html:options collection="uploadLocation" property="lookUpCode" labelProperty=""lookUpCode"/>
</html:select>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号