JSP 页面未填充与关联的 formBean 属性

发布于 2024-12-07 08:08:49 字数 1036 浏览 3 评论 0原文

<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>

我使用 LookUpBean 填充 select 标记中的选项,该标记与具有 fileLocation 属性的 formBean 关联。

虽然所有其他属性都填充了 formBean 中的属性,但这个属性却不是。我还尝试在我的操作类中使用 request.getParameter("fileLocation") 来获取它,但它不起作用。

有人能仔细观察这段代码并指出任何可能被遗漏的愚蠢错误吗?我可能遇到其他领域/问题吗?如果能快速回复,我们将不胜感激。谢谢


它成功了:) 但不知道为什么:(

我所做的只是重构我的代码并重新排列表单上的输入元素。一旦我将流氓 放在我的一段 java 代码之后jsp,它就像一个魅力。任何人都可以指出我做的错误以及为什么在我重新排列我的表单元素后它会起作用吗?

<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 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

也只是曾经 2024-12-14 08:08:49

如果 fileLocationlookUpCode 属性都是字符串,我没有发现这段代码有任何明显的错误。

一个提示,您应该能够使用 消除 scriptlet 代码html:选项 标签:

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

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文