aspose file tools*
The moose likes Struts and the fly likes hi i am getting an exception:BeanUtils.populate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "hi i am getting an exception:BeanUtils.populate" Watch "hi i am getting an exception:BeanUtils.populate" New topic
Author

hi i am getting an exception:BeanUtils.populate

Vissu javvaji
Greenhorn

Joined: Feb 01, 2013
Posts: 1
Hiiiiii ...i am new to struts1.3..since last few days i was fighting against an exception
javax.servlet.ServletException: javax.servlet.ServletException: BeanUtils.populate
root cause:
java.lang.IllegalArgumentException: Cannot invoke FlatForm.setArrList on bean class 'class FlatForm' - argument type mismatch - had objects of type "java.lang.String" but expected signature "java.util.List"

my code is:
------------
Flat.jsp
--------
<%@taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<body bgcolor="cyan" text="black">
<bean:message key="my.title"/>
<center>
<html:form action="/register">
<bean:message key="my.count"/>: <html:text property="count"/><br>
<html:submit>
<bean:message key="my.enter"/>
</html:submit>
</html:form>
</center>
</body>

Generation.jsp
----------------
<%@taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<body bgcolor="orange" text="black">
<bean:message key="my.title1"/>
<center>
<html:form action="/register1">
<bean:message key="my.count"/>: <html:text property="count"/><br>
<bean:message key="my.metro"/>: <html:text property="metro"/><br>
<bean:message key="my.total"/>: <html:text property="total"/><br>
<% if(request.getAttribute("noOfTextBoxes")!=null){
int noOfBoxes=(Integer)request.getAttribute("noOfTextBoxes");
for(int i=1;i<=noOfBoxes;i++){
%>
Enter <%=i%>th Flat Meter Reading:<html:text property="arrList"/><br>
<% }
} %><br>
<html:submit>
<bean:message key="my.enter1"/>
</html:submit>
</html:form>
</center>
</body>
Result.jsp
-----------
<%@taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<body bgcolor="pink" text="black">
<center><font size=6>Tables of Metro and Borewell Water</font>
<table border=1>
<tr>
<th>Metro Water</th>
</tr>
<logic:notEmpty name="mazlist" scope="request">
<logic:iterate id="listid" name="mazlist">
<tr>
<td><bean:write name="listid" property="manzera1"/></td>
</tr>
</logic:iterate>
</logic:notEmpty>
</table></br>
<table border=1>
<tr>
<th>Borewell Water</th>
</tr>
<logic:notEmpty name="borlist" scope="request">
<logic:iterate id="listid1" name="borlist">
<tr>
<td><bean:write name="listid1" property="borewell1"/></td>
</tr>
</logic:iterate>
</logic:notEmpty>
</table></br>
</center>
</body>

web.xml
------------
<web-app>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<load-on-startup>3</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>Flat.jsp</welcome-file>
</welcome-file-list>
</web-app>

struts.config.xml
-----------------
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
"http://struts.apache.org/dtds/struts-config_1_3.dtd">
<struts-config>
<form-beans>
<form-bean name="rf" type="FlatForm"/>
</form-beans>

<action-mappings>

<action path="/register" name="rf" type="FlatAction" scope="request">
<forward name="display" path="/Generation.jsp"/>
</action>

<action path="/register1" name="rf" type="FlatAction1" scope="request">
<forward name="result" path="/Result.jsp"/>
</action>

</action-mappings>

<message-resources parameter="myfile"/>

</struts-config>

myfile.properties
-----------------
#presentation labels
my.count=Enter the Total no of Flats
my.enter=Submit
my.title=<center><h1>A Mini Application of Calculating Average</h1><center>
my.title1=<center><h1>Consumption of metro and borewell water</h1><center>
my.metro=The Total Manzeraa Water is
my.total=The Total Consumed Water is
my.exit=Enter The readings
my.enter1=Calculate

FlatForm.java(formbean class)
---------------------------------
import org.apache.struts.action.*;
import java.io.*;
import java.util.*;
public class FlatForm extends ActionForm implements java.io.Serializable
{
private int count=0;
private int metro=0;
private int total=0;
private List<Integer> arrList=null;
Integer[] manzera=null;
Integer[] borewell=null;

public List getArrList() {
return arrList;
}

public void setArrList(List arrList) {
this.arrList = arrList;
}

public int getCount() {
return count;
}

public void setCount(int count) {
this.count = count;
}


public int getMetro() {
return metro;
}

public void setMetro(int metro) {
this.metro = metro;
}

public int getTotal() {
return total;
}

public void setTotal(int total) {
this.total = total;
}

public Integer[] getBorewell() {
return borewell;
}

public void setBorewell(Integer[] borewell) {
this.borewell = borewell;
}

public Integer[] getManzera() {
return manzera;
}

public void setManzera(Integer[] manzera) {
this.manzera = manzera;
}


}

FlatAction.java
---------------
import org.apache.struts.action.*;
import javax.servlet.http.*;
import javax.servlet.*;
import java.util.*;
public class FlatAction extends Action
{
public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response)throws Exception
{
FlatForm fm=(FlatForm)form;
int count=fm.getCount();
try{
request.setAttribute("noOfTextBoxes",count);
}catch(Exception e)
{
System.out.println(e);
}
return mapping.findForward("display");
}
}

FlatAction1.java

-----------------
import org.apache.struts.action.*;
import javax.servlet.http.*;
import javax.servlet.*;
import java.util.*;
import java.util.ArrayList.*;
import java.util.Arrays.*;
import java.lang.*;
public class FlatAction1 extends Action
{
public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response)
{
FlatForm fm=(FlatForm)form;
int count=fm.getCount();
System.out.println(count);
int metro=fm.getMetro();
System.out.println(metro);
int total=fm.getTotal();
System.out.println(total);
List<Integer> arrList=fm.getArrList();
ArrayList mazlist= new ArrayList();
ArrayList borlist= new ArrayList();
try{
int bore=total-metro;
System.out.println(bore);
int avg=metro/count;
System.out.println(avg);
Integer[] manzera=new Integer[count];
Integer[] borewell=new Integer[count];
Integer[] meter=new Integer[count];
arrList.toArray(meter);
for(int i=0;i<count;i++)
{
manzera[i]=avg;
borewell[i]=meter[i]-manzera[i];
}
FlatForm fm1=new FlatForm();
fm1.setManzera(manzera);
FlatForm fm2=new FlatForm();
fm2.setBorewell(borewell);
mazlist.add(fm1);
borlist.add(fm2);
request.setAttribute("mazlist",mazlist);
request.setAttribute("borlist",borlist);
}catch(Exception e){
System.out.println(e);
}
return mapping.findForward("result");
}
}

Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8908
    
    8

Welcome to the JavaRanch. You cannot enter a list of items by producing a bunch of form fields with the same name:

You must use indexed properties so the framework can rebuild the list of values.
By the way, please use code tags. They preserve your source code formatting and make your post easier to read.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: hi i am getting an exception:BeanUtils.populate