• <small id='w5Yqo'></small><noframes id='w5Yqo'>

      1. <tfoot id='w5Yqo'></tfoot>

      2. <legend id='w5Yqo'><style id='w5Yqo'><dir id='w5Yqo'><q id='w5Yqo'></q></dir></style></legend>
      3. <i id='w5Yqo'><tr id='w5Yqo'><dt id='w5Yqo'><q id='w5Yqo'><span id='w5Yqo'><b id='w5Yqo'><form id='w5Yqo'><ins id='w5Yqo'></ins><ul id='w5Yqo'></ul><sub id='w5Yqo'></sub></form><legend id='w5Yqo'></legend><bdo id='w5Yqo'><pre id='w5Yqo'><center id='w5Yqo'></center></pre></bdo></b><th id='w5Yqo'></th></span></q></dt></tr></i><div id='w5Yqo'><tfoot id='w5Yqo'></tfoot><dl id='w5Yqo'><fieldset id='w5Yqo'></fieldset></dl></div>
          <bdo id='w5Yqo'></bdo><ul id='w5Yqo'></ul>

        “选择"未从 List&lt;String&gt; 填充在支柱

        时间:2023-10-15

          <bdo id='VKteL'></bdo><ul id='VKteL'></ul>

            <small id='VKteL'></small><noframes id='VKteL'>

                <tbody id='VKteL'></tbody>

              • <tfoot id='VKteL'></tfoot>
                <i id='VKteL'><tr id='VKteL'><dt id='VKteL'><q id='VKteL'><span id='VKteL'><b id='VKteL'><form id='VKteL'><ins id='VKteL'></ins><ul id='VKteL'></ul><sub id='VKteL'></sub></form><legend id='VKteL'></legend><bdo id='VKteL'><pre id='VKteL'><center id='VKteL'></center></pre></bdo></b><th id='VKteL'></th></span></q></dt></tr></i><div id='VKteL'><tfoot id='VKteL'></tfoot><dl id='VKteL'><fieldset id='VKteL'></fieldset></dl></div>
                • <legend id='VKteL'><style id='VKteL'><dir id='VKteL'><q id='VKteL'></q></dir></style></legend>
                  本文介绍了“选择"未从 List&lt;String&gt; 填充在支柱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有以下来源:

                  struts.xml

                  <?xml version="1.0" encoding="UTF-8" ?>
                  <!DOCTYPE struts PUBLIC
                      "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
                      "http://struts.apache.org/dtds/struts-2.0.dtd">
                  
                  <struts>
                  
                      <constant name="struts.enable.DynamicMethodInvocation" value="true" />
                      <constant name="struts.devMode" value="true" />
                      <constant name="struts.custom.i18n.resources" value="ApplicationResources" />
                  
                      <package name="vislabWebShop" extends="struts-default">
                  
                          <action name="UserForward">
                              <result>/pages/Login.jsp</result>
                          </action>
                  
                          <action name="UserLogin" class="vislabWebShop.controller.LoginAction">
                              <result name="success">/pages/Welcome.jsp</result>
                              <result name="input">/pages/Login.jsp</result>
                          </action>
                  
                          <action name="UserRegister" class="vislabWebShop.controller.RegisterAction">
                              <result name="success">/pages/RegisterSuccess.jsp</result>
                              <result name="input">/pages/Register.jsp</result>
                          </action>
                  
                          <action name="UserRegisterNew">
                              <result>/pages/Register.jsp</result>
                          </action>
                  
                          <action name="UserRegisterSuccess">
                              <result>/pages/Login.jsp</result>
                          </action>
                  
                          <action name="ProductSearchForward">
                              <result>/pages/SearchProduct.jsp</result>
                          </action>
                  
                          <action name="ProductSearch" class="vislabWebShop.controller.ProductSearchAction">
                              <result name="success">/pages/Login.jsp</result>
                          </action>
                      </package>
                  </struts>
                  

                  ProductSearchAction.java:

                  ProductSearchAction.java:

                  package vislabWebShop.controller;
                  
                  import java.util.ArrayList;
                  import java.util.List;
                  
                  import com.opensymphony.xwork2.ActionSupport;
                  
                  public class ProductSearchAction extends ActionSupport
                  {
                    private List<String> categories;
                    private String chosenCategory;
                  
                    public ProductSearchAction()
                    {
                      categories = new ArrayList<String>();
                      categories.add("Eins");
                      categories.add("Zwei");
                      categories.add("Drei");
                    }
                  
                    @Override
                    public String execute() throws Exception
                    {
                      return SUCCESS;
                    }
                  
                    public List<String> getCategories()
                    {
                      return categories;
                    }
                  
                    public void setCategories(List<String> categories)
                    {
                      this.categories = categories;
                    }
                  
                    public String getChosenCategory()
                    {
                      return chosenCategory;
                    }
                  
                    public void setChosenCategory(String chosenCategory)
                    {
                      this.chosenCategory = chosenCategory;
                    }
                  }
                  

                  SearchProduct.jsp:

                  SearchProduct.jsp:

                      <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
                          pageEncoding="ISO-8859-1"%>
                      <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
                      <%@ taglib prefix="s" uri="/struts-tags"%>
                  
                      <html>
                      <head>
                      <title><s:text name="welcome.title" /></title>
                      </head>
                  
                      <body bgcolor="white">
                  
                          <font color="red"> <s:actionmessage />
                          </font>
                  
                      <p>
                          <b><s:text name="product.search.title" /></b>
                      </p>
                  
                      <s:form action="ProductSearch" focusElement="description">
                          <s:textfield name="description" key="prompt.description" size="20" />
                          <s:textfield name="minprice" key="prompt.price.min" size="20" />
                          <s:textfield name="maxprice" key="prompt.price.max" size="20" />
                          <s:select key="product.search.category" headerKey="-1" 
                          headerValue="Bitte whlen Sie eine Kategorie"
                              list="categories" />
                          <s:submit value="Produkt suchen" align="right" />
                      </s:form>
                  
                      <font color="red"> <s:actionerror label="label" />
                      </font>
                  
                  
                  </body>
                  </html>
                  

                  现在我有一个问题,如果我从 Action ProductSearchForward 转到 JSP 站点 SearchProduct.jsp,我总是会收到以下错误:

                  Now I have the problem, that I always get the following error if I come from Action ProductSearchForward to the JSP site SearchProduct.jsp:

                  org.apache.jasper.JasperException:标签选择",字段列表",名称产品.search.category":请求的列表键类别"无法解析为集合/数组/映射/枚举/迭代器类型.示例:人或人.{name} - [未知位置]

                  org.apache.jasper.JasperException: tag 'select', field 'list', name 'product.search.category': The requested list key 'categories' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]

                  我只想从给定的 ArrayList<String> (List<String>) 填充 DropDownList,但它不起作用.如果我直接设置列表内容就可以了.

                  I just want the DropDownList to be populated from the given ArrayList<String> (List<String>), but it is not working. If I set the list content directly it works fine.

                  推荐答案

                  <s:select list = "categories" 
                             key = "product.search.category" />
                  

                  您正在列出 List<String> 并尝试通过 OGNL .(点表示法)访问不存在的字段.

                  You are listing a List<String> and trying to access, through OGNL . (dot notation), fields that do not exist.

                  在 OGNL 中

                  product.search.category 
                  

                  相当于Java

                  getProduct().getSearch().getCategory()
                  

                  由于您要列出字符串,因此只需省略 key 属性,因为您的键和值都将是字符串本身.

                  Since you are listing Strings, just omit key attribute, because both your key and value will be the String itself.

                  您似乎也将 keyname 混淆了:key 的键code> 元素,而 name 是 Action 的属性,它将通过其 Setter 接收所选值.

                  It seems that you are confusing key with name too: key is the key of the <option> element, while name is the Action's attribute that will receive the chosen value through its Setter.

                  <s:select list = "categories" 
                            name = "chosenCategory" />
                  

                  <小时>

                  编辑:为了成功的生活,实施 Preparable Interface 并在那里加载你的静态"数据:


                  EDIT: for a succesful living, implement Preparable Interface and load there your "static" data:

                  public class ProductSearchAction extends ActionSupport implements Preparable {
                      private List<String> categories;
                      private String chosenCategory;
                  
                      @override
                      public void prepare() throws Exception {      
                          categories = new ArrayList<String>();
                          categories.add("Eins");
                          categories.add("Zwei");
                          categories.add("Drei");
                      }
                  
                      @Override
                      public String execute() throws Exception {
                          return SUCCESS;
                      }
                  
                      /* GETTERS AND SETTERS */
                  }
                  

                  而且你必须为 struts.xml 中的每个标签指定完全限定的类名...

                  And you must specify fully qualified class names for each tag in struts.xml...

                  这篇关于“选择"未从 List&lt;String&gt; 填充在支柱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在不使用主题=“简单"的情况下使用 Struts 2 在同一行中定位多个文本字段? 下一篇:我如何在eclipse中配置applicationcontext.xml

                  相关文章

                  <small id='EYABs'></small><noframes id='EYABs'>

                      <tfoot id='EYABs'></tfoot>
                    1. <i id='EYABs'><tr id='EYABs'><dt id='EYABs'><q id='EYABs'><span id='EYABs'><b id='EYABs'><form id='EYABs'><ins id='EYABs'></ins><ul id='EYABs'></ul><sub id='EYABs'></sub></form><legend id='EYABs'></legend><bdo id='EYABs'><pre id='EYABs'><center id='EYABs'></center></pre></bdo></b><th id='EYABs'></th></span></q></dt></tr></i><div id='EYABs'><tfoot id='EYABs'></tfoot><dl id='EYABs'><fieldset id='EYABs'></fieldset></dl></div>

                        <bdo id='EYABs'></bdo><ul id='EYABs'></ul>
                      <legend id='EYABs'><style id='EYABs'><dir id='EYABs'><q id='EYABs'></q></dir></style></legend>