• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

JasperException: Cannot find bean under name contractors

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I keep getting errors trying to do html:select/html:options in a form. I'm not understanding how to code the tag, whether with property or collection attributes and how the interaction works with the Action class and the struts-config.xml. Can someone show me the syntax for all three files, please? I'm looking for a simple implementation. Here is what I've got:
JSP------------
<%@ page import="java.sql.*"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<html>
<head></head>
<body>
<html:form action="/select">
<html:select property="select" >
<html:options property="names" />
</html:select>
</html:form>
</body>
</html>
STRUTS-CONFIG.XML---------------------
...
<form-beans>
<form-bean name="selectForm" type="com.test.struts.form.SelectForm">
<form-property name="select" />
<form-property name="names" type="java.lang.String" />
</form-bean>
</form-beans>
...
SELECTACTION.JAVA----------------------
try{
SelectForm selectForm = (SelectForm) form;
DataSource ds = (DataSource )servlet.getServletContext().getAttribute(Action.DATA_SOURCE_KEY);
Connection con = ds.getConnection();
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select LAST_NM from MY_TBL");
ArrayList arrayList= new ArrayList();
while(rs.next())
{
arrayList.add(new org.apache.struts.util.LabelValueBean(rs.getString(1)));
}
selectForm.setNames(al);
request.getSession().setAttribute("names", al);
SELECTFORM.JAVA---------------------
public class SelectForm extends ActionForm {
private String select;
private String names;
public String getSelect() { return select; }
public void setSelect(String select) { this.select = select; }
public String getNames() { return names; }
public void setNames(String names) { this.names= names; }
}
 
Jeff Horan
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, the error reads contractors, substitue names in there.
 
Sheriff
Posts: 67537
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is best moved to the Struts forum.
bear
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am having the same problem. I develop under WSAD 5.0 and in my localhost test environment, the code works fine and I get the expcected results. Once I package an EAR and deploy it to WebSphere Application Server 5.0, I get this error. Looking forward to a resolution. Thanks.....
 
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jeff,
If you are going to specify only the property attribute on the options tag, then Struts is going to look for a collection property on your form bean. The "names" property on your form isn't a collection, it's a String, so that may be your problem.
Also, you are putting a collection(an ArrayList) in the session called "names" as well, so I think you are mixing the syntax a bit. If you use the name attribute in conjunction with property attribute, then Struts will look for a bean with the name you give(in some scope). It will then look for a property on the bean contained in the collection that matches the property attribute. The property attribute of the options tag will then be the value returned when the form is submitted, in your case in the "select" field of the action form. The labelProperty attribute of the options tag will be the values shown to the user in the list, which you also get from the bean in the collection. Does that make sense?
Here is a little bit of the documentation on this at the Struts site:


The collection of values actually selected depends on the presence or absence of the name and property attributes. The following combinations are allowed:
Only name is specified - The value of this attribute is the name of a JSP bean in some scope that is the collection.
Only property is specified - The value of this attribute is the name of a property of the ActionForm bean associated with our form, which will return the collection.
Both name and property are specified - The value of the name attribute identifies a JSP bean in some scope. The value of the property attribute is the name of some property of that bean which will return the collection.


Here is the url to the quoted page:

HTML tags API

HTH,
E
 
Jeff Horan
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I solved my problem. I wanted to use an optionsCollection to display the results of a search. However, I'm working on a single page form jsp and the dropdown needed to display empty first and then the search would be clicked and a populated dropdown would appear. So the initial page wouldn't load because it couldn't see the bean needed, yet. So, a combination of using the bean:define and having to initialize my form property made it display. here is the code below:
JSP:
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<html>
<body>
<html:form action="/select">
<html:select property="neList">
<bean:define id="neName" name="selectForm" property="neName" type="java.util.ArrayList"/>
<html:optionsCollection name="neName"/>
</html:select>
<html:submit/><html:cancel/>
</html:form>
<body>
</html>
STRUTS-CONFIG.XML:
<!-- ========== Form Bean Definitions ================================== -->
<form-beans>
<form-bean name="selectForm" type="com.youcompany.struts.form.SelectForm">
<form-property name="neList" type="java.lang.String" />
<form-property name="neName" type="java.util.ArrayList" />
</form-bean>
</form-beans>
ACTION:
// Created by Xslt generator for Eclipse.
// XSL : not found (java.io.FileNotFoundException: (Bad file descriptor))
// Default XSL used : easystruts.jar$org.easystruts.xslgen.JavaClass.xsl
package com.youcompany.struts.action;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Iterator;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.sql.DataSource;
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 com.youcompany.struts.form.SelectForm;
/**
* SelectAction.java created by EasyStruts - XsltGen.
* http://easystruts.sf.net
* created on 12-03-2003
*
* XDoclet definition:
* @struts:action path="/select" name="selectForm" input="/form/select.jsp"
* @struts:action-forward name="\form\select.jsp" path="\form\select.jsp" redirect="true"
*/
public class SelectAction extends Action {
// --------------------------------------------------------- Instance Variables
// --------------------------------------------------------- Methods
/**
* Method execute
* @param ActionMapping mapping
* @param ActionForm form
* @param HttpServletRequest request
* @param HttpServletResponse response
* @return ActionForward
* @throws Exception
*/
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
SelectForm selectForm = (SelectForm) form;
return mapping.findForward("success");
}
}
FORM:
// Created by Xslt generator for Eclipse.
// XSL : not found (java.io.FileNotFoundException: (Bad file descriptor))
// Default XSL used : easystruts.jar$org.easystruts.xslgen.JavaClass.xsl
package com.youcompany.struts.form;
import java.util.ArrayList;
import org.apache.struts.action.ActionForm;
/**
* SelectForm.java created by EasyStruts - XsltGen.
* http://easystruts.sf.net
* created on 12-03-2003
*
* XDoclet definition:
* @struts:form name="selectForm"
*/
public class SelectForm extends ActionForm {
// --------------------------------------------------------- Instance Variables
/** neList property */
private String neList;
/** neName property */
private ArrayList neName = new ArrayList();
// --------------------------------------------------------- Methods
/**
* Returns the neList.
* @return String
*/
public String getNeList() {
return neList;
}
/**
* Set the neList.
* @param neList The neList to set
*/
public void setNeList(String neList) {
this.neList = neList;
}
/**
* Returns the neName.
* @return ArrayList
*/
public ArrayList getNeName() {
return neName;
}
/**
* Set the neName.
* @param neName The neName to set
*/
public void setNeName(ArrayList neName) {
this.neName = neName;
}
}
 
reply
    Bookmark Topic Watch Topic
  • New Topic