I didn't read the whole thing, please excuse.  The only thing I notices
is that you seem to be misusing the naming conventions.

I don't know if I can explain this simply but here goes.

        In you classes the objects are named

                private <type> objectname

        The getter method is

                public <type> getObjectname() { return object; }

        The setter method is

                public void setObjectname(<type> newval) { objectname =
newval; }

        In the jsp you would use

                property='objectname'

Basically when you are specifing the object (in the class and in the
jsp) you use the exact variable name and the first character CANNOT be
uppercase.  When you are writing the methods you specify get/set and the
first letter uppercase and the rest of the object name.   In the JSP
sample you gave you used the getter method name, not the property name.

Let me know if that helps

Edgar
        
        

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:tbachta@;kcp.com] 
Sent: Friday, November 08, 2002 10:36 AM
To: 'Struts Users Mailing List'
Subject: RE: select and option tag issues



Ok I am still getting an error, the error is:

javax.servlet.jsp.JspException: No getter method available for property
getLocationValues for bean under name null


here is the code form the class that extends ActionForm

  private ArrayList getDataValues(String sql, String varaible)
  {

    ArrayList list = new ArrayList();


    Connection conn = null;
    Statement stmt = null;
    ResultSet rs = null;

    ServletContext context = servlet.getServletContext();
    DataSource dataSource = (DataSource)
context.getAttribute(Action.DATA_SOURCE_KEY);

    try
    {

      conn = dataSource.getConnection();
      stmt = conn.createStatement();
      rs = stmt.executeQuery(sql);

      while(rs.next())
      {
        System.out.println("here");
        String value = rs.getString(varaible);
        list.add(value);
      }

    }
    catch(Exception e)
    {
      System.out.println("ERROR GETTING NUMBER  "+e);
    }
    finally
    {
      if(rs != null)
      {
        try
        {
          rs.close();
        }
        catch(SQLException e)
        {
          System.out.println(e.getMessage());
        }
        rs = null;
      }
      if(stmt != null)
      {
        try
        {
          stmt.close();
        }
        catch(SQLException e)
        {
          System.out.println(e.getMessage());
        }
        stmt = null;
      }
      if(conn != null)
      {
        try
        {
          conn.close();
        }
        catch(SQLException e)
        {
          System.out.println(e.getMessage());
        }
        conn = null;
      }
    }

    return(list);
  }

  public ArrayList getLocationValues()
  {
    ArrayList values = new ArrayList();
    String sql = "select id from locations";
    values = getDataValues(sql, "id");

    return(values);
  }

  public ArrayList getLocationLables()
  {
    ArrayList lables = new ArrayList();
    String sql = "select location from locations";
    lables = getDataValues(sql, "location");

    return(lables);
  }

here is the code from the jsp

<td><html:select property="major_locations">
                      <html:options property ="getLocationValues"
labelProperty="getLocationLables"/>
                      </html:select></td>


What am I doing wrong?  I am very confused. Please help

Tim Bachta
Information Technology
MC 48
816-997-7137


 

                      "edgar"

                      <edgar@blue-moose        To:       "'Struts Users
Mailing List'" <[EMAIL PROTECTED]>          
                      .net>                    cc:

                                               Subject:  RE: select and
option tag issues                                        
                      11/08/2002 08:08

                      AM

                      Please respond to

                      "Struts Users

                      Mailing List"

 

 





In your form create two ArrayLists one for the values, one for the
labels.  If the data doesn't change much you can make them static.
Create getter methods for them which populate the arraylists from you
database (make sure you populate them in the same order so the labels
correspond to the values.  Then in your jsp do

             <html:select property='dbfield'>
                         <html:options property='arraylistofvalues'
labelProperty='arraylistoflabels' />
             </html:select>

If you have really static stuff you can stick the above arraylists in
the session or the context and use

             <html:select property='dbfield'>
                         <html:options name='attributelabelname'
labelName='attributevaluename' />
             </html:select>

Hope this helps.

Edgar
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:tbachta@;kcp.com]
Sent: Friday, November 08, 2002 8:50 AM
To: 'Struts Users Mailing List'
Subject: Re: select and option tag issues



I posted this question a couple of days ago and received an answer.
Unfortunately the answer does not work for me.  The problem I am having
is on the initial page of my web application I have drop-down boxes that
I want to be populated with information from a database.  I have no
problem getting the recordset but do not know how to transfer that
recordset data into the drop-downs.  I was able to populate the
drop-downs similar to the example used in the documentation but that
does not have  an example of how to populate them with live data.  Can
anyone give me a quick lesson on how to do this. Tim Bachta Information
Technology MC 48 816-997-7137




                      Eddie Bush

                      <[EMAIL PROTECTED]        To:       Struts Users
Mailing List <[EMAIL PROTECTED]>
                      t>                       cc:

                                               Subject:  Re: select and
option tag issues
                      11/06/2002 11:52

                      AM

                      Please respond to

                      "Struts Users

                      Mailing List"









Have you discovered the collection attribute of the options tag?  Your
action can build any collection you desire (ie from a database -- see
org.apache.struts.util.LabelValueBean for holding the name/value pairs).
It then places that collection into some scope (whichever you like) and
forwards to the page.  Now, by specifying the key you used when placing
the collection into scope as the value to the collection attribute of
the options tag, you've got a dynamic drop-down populated from the
database.

------------- in your Action subclass

Collection c = ...;

while (...)
{
    String label = ...;
    String value = ...;
    c.add(new LabelValueBean(label, value));
}

request.setAttribute("myCollection", c);

------------- in your JSP

<html:select ... >
    <html:options collection="c" ... />
</html:select>

(This isn't in the FAQ, is it?  <goes-to-check/>)

[EMAIL PROTECTED] wrote:

>Hi all,
>
>I am very new to struts and I am trying to create combo boxes using the

><html:select><html:options> tags.  I have been able to create and 
>populate them with string arrays placed on the JSP page similar to the 
>examples in the documentation.  What I really need to do is populate 
>them based on information in a database.  I can create the recordset 
>but after that I am lost.  Can anyone please help.  Thank you. Tim 
>Bachta
>
>Tim Bachta
>

--
Eddie Bush





--
To unsubscribe, e-mail:   <
mailto:struts-user-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <
mailto:struts-user-help@;jakarta.apache.org>







--
To unsubscribe, e-mail:
<mailto:struts-user-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail:
<mailto:struts-user-help@;jakarta.apache.org>


--
To unsubscribe, e-mail:   <
mailto:struts-user-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <
mailto:struts-user-help@;jakarta.apache.org>







--
To unsubscribe, e-mail:
<mailto:struts-user-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail:
<mailto:struts-user-help@;jakarta.apache.org>


--
To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@;jakarta.apache.org>

Reply via email to