wood burning stoves 2.0*
The moose likes Struts and the fly likes BeanUtils.populate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "BeanUtils.populate" Watch "BeanUtils.populate" New topic
Author

BeanUtils.populate

Giomar Guevara
Ranch Hand

Joined: Oct 18, 2006
Posts: 51
When I try to submit a form I got this error and I have no idea what the problem can be, jsp code follows:

javax.servlet.ServletException: BeanUtils.populate
at org.apache.struts.util.RequestUtils.populate(RequestUtils.java:495)
at org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:805)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:203)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at com.ibmm.sam.hibernate.HibernateFilter.doFilter(HibernateFilter.java:49)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:534)

=============================

<html:form action="/sam/deleteRelationships">



<nested:notEmpty property="useList">
<tr bgcolor="#E6E6E6">
<td valign="top" align="left">
<img src="../images/spacer.gif" width="20"/><font class="label"><bean:message key="use" bundle="labels"/></font>
</td>
<td align="left" colspan="3">
<table border="0" cellpadding="0" cellspacing="0" width="95%">
<nested:iterate property="useList" indexId="iterateId">
<tr>
<td width="65%">
<nested:link action="/sam/editEntity"
paramId="id" paramProperty="entity2.entityId" target="main">
<font class="default"><nested:write property="entity2.preferredTerm.name"/></font>
</nested:link>
</td>
<td width="20%" align="right">
<nested:image property="deleted" src="../images/trash-can.gif" onclickk="deleteRelationships(this.form,this)"
alt="Delete Checked Relationship(s)" title="Delete Checked Relationship(s)" accesskey="D"/>
</td>

</tr>
</nested:iterate>
</table>
</td>
</tr>
<tr>
<td colspan="5" height="1">
</td>
</tr>
</nested:notEmpty>

<nested:notEmpty property="usedForList">
<tr>
<td nowrap valign="top" align="left">
<img src="../images/spacer.gif" width="20"/>
<font class="label"><bean:message key="used.for" bundle="labels"/></font>
</td>
<td align="left" colspan="2">
<table border="0" cellpadding="0" cellspacing="0" width="95%">
<nested:iterate property="usedForList">
<tr>
<td width="65%">
<nested:link action="/sam/editEntity"
paramId="id" paramProperty="entity2.entityId" target="main">
<font class="default"><nested:write property="entity2.preferredTerm.name"/></font>
</nested:link>
</td>
<td width="20%" align="right">
<nested:image property="deleted" src="../images/delete_img.gif" onclickk="deleteRelationships(this.form,this)"
alt="Delete Checked Relationship(s)" title="Delete Checked Relationship(s)" accesskey="D"/>
</td>
</tr>
</nested:iterate>
</table>
</td>
</tr>
<tr>
<td colspan="5" height="1">
</td>
</tr>
</nested:notEmpty>


<nested:notEmpty property="broaderList">
<tr bgcolor="#E6E6E6">
<td valign="top" align="left">
<img src="../images/spacer.gif" width="20"/>
<font class="label"><bean:message key="broader" bundle="labels"/></font>
</td>
<td align="left" colspan="2">
<table border="0" cellpadding="0" cellspacing="0" width="95%">
<nested:iterate property="broaderList">
<tr>
<td width="65%">
<nested:link action="/sam/editEntity"
paramId="id" paramProperty="entity2.entityId" target="main">
<font class="default"><nested:write property="entity2.preferredTerm.name"/></font>
</nested:link>
</td>
<td width="20%" align="right">

<nested:image property="deleted" src="../images/delete_img.gif" onclickk="deleteRelationships(this.form,this)"
alt="Delete Checked Relationship(s)" title="Delete Checked Relationship(s)" accesskey="D"/>
</td>
</tr>
</nested:iterate>
</table>
</td>
</tr>
</nested:notEmpty>
<tr>
<td colspan="5" height="1">
</td>
</tr>

<nested:notEmpty property="narrowerList">

<tr>


<td valign="top" align="left">
<img src="../images/spacer.gif" width="20"/>
<font class="label"><bean:message key="narrower" bundle="labels"/></font>
</td>
<td align="left" colspan="2">
<table border="0" cellpadding="0" cellspacing="0" width="95%">
<nested:iterate property="narrowerList">
<tr>
<td width="65%">
<nested:link action="/sam/editEntity"
paramId="id" paramProperty="entity2.entityId" target="main">
<font class="default"><nested:write property="entity2.preferredTerm.name"/></font>
</nested:link>
</td>
<td width="20%" align="right">

<nested:image property="deleted" src="../images/delete_img.gif" onclickk="deleteRelationships(this.form,this)"
alt="Delete Checked Relationship(s)" title="Delete Checked Relationship(s)" accesskey="D"/>
</td>
</tr>
</nested:iterate>
</table>
</td>
</tr>
<tr>
<tdcolspan="5" height="1">
</td>
</tr>
</nested:notEmpty>
<nested:notEmpty property="relatedList">
<tr bgcolor="#E6E6E6" >
<td valign="top" align="left">
<img src="../images/spacer.gif" width="20"/>
<font class="label"><bean:message key="related" bundle="labels"/></font>
</td>
<td align="left" colspan="2">
<table border="0" cellpadding="0" cellspacing="0" width="95%">
<nested:iterate property="relatedList">
<tr>
<td width="65%">
<nested:link action="/sam/editEntity"
paramId="id" paramProperty="entity2.entityId" target="main">
<font class="default"><nested:write property="entity2.preferredTerm.name"/></font>
</nested:link>
</td>
<td width="20%" align="right">

<nested:image property="deleted" src="../images/delete_img.gif" onclickk="deleteRelationships(this.form,this)"
alt="Delete Checked Relationship(s)" title="Delete Checked Relationship(s)" accesskey="D"/>
</td>
</tr>
</nested:iterate>
</table>
</td>
</tr>
</nested:notEmpty>
<tr>
<td>
</td>
</tr>
<tr>
<td colspan="5" >
<hr>
</td>
</tr>
</html:form>
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
This error generally occurs when you have a property in your ActionForm that is not a String or something that can be converted from a String. If you have any non-String properties in your ActionForm (i.e. java.util.Date, Integer, etc.) change then to Strings.


Merrill
Consultant, Sima Solutions
Giomar Guevara
Ranch Hand

Joined: Oct 18, 2006
Posts: 51
import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
I attached my form...can you please take a look at it?,I don't see anything wrong thanks...

import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;



public class EntityForm extends ValidatingForm {

private static final Logger LOGGER = Logger.getLogger(EntityForm.class);

// ------------------------------ FIELDS ------------------------------

//private String deleted;
private Entity entity;

private int hierarchyId;

private MultilingualHolder addedVariation;

private MultilingualHolder addedTerm;

private Relationship addedRelationship = new Relationship();

private int id = 0;

private int variationId;

private int preferredTermIndex;

private String addedRelationshipTermName = null;

private int addedRelationshipTypeCode;

private RelationshipTypeImpl[] relationshipTypeCodes;

private String newTermName;

private ArrayList availableAttributes;

private MultilingualHolder[] variations;

private MultilingualHolder[] terms;

private Collection kbases;

private static int i = 0;

private int instanceId;

private int termId;

// --------------------------- CONSTRUCTORS ---------------------------

public EntityForm() {

instanceId = i++;
}

// -------------------------- OTHER METHODS --------------------------

public Relationship getAddedRelationship() {
return addedRelationship;
}

public void setAddedRelationship(Relationship addedRelationship) {
this.addedRelationship = addedRelationship;
}

public String getAddedRelationshipTermName() {
return addedRelationshipTermName;
}

public void setAddedRelationshipTermName(String addedRelationshipTermName) {
this.addedRelationshipTermName = addedRelationshipTermName;
}

public int getAddedRelationshipTypeCode() {
return addedRelationshipTypeCode;
}

public void setAddedRelationshipTypeCode(int addedRelationshipTypeCode) {
this.addedRelationshipTypeCode = addedRelationshipTypeCode;
}

public MultilingualHolder getAddedTerm() {
return addedTerm;
}

public void setAddedTerm(MultilingualHolder addedTerm) {
this.addedTerm = addedTerm;
}

public MultilingualHolder getAddedVariation() {
if (LOGGER.isDebugEnabled())
LOGGER.debug("getting added variation " + addedVariation + " from "
+ instanceId);
return addedVariation;
}

public void setAddedVariation(MultilingualHolder addedVariation) {
if (LOGGER.isDebugEnabled())
LOGGER.debug("**************setting added variation "
+ addedVariation + " to " + instanceId);
this.addedVariation = addedVariation;
}

public ArrayList getAvailableAttributes() {
return availableAttributes;
}

public void setAvailableAttributes(ArrayList arrayList) {
availableAttributes = arrayList;
}

public LanguageImpl[] getPreferredTermLanguages() {

return (LanguageImpl[]) retrieveEntity().getPreferredTerm()
.getLanguages().toArray(new LanguageImpl[0]);
}

public void sortRelationships(List relationShipList) {
Collections.sort(relationShipList, new Comparator() {
public int compare(Object o1, Object o2) {
Relationship relation1 = (Relationship) o1;
Relationship relation2 = (Relationship) o2;
return getName(relation1).compareTo(getName(relation2));
}

private String getName(Relationship relationship) {
try {
return relationship.getEntity2().getPreferredTerm()
.getName();
} catch (NullPointerException ex) {
return "";
}
}
});
}

public ArrayList getBroaderList() {
ArrayList al = new ArrayList();
Set list = retrieveEntity().getRelationshipsTerm1();
for (Iterator iterator = list.iterator(); iterator.hasNext() {
Relationship relationship = (Relationship) iterator.next();
if (relationship.getRelationshipType().getCode().equals("BT")) {
al.add(relationship);
}
}
sortRelationships(al);
return al;
}

public Date getDateCreated() {
return retrieveEntity().getDateCreated();
}

public Date getDateUpdated() {
return retrieveEntity().getDateUpdated();
}

public int getEntityId() {
return retrieveEntity().getEntityId().intValue();
}

public Hierarchy getHierarchy() {
return retrieveEntity().getHierarchy();
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public ArrayList getNarrowerList() {
ArrayList al = new ArrayList();
Set list = retrieveEntity().getRelationshipsTerm1();
for (Iterator iterator = list.iterator(); iterator.hasNext() {
Relationship relationship = (Relationship) iterator.next();
if (relationship.getRelationshipType().getCode().equals("NT")) {
al.add(relationship);
}
}
sortRelationships(al);
return al;
}

public String getNewTermName() {
return newTermName;
}

public void setNewTermName(String newTermName) {
this.newTermName = newTermName;
}

public TermImpl getPreferredTerm() {
return (TermImpl) retrieveEntity().getPreferredTerm();
}

public int getPreferredTermIndex() {
return preferredTermIndex;
}

public void setPreferredTermIndex(int preferredTermIndex) {
this.preferredTermIndex = preferredTermIndex;
}

public ArrayList getRelatedList() {
ArrayList al = new ArrayList();
Set list = retrieveEntity().getRelationshipsTerm1();
for (Iterator iterator = list.iterator(); iterator.hasNext() {
Relationship relationship = (Relationship) iterator.next();
if (relationship.getRelationshipType().getCode().equals("RT")) {
al.add(relationship);
}
}
sortRelationships(al);
return al;
}

public RelationshipTypeImpl[] getRelationshipTypeCodes() {
return relationshipTypeCodes;
}

public void setRelationshipTypeCodes(
RelationshipTypeImpl[] relationshipTypeCodes) {
this.relationshipTypeCodes = relationshipTypeCodes;
}

public TermAttribute[] getTermAttributes() {
return (TermAttribute[]) retrieveEntity().getAttributes().toArray(
new TermAttribute[0]);
}

public MultilingualHolder[] getTermsWithLanguageCode() {
return terms;
}

public String getUpdateUser() {
return retrieveEntity().getUpdateUser();
}

public ArrayList getUseList() {
ArrayList al = new ArrayList();
Set list = retrieveEntity().getRelationshipsTerm1();
for (Iterator iterator = list.iterator(); iterator.hasNext() {
Relationship relationship = (Relationship) iterator.next();
if (relationship.getRelationshipType().getCode().equals("U")) {
al.add(relationship);
}
}
sortRelationships(al);
return al;
// return (Relationship[]) al.toArray(new Relationship[0]);
}

public ArrayList getUsedForList() {
ArrayList al = new ArrayList();
Set list = retrieveEntity().getRelationshipsTerm1();
for (Iterator iterator = list.iterator(); iterator.hasNext() {
Relationship relationship = (Relationship) iterator.next();
if (relationship.getRelationshipType().getCode().equals("UF")) {
al.add(relationship);
}
}
sortRelationships(al);
return al;
}

public String getUsername() {
return retrieveEntity().getUsername();
}

public MultilingualHolder[] getVariations() {
return variations;
}

public void setVariations(MultilingualHolder[] variations) {
this.variations = variations;
}

public MultilingualHolder[] getVariationsWithLanguageCode() {
return variations;
}

public void setBroaderList(Relationship[] broaderList) {
// todo this is probably wrong....
retrieveEntity().getRelationshipsTerm1()
.add(Arrays.asList(broaderList));
}

public void setEntityId(int entityId) {
retrieveEntity().setEntityId(new Integer(entityId));
}

public void setNarrowerList(Relationship[] useList) {
// todo this is probably wrong....
retrieveEntity().getRelationshipsTerm1().add(Arrays.asList(useList));
}

public void setRelatedList(Relationship[] useList) {
// todo this is probably wrong....
retrieveEntity().getRelationshipsTerm1().add(Arrays.asList(useList));
}

public void setTermAttributes(TermAttribute[] atts) {
retrieveEntity().getAttributes().clear();
retrieveEntity().getAttributes().addAll(Arrays.asList(atts));
}

public void setTermsWithLanguageCode(MultilingualHolder[] terms) {
this.terms = terms;
}

public void setUseList(Relationship[] useList) {
// todo this is probably wrong....
retrieveEntity().getRelationshipsTerm1().add(Arrays.asList(useList));
}

public void setUsedForList(Relationship[] useList) {
// todo this is probably wrong....
retrieveEntity().getRelationshipsTerm1().add(Arrays.asList(useList));
}

public void setVariationsWithLanguageCode(MultilingualHolder[] variations) {
this.variations = variations;
}

/**
* @return Returns the kbases.
*/
public Collection getKbases() {
return kbases;
}

/**
* @param kbases
* The kbases to set.
*/
public void setKbases(Collection kbases) {
this.kbases = kbases;
}

public Entity retrieveEntity() {

return entity;
}

public void setEntity(Entity entity) {
if (LOGGER.isDebugEnabled())
LOGGER.debug("setting entity in form to " + entity);
// TODO these two values need to be in sync, when outputting.
// TODO fixme
this.id = (entity.getId() == null) ? 0 : entity.getId().intValue();
this.entity = entity;
}

public int getHierarchyId() {
return hierarchyId;
}

public void setHierarchyId(int hierarchyId) {
this.hierarchyId = hierarchyId;
}

public int getVariationId() {
return variationId;
}

public void setVariationId(int variationId) {
this.variationId = variationId;
}

public void reset(ActionMapping am, HttpServletRequest req) {
ArrayList _listAttributes = getAvailableAttributes();
ArrayList _listAttributesReset = new ArrayList();
if (_listAttributes != null) {
for (int l = 0; l < _listAttributes.size(); l++) {
TermAttribute termAttribute = (TermAttribute) _listAttributes
.get(l);
termAttribute.setValue("");
_listAttributesReset.add(termAttribute);
}
setAvailableAttributes(_listAttributesReset);
}
}

public void validate(String action) {
if (action.equals("/sam/saveTerm")) {
required(newTermName, "newTermName", "Term name");
}

else if (action.equals("/sam/addEntityVariation")) {
required(((VariationImpl) addedVariation.getMultilingual())
.getName(), "addedVariation.multilingual.name",
"Variation name");
}

else if (action.equals("/sam/addRelationship")) {
required(addedRelationshipTermName, "addedRelationshipTermName",
"Relationship name");
}

}

public int getTermId() {
return this.termId;
}

public void setTermId(int termid) {
this.termId = termid;
}

}
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I can't really diagnose this problem just by looking at your Actionform. I do notice, though, that you have several non-String properties in your ActionForm. This in itself is not a problem, but if you have an input that references one of these properties, you will get the BeanUtils.populate error you presented in your first post. For example, if somewhere in your JSP you had written:

You would get the error because addedTerm is of type MiltilingualHolder, and Struts doesn't know how to convert the String that comes from the request into a MultilingualHolder object.

Look through your code and see if you can find any situations like this and change the code accordingly.
Giomar Guevara
Ranch Hand

Joined: Oct 18, 2006
Posts: 51
ok, thanks...
 
Don't get me started about those stupid light bulbs.
 
subject: BeanUtils.populate
 
Similar Threads
how to set the value of a boolean in javascript
XSLT: Transformer Configuration Exception
Retrieving values of nested tags
Problems with select
problems with form