You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Tom Bednarz <li...@bednarz.ch> on 2006/09/03 18:45:35 UTC

Problems to fill a DropDownListbox on a DynaValidatorActionForm

I try to fill a DropDownListbox on a DynaValidatorActionForm and get the 
following exception:

2006-09-03 18:20:45,007 ERROR [http-8080-1] [/mtweb].[jsp] 
(ApplicationDispatcher.java:704)     - Servlet.service() for servlet jsp 
threw exception
javax.servlet.jsp.JspException: Cannot find bean under name 
[ch.smartsol.bl.TxpExpense$ExpenseType@1860045, 
ch.smartsol.bl.TxpExpense$ExpenseType@7bb2cb, 
ch.smartsol.bl.TxpExpense$ExpenseType@1172fb9, 
ch.smartsol.bl.TxpExpense$ExpenseType@13e4653, 
ch.smartsol.bl.TxpExpense$ExpenseType@17b2712, 
ch.smartsol.bl.TxpExpense$ExpenseType@423da9]
	at 
org.apache.struts.taglib.html.OptionsTag.getIterator(OptionsTag.java:366)
	at org.apache.struts.taglib.html.OptionsTag.doEndTag(OptionsTag.java:186)
	at 
org.apache.jsp.form.editExpense_jsp._jspx_meth_html_options_0(org.apache.jsp.form.editExpense_jsp:553)
....

I have the follwoing definition in struts-config.xml:

<form-bean name="editExpenseForm" 
type="org.apache.struts.action.DynaActionForm">
   <form-property name="expenseType" type="java.lang.String" />
   <form-property name="expenseName" type="java.lang.String" />
   <form-property name="expenseId" type="java.lang.String" />
   <form-property name="expenseDescription" type="java.lang.String" />
   <form-property name="expenseLocation" type="java.lang.String"/>
   <form-property name="expenseAmount" type="java.lang.String"/>
   <form-property name="expenseIsoCurrency" type="java.lang.String"/>
   <form-property name="expenseReceiptNo" type="java.lang.String"/>
   <form-property name="expenseTime" type="java.lang.String"/>
   <form-property name="expensePaymentMethodID" type="java.lang.String"/>
   <form-property name="expenseCrossrate" type="java.lang.String"/>
   <form-property name="expenseProjectId" type="java.lang.String"/>
</form-bean>

expenseType should be the SELECTED item of a drop-down-listbox. I do 
have a business object containing a java.util.Vector of expenseTypes.
In my JSP file I have:

....
<html:select property="expenseType">
   <html:options collection="${sessionScope.expense.expenseTypes}"
       property="typeCode" labelProperty="typeDescription"/>
</html:select>			

I also tried:

<html:select property="expenseType">
   <c:forEach items="${sessionScope.expense.expenseTypes}" var="record">
     <html:optionsCollection label="${record.typeDescription}"
         value="${record.typeCode}" />
   </c:forEach>
</html:select>			

but also without any success!

The business object is defined as follows with the containing class 
ExpenseType:

public class TxpExpense extends trixpertObject
{
   .....

   private Vector expenseTypes = new Vector();
   ......
   public synchronized Vector getExpenseTypes()
   {
	return expenseTypes;
   }
   public synchronized void setExpenseTypes(Vector expenseTypes)
   {
	this.expenseTypes = expenseTypes;
   }
   ......
   // somewhere is code which retrieves data
   // from a database to fill instances of
   // class ExpenseType into the Vector
   // expenseTypes

   //
   // an inner class as bean for ExpenseTypes
   //
   public class ExpenseType
   {
     long typeCode;
     String typeDescription;

     public ExpenseType()
     {
     }
		
     public ExpenseType(long typeCode, String typeDescription)
     {
       this.typeCode = typeCode;
       this.typeDescription = typeDescription;
     }

     ... correct getters and setters
   }
}



What am I doing wrong? Why can the type ExpenseType not be found? Is it 
a problem to define it as inner class?

Many thanks for your help!

Tom

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Problems to fill a DropDownListbox on a DynaValidatorActionForm

Posted by Tom Bednarz <li...@bednarz.ch>.
Richard,

Many thanks for your feedback. This means I have to store the data 
twice. I tried that but now I get another error:

2006-09-04 09:45:17,339 ERROR [http-8080-1] [/mtweb].[jsp] 
(ApplicationDispatcher.java:704)     - Servlet.service() for servlet jsp 
threw exception
javax.servlet.jsp.JspException: Cannot create iterator for 
DynaActionForm[dynaClass=editExpenseForm,.....

There seems still be something wrong...

Tom



Richard Yee wrote:
> Tom,
> Try this for your <options> tag instead:
> 
>  <html:options collection="expenseTypes"
>      property="typeCode" labelProperty="typeDescription"/>
> 
> This will work if your have an attribute called "expenseTypes" in some 
> scope (ie. session, request).
> The options tag collection attribute expects the name of the collection, 
> not the collection itself.
> 
> -Richard
> 
> Tom Bednarz wrote:
>> I try to fill a DropDownListbox on a DynaValidatorActionForm and get 
>> the following exception:
>>
>> 2006-09-03 18:20:45,007 ERROR [http-8080-1] [/mtweb].[jsp] 
>> (ApplicationDispatcher.java:704)     - Servlet.service() for servlet 
>> jsp threw exception
>> javax.servlet.jsp.JspException: Cannot find bean under name 
>> [ch.smartsol.bl.TxpExpense$ExpenseType@1860045, 
>> ch.smartsol.bl.TxpExpense$ExpenseType@7bb2cb, 
>> ch.smartsol.bl.TxpExpense$ExpenseType@1172fb9, 
>> ch.smartsol.bl.TxpExpense$ExpenseType@13e4653, 
>> ch.smartsol.bl.TxpExpense$ExpenseType@17b2712, 
>> ch.smartsol.bl.TxpExpense$ExpenseType@423da9]
>>     at 
>> org.apache.struts.taglib.html.OptionsTag.getIterator(OptionsTag.java:366)
>>     at 
>> org.apache.struts.taglib.html.OptionsTag.doEndTag(OptionsTag.java:186)
>>     at 
>> org.apache.jsp.form.editExpense_jsp._jspx_meth_html_options_0(org.apache.jsp.form.editExpense_jsp:553) 
>>
>> ....
>>
>> I have the follwoing definition in struts-config.xml:
>>
>> <form-bean name="editExpenseForm" 
>> type="org.apache.struts.action.DynaActionForm">
>>   <form-property name="expenseType" type="java.lang.String" />
>>   <form-property name="expenseName" type="java.lang.String" />
>>   <form-property name="expenseId" type="java.lang.String" />
>>   <form-property name="expenseDescription" type="java.lang.String" />
>>   <form-property name="expenseLocation" type="java.lang.String"/>
>>   <form-property name="expenseAmount" type="java.lang.String"/>
>>   <form-property name="expenseIsoCurrency" type="java.lang.String"/>
>>   <form-property name="expenseReceiptNo" type="java.lang.String"/>
>>   <form-property name="expenseTime" type="java.lang.String"/>
>>   <form-property name="expensePaymentMethodID" type="java.lang.String"/>
>>   <form-property name="expenseCrossrate" type="java.lang.String"/>
>>   <form-property name="expenseProjectId" type="java.lang.String"/>
>> </form-bean>
>>
>> expenseType should be the SELECTED item of a drop-down-listbox. I do 
>> have a business object containing a java.util.Vector of expenseTypes.
>> In my JSP file I have:
>>
>> ....
>> <html:select property="expenseType">
>>   <html:options collection="${sessionScope.expense.expenseTypes}"
>>       property="typeCode" labelProperty="typeDescription"/>
>> </html:select>          
>> I also tried:
>>
>> <html:select property="expenseType">
>>   <c:forEach items="${sessionScope.expense.expenseTypes}" var="record">
>>     <html:optionsCollection label="${record.typeDescription}"
>>         value="${record.typeCode}" />
>>   </c:forEach>
>> </html:select>          
>> but also without any success!
>>
>> The business object is defined as follows with the containing class 
>> ExpenseType:
>>
>> public class TxpExpense extends trixpertObject
>> {
>>   .....
>>
>>   private Vector expenseTypes = new Vector();
>>   ......
>>   public synchronized Vector getExpenseTypes()
>>   {
>>     return expenseTypes;
>>   }
>>   public synchronized void setExpenseTypes(Vector expenseTypes)
>>   {
>>     this.expenseTypes = expenseTypes;
>>   }
>>   ......
>>   // somewhere is code which retrieves data
>>   // from a database to fill instances of
>>   // class ExpenseType into the Vector
>>   // expenseTypes
>>
>>   //
>>   // an inner class as bean for ExpenseTypes
>>   //
>>   public class ExpenseType
>>   {
>>     long typeCode;
>>     String typeDescription;
>>
>>     public ExpenseType()
>>     {
>>     }
>>            public ExpenseType(long typeCode, String typeDescription)
>>     {
>>       this.typeCode = typeCode;
>>       this.typeDescription = typeDescription;
>>     }
>>
>>     ... correct getters and setters
>>   }
>> }
>>
>>
>>
>> What am I doing wrong? Why can the type ExpenseType not be found? Is 
>> it a problem to define it as inner class?
>>
>> Many thanks for your help!
>>
>> Tom
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Problems to fill a DropDownListbox on a DynaValidatorActionForm

Posted by Richard Yee <ry...@cruzio.com>.
Tom,
Try this for your <options> tag instead:

  <html:options collection="expenseTypes"
      property="typeCode" labelProperty="typeDescription"/>

This will work if your have an attribute called "expenseTypes" in some 
scope (ie. session, request).
The options tag collection attribute expects the name of the collection, 
not the collection itself.

-Richard

Tom Bednarz wrote:
> I try to fill a DropDownListbox on a DynaValidatorActionForm and get 
> the following exception:
>
> 2006-09-03 18:20:45,007 ERROR [http-8080-1] [/mtweb].[jsp] 
> (ApplicationDispatcher.java:704)     - Servlet.service() for servlet 
> jsp threw exception
> javax.servlet.jsp.JspException: Cannot find bean under name 
> [ch.smartsol.bl.TxpExpense$ExpenseType@1860045, 
> ch.smartsol.bl.TxpExpense$ExpenseType@7bb2cb, 
> ch.smartsol.bl.TxpExpense$ExpenseType@1172fb9, 
> ch.smartsol.bl.TxpExpense$ExpenseType@13e4653, 
> ch.smartsol.bl.TxpExpense$ExpenseType@17b2712, 
> ch.smartsol.bl.TxpExpense$ExpenseType@423da9]
>     at 
> org.apache.struts.taglib.html.OptionsTag.getIterator(OptionsTag.java:366)
>     at 
> org.apache.struts.taglib.html.OptionsTag.doEndTag(OptionsTag.java:186)
>     at 
> org.apache.jsp.form.editExpense_jsp._jspx_meth_html_options_0(org.apache.jsp.form.editExpense_jsp:553) 
>
> ....
>
> I have the follwoing definition in struts-config.xml:
>
> <form-bean name="editExpenseForm" 
> type="org.apache.struts.action.DynaActionForm">
>   <form-property name="expenseType" type="java.lang.String" />
>   <form-property name="expenseName" type="java.lang.String" />
>   <form-property name="expenseId" type="java.lang.String" />
>   <form-property name="expenseDescription" type="java.lang.String" />
>   <form-property name="expenseLocation" type="java.lang.String"/>
>   <form-property name="expenseAmount" type="java.lang.String"/>
>   <form-property name="expenseIsoCurrency" type="java.lang.String"/>
>   <form-property name="expenseReceiptNo" type="java.lang.String"/>
>   <form-property name="expenseTime" type="java.lang.String"/>
>   <form-property name="expensePaymentMethodID" type="java.lang.String"/>
>   <form-property name="expenseCrossrate" type="java.lang.String"/>
>   <form-property name="expenseProjectId" type="java.lang.String"/>
> </form-bean>
>
> expenseType should be the SELECTED item of a drop-down-listbox. I do 
> have a business object containing a java.util.Vector of expenseTypes.
> In my JSP file I have:
>
> ....
> <html:select property="expenseType">
>   <html:options collection="${sessionScope.expense.expenseTypes}"
>       property="typeCode" labelProperty="typeDescription"/>
> </html:select>           
>
> I also tried:
>
> <html:select property="expenseType">
>   <c:forEach items="${sessionScope.expense.expenseTypes}" var="record">
>     <html:optionsCollection label="${record.typeDescription}"
>         value="${record.typeCode}" />
>   </c:forEach>
> </html:select>           
>
> but also without any success!
>
> The business object is defined as follows with the containing class 
> ExpenseType:
>
> public class TxpExpense extends trixpertObject
> {
>   .....
>
>   private Vector expenseTypes = new Vector();
>   ......
>   public synchronized Vector getExpenseTypes()
>   {
>     return expenseTypes;
>   }
>   public synchronized void setExpenseTypes(Vector expenseTypes)
>   {
>     this.expenseTypes = expenseTypes;
>   }
>   ......
>   // somewhere is code which retrieves data
>   // from a database to fill instances of
>   // class ExpenseType into the Vector
>   // expenseTypes
>
>   //
>   // an inner class as bean for ExpenseTypes
>   //
>   public class ExpenseType
>   {
>     long typeCode;
>     String typeDescription;
>
>     public ExpenseType()
>     {
>     }
>        
>     public ExpenseType(long typeCode, String typeDescription)
>     {
>       this.typeCode = typeCode;
>       this.typeDescription = typeDescription;
>     }
>
>     ... correct getters and setters
>   }
> }
>
>
>
> What am I doing wrong? Why can the type ExpenseType not be found? Is 
> it a problem to define it as inner class?
>
> Many thanks for your help!
>
> Tom
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org