OK, that's already done. As you see in the example struts-config down
here, I can use the same Action Object to get the result. What I want to
avoid is using several action elements in struts-config, because cats
and dogs, for those purposes are the same thing. As I said, i tried the
following:

<struts-config>
  <form-beans>
    <form-bean      name="cats"
                    type="CatsForm"/>
    <form-bean      name="dogs"
                    type="DogsForm"/>
    <form-bean      name="pets"
                    type="BasePetsForm"/>
  </form-beans>

  <action-mappings>
    <action    path="/addAnagEntry"
               type="AddAnagEntryAction"
               name="pets"                       <---- what to put here
??
              scope="session"
              input="/newAnag.jsp"
           validate="true">
      <forward name="success" path="/listAnag.do"/>
      <forward name="failure" path="/failure.jsp"/>
    </action>

    <action    path="/listAnag"
               type="ListAnagAction"
               name="pets"                       <---- what to put here
??
              scope="session"
              input="/index.jsp"
           validate="true">
      <forward name="success" path="/listAnag.jsp"/>
      <forward name="failure" path="/failure.jsp"/>
    </action>    

... And so on...

That is: using the mapping for the path /listAnag for listing not only
cats, but also dogs and monkeys. For reaching this, I extend the method

protected ActionForm processActionForm(ActionMapping mapping,
                               HttpServletRequest request)

of ActionServlet: this method normally checks for the existance of a
Bean of the correct class in the correct scope, eventually creates it
and returns it. Information for doing this i retrieved in the mapping
parameter passed to it /basically what is retrieved is the "name" of the
bean to search. What I did is determine this name in a request
parameter, instead of logging at the mapping. This works fine, but if
some other component (say the <html:form> tag) uses information in the
mapping (that is in struts-config) it can't work.

Renato

____________________________________
Renato Romano
Sistemi e Telematica S.p.A.
Calata Grazie - Vial Al Molo Giano
16127 - GENOVA

e-mail: [EMAIL PROTECTED]
Tel.:   010 2712603
_____________________________________


-----Original Message-----
From: Ray Madigan [mailto:[EMAIL PROTECTED] 
Sent: marted́ 4 marzo 2003 18.05
To: Struts Users Mailing List; [EMAIL PROTECTED]
Subject: RE: How to reuse mappings and jsp pages


I do something very similar to this. But Im not sure exactly what you
are trying to do.  If your base class is abstract and defines a general
interface that the extending classes implement, like public Collection
list ( );

and the classes that extend your base class implement this interface,
all the action class has to do is call list on the object it holds and
doesn't need to know if it is cats or dogs?

Im not sure if this helps.


-----Original Message-----
From: Renato Romano [mailto:[EMAIL PROTECTED]
Sent: Tuesday, March 04, 2003 8:46 AM
To: 'Struts Users Mailing List'
Subject: RE: How to reuse mappings and jsp pages


I'm not sure I understood your answer. To get closer to the problem: in
the action mapping for the path, say, "listAnag(.do)", I have to specify
the "name" attribute, which determines the class of objects I have to
retrieve and then list in the result page. Suppose I have a BaseAnagForm
class (which extends ActionForm) and then CatAnag and DogAnag, both
extending BaseAnag. What i'd like to do is determine wheter to list Cats
or Dogs, using some other parameter, because I don't want to determine
this at deploy time. A solution of course would be to define several
mappings in struts-config, like:

<action-mappings>
    <action    path="/listCatsAnag"
               type="myPackage.ListAnagAction"
               name="cats"
              scope="session"
              input="---"
           validate="true">
      <forward name="success" path="/showCatsAnag.jsp"/>
      <forward name="failure" path="/failure.jsp"/>
    </action>
    <action    path="/listDogsAnag"
               type="myPackage.ListAnagAction"
               name="dogs"
              scope="session"
              input="---"
           validate="true">
      <forward name="success" path="/showDogsAnag.jsp"/>
      <forward name="failure" path="/failure.jsp"/>
    </action>

Where dogs is a Bean of class DogsAnag and cats is a bean of class
CatsAnag. What I would like to do is configure a UNIQUE action element,
because I have lots of those objects, and the things I have to do on
them (list, save, retrieve) are substantially the same...

Thanks

____________________________________
Renato Romano
Sistemi e Telematica S.p.A.
Calata Grazie - Vial Al Molo Giano
16127 - GENOVA

e-mail: [EMAIL PROTECTED]
Tel.:   010 2712603
_____________________________________


-----Original Message-----
From: Mark [mailto:[EMAIL PROTECTED]
Sent: marted́ 4 marzo 2003 17.03
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: Re: How to reuse mappings and jsp pages


Not to mention the validator and everything uses BeanUtils and
PropertyUtils from commons... What remains to be seen is if these will
introspect the base (abstract) class or the proper (bean) class, but
either way i fear they will miss out on the underlying fields.  i havent
personnally tested this, but perhaps the introspection is smart enough
to get the properties from "extended" classes.

You've also touched on some things I've experienced, i.e. tight
configuration between tiers in the Struts-MVC implementation.  I've been
looking for a more "loose" way too.

Regards,
Mark

*********** REPLY SEPARATOR  ***********

On 03/04/2003 at 5:00 PM Renato Romano wrote:

>Hi all.
>
>I'm trying to model a set of "Anagraphics" objects; each object extends

>a base abstract class, and only adds getter and setter method specific 
>to it; all these object behave the same way, in the sense that all I 
>have to do on them is reading, listing, updating, inserting. I can 
>already persist those object in and independent way, so Action Objects 
>are written assuming to use the base class, and don't have to know what

>the exact runtime class is; what I would like to do now is:
>
>1) write action-mappings in struts-config in a similar independent way;

>this seems difficult to me because in the mapping I have to specify the

>"name" of the ActionForm bean to use, and therefore it's class! I tried

>do subclass ActionServlet, and determine the class of the Bean to use 
>using a runtime request parameter, if present, instead of using 
>information from the mapping; this works, but not all work is done by 
>ActionServlet !! For example the <html:form> tag uses its action 
>attribute to look up the bean name (and type) to use, so I get stuck 
>again, because it tries to instantiate an abstract class; even if this 
>class was not abstract i get a wrong object !!. Should I extend this 
>tag ? And what else ? Is there a better way ?
>
>2) write jsp pages in a similar independent way. This seems more 
>difficult and maybe not so useful, also considering that rendering 
>appropriate input forms, or listing tables using generic jsp pages 
>would not lead to frendly interfaces, I think!!
>
>Suggestions are welcome.
>
>Renato
>
>____________________________________
>Renato Romano
>Sistemi e Telematica S.p.A.
>Calata Grazie - Vial Al Molo Giano
>16127 - GENOVA
>
>e-mail: [EMAIL PROTECTED]
>Tel.:   010 2712603
>_____________________________________
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to