• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

html:select html:options error, no getter. please help

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know that similar errors are very common, and I've read hundreds (feels like) of posts about this, but still haven't been able to get it to work for me. So, I apologize for any repetition, but I would appreciate any help anyone can give me.

Thank you in advance for your assistance,
Peter

I'm creating a collection (ArrayList) that I want to use for a form's select list. I've been trying to use the "html ptions collection" tag to populate the select list, but when I try to do that, it says it can't find the getter for the protocols, even though it's there, and the case is correct. I'm sure I'm not understanding something pretty basic, but have no idea what that could be. Thanks.

JSP page:

<%@ page language="java" contentType="text/html" %>
<%@ page import="java.util.ArrayList, com.gene.bdllts.bean.projects" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>

<html:html>
<head>
<title>Scheduling Data</title>
</head>

<body>

<html:form action="/deDom">

<jsp:useBean id="bdlLtsOclProtocols" scope="session" class="com.gene.bdllts.bean.bdlLtsOclProtocols"/>
<bean efine id="protocolList" name="bdlLtsOclProtocols" property="protocols"/>
<TABLE COLS="3" WIDTH="100%" BGCOLOR="#FFFF99">
<TR VALIGN="CENTER">
<TD VALIGN="CENTER">
<CENTER>Protocol: 
<html:select property="protocol">
<html ptions collection="protocolList" property="protocols"/>
</html:select>
<html:submit value="Go!" /></CENTER>
</TD>

</TR>
</TABLE>
</html:form>
</body>
</html:html>

Action Class:

package com.gene.bdllts.bean;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

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

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

public class deDomAction extends Action
{
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception{

Collection protocols = new ArrayList();
protocols.add("John");
protocols.add("Paul");
protocols.add("George");
protocols.add("Ringo");

request.setAttribute("protocols", protocols);
return mapping.findForward("deConfirm");
}
}

Form Bean:

package com.gene.bdllts.bean;

import java.text.*;
import java.util.*;
import org.apache.struts.action.*;
import javax.servlet.http.HttpServletRequest;

public class deDomForm extends ActionForm {
private String protocols= null;

public String getProtocols() {
return protocols;
} // getProtocols

public void setProtocols(String protocol) {
this.protocols = protocol;
} // setProtocols

public void reset(ActionMapping mapping, HttpServletRequest request) {
this.protocols=null;
} // reset

public ActionErrors validate(
ActionMapping mapping, HttpServletRequest request ) {
ActionErrors errors = new ActionErrors();

return errors;
} // actionErrors

} // deDomForm

struts-config.xml:

<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">

<struts-config>

<form-beans>
<form-bean
name="deDomForm"
type="com.gene.bdllts.bean.deDomForm"/>
<form-bean
name="bdlLtsOclProtocols"
type="com.gene.bdllts.bean.bdlOclProtocols"/>

</form-beans>

<action-mappings>

<action
path="/deDom"
type="com.gene.bdllts.bean.deDomAction"
name="deDomForm"
scope="request"
validate="true"
input="/pages/dataEntry2.jsp">
<forward name="deConfirm" path="/pages/deConfirm.jsp"/>
</action>

</action-mappings>

</struts-config>


The Error I get:

Error 500--Internal Server Error
javax.servlet.jsp.JspException: No getter method for property: "protocols" of bean: "bdlLtsOclProtocols"
at org.apache.struts.taglib.TagUtils.lookup(TagUtils.java:987)
at org.apache.struts.taglib.bean.DefineTag.doEndTag(DefineTag.java:230)
at jsp_servlet._pages.__dataentry2._jspService(__dataentry2.java:282)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:33)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:971)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:402)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:446)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:305)
at weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:301)
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1085)
at org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:263)
at org.apache.struts.action.RequestProcessor.internalModuleRelativeForward(RequestProcessor.java:1023)
at org.apache.struts.tiles.TilesRequestProcessor.internalModuleRelativeForward(TilesRequestProcessor.java:345)
at org.apache.struts.action.RequestProcessor.processForward(RequestProcessor.java:572)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:221)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:971)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:402)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:305)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6364)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:317)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3641)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2585)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Peter,
We are pleased to have you here with us in the Struts forum, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks,
Jeanne
Forum Bartender
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The <html:optionsCollection> tag is to be used when you have a collection of beans and you want one of the properties of the bean to represent the "value" of each <option> and another property to represent the label for that option. In your case, the label and the value are the same, and you don't have a collection of beans, but only a collection of Strings. In this case, you need to use the <html:options> tag.

Try this:

<html:options name="protocolList" />

You could also get rid of both the <jsp:usebean> and the <bean:define> tags and write:

<html:options name="bdlLtsOclProtocols" property="protocols" />

I know the documentation can be a bit confusing on this topic, but here is a link to it.
[ July 08, 2006: Message edited by: Merrill Higginson ]
 
peter cunningham
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply. When I remove the <jsp:usebean> and the <bean efine> tags, and have:

<%@ page import="com.gene.bdllts.bean.bdlLtsOclProtocols" %>

...

<html:select property="bdlLtsOclProtocols">
<html ptions name="bdlLtsOclProtocols" property="protocols" />
</html:select>

I get the error:

javax.servlet.jsp.JspException: No getter method available for property bdlLtsOclProtocols for bean under name org.apache.struts.taglib.html.BEAN

like it's looking for the getProtocols method in a generic struts bean rather than in the bdlLtsOclProtocols bean. Though before it was making that complaint about the bdlLtsOclProtocols bean.

I feel like I've tried just about every possible combination of options and select tags. Could it be a problem if the arrayList is coming from a different bean (bdlLtsOclProtocols) than the form is associated with? My understanding is that protocols in the form bean is a single string (the string that gets selected), whereas the for the select list, I'm using an arrayList.

Thank you again,
Peter
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is your <html:select> tag that is causing this error, not your <html:options> tag. The property of your <html:select> tag must match one of the properties in your deDomForm bean. Since there is no bdlLtsOclProtocols property, that's why you're getting the message.

Change:

<html:select property="bdlLtsOclProtocols">

to:

<html:select property="protocols">

like you had it originally.
[ July 12, 2006: Message edited by: Merrill Higginson ]
 
peter cunningham
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I apologize for my continued denseness, but it's still not working, even when I followed these suggestions.

Should I be populating my collection in the action class that forwards to the form? Or in the action class that goes from the form to the result page? It's still not clear to me how the collection fits in with the form, since the field in the form is a String, but my collection is an ArrayList.

With the following settings, I'm getting this error:

javax.servlet.jsp.JspException: No getter method available for property protocolss for bean under name px


Here's how it currently is:

dataEntry2.jsp page:

<html:form action="/deDom">
<jsp:useBean id="px" class="com.gene.bdllts.bean.bdlLtsOclProtocols" />

<html:select property="protocols">
<html ptions name="px" property="protocolss" />
</html:select>


deDomAction class:

Collection protocols = new ArrayList();
protocols = bdlLtsOclProtocols.getProtocolss();

request.setAttribute("protocols", protocols);
return mapping.findForward("deConfirm");


deDomForm class:

public class deDomForm extends ActionForm {
private String protocols = null;

public String getProtocols() {
return protocols;
} // getProtocols

public void setProtocols(String protocol) {
this.protocols = protocol;
} // setProtocols

public void reset(ActionMapping mapping, HttpServletRequest request) {
this.protocols = "**";
} // reset


struts-config:

<form-bean
name="deDomForm"
type="com.gene.bdllts.bean.deDomForm"/>
<action
path="/deDom"
type="com.gene.bdllts.bean.deDomAction"
name="deDomForm"
scope="request"
validate="true"
input="/pages/dataEntry2.jsp">
<forward name="deConfirm" path="/pages/deConfirm.jsp"/>
</action>



bdlLtsOclProtocols.java:

public static Collection getProtocolss() throws SQLException
{

Connection conn = null;
int recCount = 0;
protocolss = new ArrayList();

String sql = "SELECT '***' FROM DUAL "
+ "UNION "
+ "SELECT PROJECT_NAME "
+ "FROM PDB.PDB_PROJECTS "
+ "ORDER BY 1";

try {
conn = bisonConnection.getBisonConnection();
statement = conn.createStatement();

ResultSet rs2 = statement.executeQuery(sql);
while (rs2.next()) {
protocolss.add(rs2.getString(1));
recCount++;
}
} // end try block
catch (Exception e) {
System.err.println("ERROR: " + e.toString());
} // end catch block
finally {
if (statement != null) {
statement.close();
}
if (conn != null) {
conn.close();
}
} // end finally block
return protocolss;
} // getProtocolss
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think we need to go a different direction here. The reason you're not successful at creating this application is that you don't understand the basic principles behind Struts and the Struts tags. My advice is to take some time out from your project and do some Struts tutorials or read a book on struts to get a better understanding of how this all works, and then come back to your application.

Here are the basic principles I've been trying to get across:

1-When you have a select/options combination box, you have two separate data elements: The list of available options, and the option the user actually selects. These two elements are separate data, and they come from separate locations. The option the user actually selects is represented by the property in the <html:select> tag. The list of available options is represented by the name and or property in the <html:options> tag.
2-Before displaying a jsp containing a select/options box, you must first populate the list of available options. Otherwise you'll get an error.
3-Your ActionForm must have a property that matches the property name specified in the <html:select> tag. The ActionForm bean does not have to have a property representing the list of options. It may, but it doesn't have to. A list of options can either be a property in the ActionForm bean, or it can be a bean that is placed in a scope. I usually find it convenient to put it in the ActionForm bean.
4-When the user selects an option and submits the form, Struts will populate the property in the ActionForm bean that you specified in the <html:select> tag with the option selected by the user.

To illustrate these principles, here's a simple Struts application. You start the application by entering http://myserver/myapp/initSelection.do to call the /initSelection action. It forwards to the selectionPage.jsp. When the user makes a selection and presses the submit button, the /processSelection action is called. I've tested it and know for sure that it works. Here are the relevant pieces:

struts-config.xml

SelectionForm

InitSelectionAction

OptionsPopulator

selectionPage.jsp

ProcessSelectionAction

[ July 16, 2006: Message edited by: Merrill Higginson ]
 
peter cunningham
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much, that definitely clears some things up.

If I wanted to store that arrayList in some kind of context so that it could be read by multiple pages, would the best way to do that be via a struts plugIn referenced in struts-config.xml? Or via an action for the login page? I looked at the plugIn interface, and the init method looks like a place to do that, but I'd have to put it into servletContext, which is difficult to access from a jsp. So maybe I should do it from a login action, but I'm not sure if that's frowned upon in the struts world

Maybe I'm going about this the wrong way, but I've looked at way too many tutorials and books, all of them saying different things

Thanks in advance,
Peter
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I looked at the plugIn interface, and the init method looks like a place to do that, but I'd have to put it into servletContext, which is difficult to access from a jsp



If you want to put a list of values in Application scope (Same as ServletContext) so everyone can use it, the init() method of a class that implements the Plugin interface is a very good place to populate it. If the list is unique to one user, you should put the code in an Action class and store the bean in session scope.

Your statement that Application scope is difficult to access from a JSP is not at all true. When you specify a bean name and property in an <html ptions> tag, Struts searches for the bean in all scopes, including application scope.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic