# Problem mit html:optionsCollection



## cactie (13. Okt 2006)

Hallo zusammen, ich benutze htmlptionsCollection, um einen Combobox zu generieren. Das Problem ist, dass der Wert nicht im Combobox angezeigt werden kann.

Hier ist mein Code

index.jsp

<%@ page language="java"%> 
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%> 
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
<title>CSV Export</title> 
</head> 
<body> 
<html:form action="/ChooseHeader"> 
<table width="80%" align="center"> 
<tr> 
<td>Destination</td> 
</tr> 
<tr> 
<td><html:select property="destination" name="ChooseHeaderFormBean"> 
<htmlptionsCollection name="ChooseHeaderFormBean" property="destination"/> 
</html:select></td> 
</tr> 
<tr> 
<td colspan="1"><html:submit /></td> 
</tr> 
</table> 
</html:form> 
</body> 
</html> 


struts-config 

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd"> 
<struts-config> 


<data-sources> 
</data-sources> 


<form-beans> 
<form-bean type="test.forms.ChooseHeaderFormBean" name="ChooseHeaderFormBean"> 

</form-bean> 
</form-beans> 


<global-exceptions> 
</global-exceptions> 


<global-forwards> 
</global-forwards> 


<action-mappings> 
<action path="/ChooseHeader" type="test.action.HeaderAction" name="ChooseHeaderFormBean" scope="session" input="/index.jsp"> 
<forward path="/WEB-INF/pms_query.jsp" name="pms_success"> 
</forward> 
</action> 
</action-mappings> 


<message-resources parameter="test.resources.ApplicationResources"/> 

</struts-config> 


HeaderAction


```
package test.action; 

import java.util.ArrayList; 
import java.util.Vector; 

import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 
import javax.servlet.http.HttpSession; 

import org.apache.struts.action.Action; 
import org.apache.struts.action.ActionForm; 
import org.apache.struts.action.ActionForward; 
import org.apache.struts.action.ActionMapping; 
import org.apache.struts.util.LabelValueBean; 

import test.forms.ChooseHeaderFormBean; 



public final class HeaderAction extends Action { 

    public HeaderAction() { 

    } 

    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse respons) throws Exception { 

        ChooseHeaderFormBean chooseHeaderFormBean = (ChooseHeaderFormBean) form; 
         
        Vector entries = new Vector(10); 
        entries.add(new LabelValueBean("PMS","0")); 
        entries.add(new LabelValueBean("SDK","1")); 
        chooseHeaderFormBean.setDestination(entries); 
         

            return (mapping.findForward("pms_success")); 
    } 

}
```


FormBean


```
package test.forms; 

import java.util.Collection; 
import java.util.Vector; 

import org.apache.struts.action.ActionForm; 
import org.apache.struts.util.LabelValueBean; 



public class ChooseHeaderFormBean extends ActionForm{ 
    /** 
     *  
     */ 
    private static final long serialVersionUID = 1L; 
     
    int destinationID; 
    String destinationName; 
    String selectedHeader = ""; 
    Collection destination; 
     
    public ChooseHeaderFormBean(){ 

    } 

    public String getSelectedHeader() { 
        return selectedHeader; 
    } 

    public void setSelectedHeader(String selectedHeader) { 
        this.selectedHeader = selectedHeader; 
    } 

    public int getDestinationID() { 
         
        return destinationID; 
    } 

    public void setDestinationID(int destinationID) { 
        this.destinationID = destinationID; 
    } 

    public String getDestinationName() { 
        
        return destinationName; 
    } 

    public void setDestinationName(String destinationName) { 
        this.destinationName = destinationName; 
         
    } 

    public Collection getDestination() { 
        return destination; 
    } 

    public void setDestination(Collection destination) { 
        this.destination = destination; 
    } 
         

}
```

Kann jemand mir sagen, was ich hier falsch gemacht habe?


----------



## HLX (13. Okt 2006)

<htmlptionsCollection> ist für eine Collection von Beans gedacht. Verwende für deine Combobox das "options"-Tag:


```
<html:select property="destinationName"> 
    <html:options property="destination" labelProperty="destination" />
</html:select>
```


----------



## cactie (13. Okt 2006)

danke HLX, aber jetzt bekomme ich eine Fehlmeldung

javax.servlet.jsp.JspException: No getter method available for property destination for bean under name null
	org.apache.struts.taglib.html.OptionsTag.getIterator(OptionsTag.java:397)
	org.apache.struts.taglib.html.OptionsTag.doEndTag(OptionsTag.java:243)
	org.apache.jsp.index1_jsp._jspx_meth_html_options_0(index1_jsp.java:181)
	org.apache.jsp.index1_jsp._jspx_meth_html_select_0(index1_jsp.java:153)
	org.apache.jsp.index1_jsp._jspx_meth_html_form_0(index1_jsp.java:112)
	org.apache.jsp.index1_jsp._jspService(index1_jsp.java:76)
	org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


----------



## SlaterB (13. Okt 2006)

code? 
name null klingt ja nach falscher Bedienung


----------



## cactie (13. Okt 2006)

schon erledigt.


----------

