You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Tahir Awan <TA...@descartes.com> on 2002/08/07 22:55:38 UTC

RE: DynaBean and DynaClass

I tweaked my code a little bit but without any luck. 

Here's the modified code.

    DynaProperty props[] = new DynaProperty[] {
       new DynaProperty("name"),
       new DynaProperty("country") };

    BasicDynaClass cls = new BasicDynaClass("test",
        Class.forName("org.apache.commons.beanutils.BasicDynaBean"), props);

    DynaBean test = cls.newInstance();
    HashMap map = new HashMap();
    map.put("name", "tahir");
    map.put("country", "UK");
    BeanUtils.populate(test, map);
    pageContext.setAttribute("test", test, PageContext.PAGE_SCOPE);

and a scriptlet works fine like
	<%
	DynaBean tt = (DynaBean) pageContext.getAttribute("test",
PageContext.PAGE_SCOPE);
	out.println(tt.get("name"));
	%>

BUT bean:write still gives the same "No getter method for property name of
bean test" exception.
<bean:write name="test" property="name" />

please help !!!!!!!!!!!!!


-----Original Message-----
From: wbchmura@Ensign-BickfordInd.com
[mailto:wbchmura@Ensign-BickfordInd.com]
Sent: Wednesday, August 07, 2002 2:48 PM
To: struts-user@jakarta.apache.org
Subject: RE: DynaBean and DynaClass




The beans created below are passed to the JSP...

  /**
    * Converts a resultset into an ArrayList of DynaBeans
    * 
    * @param resultSet SQL result set to be converted
    * @return ArrayList of DynaBeans with all columnnames converted to
    *         lowercase
    * @throws SQLException DOCUMENT ME!
    */
   private static ArrayList getDynaBeanArrayList(ResultSet resultSet)
                                          throws SQLException {

      ResultSetMetaData metaData = resultSet.getMetaData();
      int cols = metaData.getColumnCount();
      ArrayList list = new ArrayList();
      DynaProperty[] props = new DynaProperty[cols];
      BasicDynaClass dClass = null;

      for (int i = 1; i <= cols; i++) {
         props[i - 1] = new 
DynaProperty(metaData.getColumnName(i).toLowerCase());
      }

      try {
         dClass = new BasicDynaClass("test", 
                                     Class.forName(
                                            
"org.apache.commons.beanutils.BasicDynaBean"), 
                                     props);
      } catch (Exception e) {
         e.printStackTrace();
      }

      while (resultSet.next()) {

         HashMap map = new HashMap(cols, 1);

         for (int i = 1; i <= cols; i++) {
            map.put(metaData.getColumnName(i).toLowerCase(), 
                    resultSet.getString(i));

            //System.out.println("Column name " + 
metaData.getColumnName(i).toLowerCase());
         }

         try {

            DynaBean dbean = dClass.newInstance();
            BeanUtils.populate(dbean, map);
            list.add(dbean);
         } catch (Exception e) {
            e.printStackTrace();
            throw new SQLException("RequestUtils.getArrayList: "
                                   + e.toString());
         }
      } // End While

      return (list);
   }

-----Original Message-----
From: TAwan [mailto:TAwan@descartes.com]
Sent: Wednesday, August 07, 2002 2:28 PM
To: struts-user
Subject: RE: DynaBean and DynaClass


Can you post some code snippets here so I can try to find out any
differences? Maybe its a different build I am using (Struts 1.1b) or a
configuration issue.
btw, The java code shown below was written within jsp as I am just 
trying to
learn how DynaBean can be used before moving it to controller servlet.

-----Original Message-----
From: wbchmura@Ensign-BickfordInd.com
[mailto:wbchmura@Ensign-BickfordInd.com]
Sent: Wednesday, August 07, 2002 12:53 PM
To: struts-user@jakarta.apache.org
Subject: RE: DynaBean and DynaClass



I am not sure what is wrong in your code, but I am using Dynabeans in my 

programs without using Struts to make them and have not had any 
insurmountable problems.  



-----Original Message-----
From: TAwan [mailto:TAwan@descartes.com]
Sent: Wednesday, August 07, 2002 11:42 AM
To: struts-user
Subject: DynaBean and DynaClass


Hi,
 
I'm trying to use DynaBean without going through the struts 
configurations.
Having read the package description for the beanUtils, the documentation 

is
unfortunately wrong. Below is the code in my jsp which initializes and 
sets
some properties in a DynaBean.
 
   DynaProperty pros[] = new DynaProperty[] 
    {
       new DynaProperty("name",      Class.forName("java.lang.String")),
       new DynaProperty("country",   Class.forName("java.lang.String")) 
};
 
    BasicDynaClass cls = new BasicDynaClass("test", null, pros);
 
    DynaBean test = cls.newInstance();
    test.set("name", "myName");
    test.set("country", "UK");

    pageContext.setAttribute("person", test, PageContext.PAGE_SCOPE);

 
when I try to print any of the property like
   <bean:write name="test" property="name" />
 
I always get this exception "No getter method for property name of bean
person"

 
Hope somebody is really using DynaBean.
 
Thanks,
Tahir


--
To unsubscribe, e-mail:   
<ma...@jakarta.apache.org>
For additional commands, e-mail: 
<ma...@jakarta.apache.org>



--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>

--
To unsubscribe, e-mail:   
<ma...@jakarta.apache.org>
For additional commands, e-mail: 
<ma...@jakarta.apache.org>



--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>