无法在<html:select>标记内的<html:optionscollection>标记中获得下拉列表

时间:2018-10-17 06:14:59

标签: java struts html-select actionform

Adminprofile.jsp

我正在使用选项集合来遍历代理商列表并显示下拉值

 <html:form action="/adminaction.do" styleId="registration-form">
        <div class="firstFieldset1 agencyNameDiv">
            <label for="agencyName">Agency Name </label>
                <html:select property="agencyName" >
                     <html:option value="0">Selectagency</html:option>
                          <html:optionsCollection name="UserRegistrationForm" property="agencyList" label="agncyId" value="agncyName" />
                 </html:select>
        </div>
    </html:form>

UserRegistrationForm.java

用于显示jsp页面的Bean表单。我在此处添加了代理商列表,以便在jsp页面中获取它

 public class UserRegistrationForm extends org.apache.struts.action.ActionForm {
    private String agencyName;
    private ArrayList<BrandAgencyData> agencyList;



        public ArrayList<BrandAgencyData> getAgencyList() {
            return agencyList;
        }
        public void setAgencyList(ArrayList<BrandAgencyData> agencyList) {

            this.agencyList = agencyList;
        }
        public String getAgencyName() {
            return agencyName;
        }
        public void setAgencyName(String agencyName) {
            this.agencyName = agencyName;
        }

        public ActionErrors validate(ActionMapping mapping,
                HttpServletRequest request) {
            ActionErrors errors = new ActionErrors();

            return errors;
        }
    }

Struts-config.xml

我正在将请求发送到AdminAction,以便在操作类中查找代理商列表值

  <action path="/admineditview" name="UserRegistrationForm"
                scope="request" type="com.cts.assetserv.core.web.action.AdminAction"
                parameter="method">
                <forward name="Success" path="/jsp/Adminprofile.jsp" />
                <forward name="Error" path="/jsp/ErrorPage.jsp" />

    </action>

AdminAction.java

在表单bean中设置agencyList值。

public ActionForward modify(ActionMapping mapping, 
                            ActionForm form,
                            HttpServletRequest request, 
                            HttpServletResponse response)
       throws Exception {

  ActionForward actionForward = mapping.findForward(AssetServConstants.SUCCESS);
  UserRegistrationForm registrationForm = (UserRegistrationForm) form;

  ArrayList<BrandAgencyData> pepsiList = new ArrayList<BrandAgencyData>();
  pepsiList.add(new BrandAgencyData("1", "USA"));
  pepsiList.add(new BrandAgencyData("2", "Canada"));
  pepsiList.add(new BrandAgencyData("3", "Mexico"));

  registrationForm.setAgencyList(pepsiList);

  return actionForward;
}

BrandAgencyData.java

维护每个下拉列表的标签和值,并将相同的对象列表发送到代理商列表以进行下拉。

import java.util.ArrayList;

public class BrandAgencyData {
private String agncyId;
private String agncyName;

@Override
public String toString() {
  return "BrandAgencyData [agncyId=" + agncyId + ", agncyName=" + agncyName + "]";
}

public BrandAgencyData(String agncyId, String agncyName){
  this.agncyId = agncyId;
  this.agncyName = agncyName;
}

错误详细信息

rg.apache.jasper.JasperException: An exception occurred processing JSP page /jsp/Adminprofile_body.jsp at line 197

194:                        <label for="agencyName">Agency Name </label>
195:                          <html:select property="agencyName" >
196:                             <html:option value="0">Select Agency</html:option>
197:                             <html:optionsCollection name="UserRegistrationForm" property="agencyList" label="agncyId" value="agncyName" />
198:                         </html:select>
199:                        </div>
200:                        

javax.servlet.ServletException: javax.servlet.jsp.JspException: Failed to obtain specified collection
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:916)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:845)
    org.apache.jsp.jsp.adminviewprofile_005fbody_jsp._jspService(adminviewprofile_005fbody_jsp.java:708)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)

0 个答案:

没有答案