You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Michael McGrady <mi...@michaelmcgrady.com> on 2004/04/26 05:09:05 UTC

How do I submit code?

I got tired of trying to get some answers and listened to a couple of 
things Martin Fowler said on the users list and decided to just write my 
own tags.  I find I can write my own tags as easy as finding out how some 
of the existing ones work.  Some of that code is a little "dark"!  LOL

I have some code that I think improves PropertyUtils in commons and its 
ability to handle nested maps and other nested situations.  This also has a 
new class to go in with the bean options, which is really an improvement on 
the WriteTag in conjunction with changes to PropertyUtils in commons and 
RequestUtils in org.apache.struts.util.  I call the tag WriteMapTag and use 
it myself, as follows:

<map:write name="host" property="page(logon).key(bannerLeftColor)" 
scope="request" />

The central code for this is like the following:

public static Object getNestedProperty(Object bean,
                                          String property)
         throws IllegalAccessException,
                InvocationTargetException,
                NoSuchMethodException,
                ChainedException {
     Map map = null;
     if (bean == null) {
       throw new IllegalArgumentException("No bean specified");
     }
     if (property == null) {
       throw new IllegalArgumentException("No property specified");
     }
     int indexOfNESTED_DELIM = -1;
     int indexOfMAPPED_DELIM_L = -1;
     int indexOfMAPPED_DELIM_R = -1;
     String next = null;
     int loop = -1;
     if(!(bean instanceof Map)) {
       ChainedException ce = new ChainedException(new 
IllegalArgumentException("This is not a BeanMap object"), "This is not a 
BeanMap object.  The object is a " + bean);
       throw ce;
     }
     map = (Map)bean;
     String payload = null;
     while(true) {
       payload = property.substring(property.indexOf(MAPPED_DELIM_L) + 
1,property.indexOf(MAPPED_DELIM_R));
       loop = property.indexOf(NESTED_DELIM);
       if(loop > 0) {
         try {
           map = (Map)(map.get(payload));
         } catch (ClassCastException cce) {
           property = "Either you are using a class other than a map or you 
are burrowing too deep into the map.  The class cast exception trace is: " 
+ StackTrace.trace(cce);
           break;
         }
         property = property.substring(loop + 1);
       } else {
         break;
       }
     }
     // This need not return a string but it has to
     // return something whose payload is a string.
     return map.get(payload);
   } ///;-) Michael McGrady

With maps, the "page" and "key" are just toss ins.  If you specify a type 
atttribute, then these become method names with the parameters becoming 
arguments.  You get the idea.  How do I go about showing these to someone 
and seeing if they might be of some assistance?


RE: How do I submit code?

Posted by Michael McGrady <mi...@michaelmcgrady.com>.
Right!  Thanks!  Oops!  Sorry to both gentlemen!  Thanks.  I have written 
the tag for myself, but see that it could be written generally, if there is 
interest.  I think I will follow that procedure.  Sounds like the ticket.

At 08:49 PM 4/25/2004, Steve Raeburn wrote:
>I don't think Martin Fowler subscribes to the user list -- it'd be cool
>if he did ;-) I assume you mean Martin Cooper?
>
>Generally, raising your ideas here (the dev list) is a good place to
>start for anything relevant to Struts. However, to ensure that your
>change can be recorded and tracked correctly, you should open an
>enhancement request in Bugzilla and attach your code there.
>
>In this specific case, you will need to submit the report to the Jakarta
>Commons project, which is where BeanUtils resides.
>
>There's more commons-specific information at
>http://jakarta.apache.org/commons/patches.html
>
>In summary, discuss your suggestions/ideas on the relevant dev-list, but
>submit your patches via bugzilla.
>
>Steve
>
> > -----Original Message-----
> > From: Michael McGrady [mailto:mike@michaelmcgrady.com]
> > Sent: April 25, 2004 8:09 PM
> > To: Struts Developers List
> > Subject: How do I submit code?
> >
> >
> > I got tired of trying to get some answers and listened to a couple of
> > things Martin Fowler said on the users list and decided to
> > just write my
> > own tags.  I find I can write my own tags as easy as finding
> > out how some
> > of the existing ones work.  Some of that code is a little "dark"!  LOL
> >
> > I have some code that I think improves PropertyUtils in
> > commons and its
> > ability to handle nested maps and other nested situations.
> > This also has a
> > new class to go in with the bean options, which is really an
> > improvement on
> > the WriteTag in conjunction with changes to PropertyUtils in
> > commons and
> > RequestUtils in org.apache.struts.util.  I call the tag
> > WriteMapTag and use
> > it myself, as follows:
> >
> > <map:write name="host" property="page(logon).key(bannerLeftColor)"
> > scope="request" />
> >
> > The central code for this is like the following:
> >
> > public static Object getNestedProperty(Object bean,
> >                                           String property)
> >          throws IllegalAccessException,
> >                 InvocationTargetException,
> >                 NoSuchMethodException,
> >                 ChainedException {
> >      Map map = null;
> >      if (bean == null) {
> >        throw new IllegalArgumentException("No bean specified");
> >      }
> >      if (property == null) {
> >        throw new IllegalArgumentException("No property specified");
> >      }
> >      int indexOfNESTED_DELIM = -1;
> >      int indexOfMAPPED_DELIM_L = -1;
> >      int indexOfMAPPED_DELIM_R = -1;
> >      String next = null;
> >      int loop = -1;
> >      if(!(bean instanceof Map)) {
> >        ChainedException ce = new ChainedException(new
> > IllegalArgumentException("This is not a BeanMap object"),
> > "This is not a
> > BeanMap object.  The object is a " + bean);
> >        throw ce;
> >      }
> >      map = (Map)bean;
> >      String payload = null;
> >      while(true) {
> >        payload =
> > property.substring(property.indexOf(MAPPED_DELIM_L) +
> > 1,property.indexOf(MAPPED_DELIM_R));
> >        loop = property.indexOf(NESTED_DELIM);
> >        if(loop > 0) {
> >          try {
> >            map = (Map)(map.get(payload));
> >          } catch (ClassCastException cce) {
> >            property = "Either you are using a class other
> > than a map or you
> > are burrowing too deep into the map.  The class cast
> > exception trace is: "
> > + StackTrace.trace(cce);
> >            break;
> >          }
> >          property = property.substring(loop + 1);
> >        } else {
> >          break;
> >        }
> >      }
> >      // This need not return a string but it has to
> >      // return something whose payload is a string.
> >      return map.get(payload);
> >    } ///;-) Michael McGrady
> >
> > With maps, the "page" and "key" are just toss ins.  If you
> > specify a type
> > atttribute, then these become method names with the
> > parameters becoming
> > arguments.  You get the idea.  How do I go about showing
> > these to someone
> > and seeing if they might be of some assistance?
> >
> >
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
>For additional commands, e-mail: dev-help@struts.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


RE: How do I submit code?

Posted by Steve Raeburn <sr...@apache.org>.
I don't think Martin Fowler subscribes to the user list -- it'd be cool
if he did ;-) I assume you mean Martin Cooper?

Generally, raising your ideas here (the dev list) is a good place to
start for anything relevant to Struts. However, to ensure that your
change can be recorded and tracked correctly, you should open an
enhancement request in Bugzilla and attach your code there.

In this specific case, you will need to submit the report to the Jakarta
Commons project, which is where BeanUtils resides.

There's more commons-specific information at
http://jakarta.apache.org/commons/patches.html

In summary, discuss your suggestions/ideas on the relevant dev-list, but
submit your patches via bugzilla.

Steve

> -----Original Message-----
> From: Michael McGrady [mailto:mike@michaelmcgrady.com]
> Sent: April 25, 2004 8:09 PM
> To: Struts Developers List
> Subject: How do I submit code?
>
>
> I got tired of trying to get some answers and listened to a couple of
> things Martin Fowler said on the users list and decided to
> just write my
> own tags.  I find I can write my own tags as easy as finding
> out how some
> of the existing ones work.  Some of that code is a little "dark"!  LOL
>
> I have some code that I think improves PropertyUtils in
> commons and its
> ability to handle nested maps and other nested situations.
> This also has a
> new class to go in with the bean options, which is really an
> improvement on
> the WriteTag in conjunction with changes to PropertyUtils in
> commons and
> RequestUtils in org.apache.struts.util.  I call the tag
> WriteMapTag and use
> it myself, as follows:
>
> <map:write name="host" property="page(logon).key(bannerLeftColor)"
> scope="request" />
>
> The central code for this is like the following:
>
> public static Object getNestedProperty(Object bean,
>                                           String property)
>          throws IllegalAccessException,
>                 InvocationTargetException,
>                 NoSuchMethodException,
>                 ChainedException {
>      Map map = null;
>      if (bean == null) {
>        throw new IllegalArgumentException("No bean specified");
>      }
>      if (property == null) {
>        throw new IllegalArgumentException("No property specified");
>      }
>      int indexOfNESTED_DELIM = -1;
>      int indexOfMAPPED_DELIM_L = -1;
>      int indexOfMAPPED_DELIM_R = -1;
>      String next = null;
>      int loop = -1;
>      if(!(bean instanceof Map)) {
>        ChainedException ce = new ChainedException(new
> IllegalArgumentException("This is not a BeanMap object"),
> "This is not a
> BeanMap object.  The object is a " + bean);
>        throw ce;
>      }
>      map = (Map)bean;
>      String payload = null;
>      while(true) {
>        payload =
> property.substring(property.indexOf(MAPPED_DELIM_L) +
> 1,property.indexOf(MAPPED_DELIM_R));
>        loop = property.indexOf(NESTED_DELIM);
>        if(loop > 0) {
>          try {
>            map = (Map)(map.get(payload));
>          } catch (ClassCastException cce) {
>            property = "Either you are using a class other
> than a map or you
> are burrowing too deep into the map.  The class cast
> exception trace is: "
> + StackTrace.trace(cce);
>            break;
>          }
>          property = property.substring(loop + 1);
>        } else {
>          break;
>        }
>      }
>      // This need not return a string but it has to
>      // return something whose payload is a string.
>      return map.get(payload);
>    } ///;-) Michael McGrady
>
> With maps, the "page" and "key" are just toss ins.  If you
> specify a type
> atttribute, then these become method names with the
> parameters becoming
> arguments.  You get the idea.  How do I go about showing
> these to someone
> and seeing if they might be of some assistance?
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org