How about @InjectObject("spring:someBean") to get whatever resources
you want from spring.  And an @InitialValue() annotation to initialize
things that don't come from spring.  I haven't tried it, but perhaps 
@InitialValue("new Logger(this.getClass().getName())") (or whatever
the appropriate ognl syntax would be) on a log property.  The problem
with doing a log object in the base class, of course, is that all log
messages would appear to be from the base class.  You really need a
separate logger instance in your base class and subclass in order to
differentiate exactly where the log messages are truly coming from.

--sam


On 4/9/06, Mark <[EMAIL PROTECTED]> wrote:
> Hi Pedro,
>
> this would work, but now you have the LogFactory reference hard-coded.
>
> I am trying to be completely independent and just inject everything.
>
> I found something on the Spring site that is extending BaseEngine, in
> order to add a hook to the application-context into the IEngine
> Implementation:
> http://static.springframework.org/spring/docs/1.2.x/reference/webintegration.html#view-tapestry-exposeappctx
>
> It puts the hook into the Global object. Since this is designed for T3,
> I guess T4 could use an application-scope ApplicationStateObject to do this.
> It could be created in the HiveMind module deployment descriptor:
> <contribution configuration-id="tapestry.state.ApplicationObjects">
>     <state-object name="logFactory" scope="application">
>         <create-instance class="some.new.logFactory"/>
>     </state-object>
> </contribution>
>
> Then it could be injected in the .page file:
> <inject name="registration" type="state" object="logFactory"/>
>
> The question is just: how can I make the BasePageImplementation initiate
> the injection, so that I do not have to do it in each .page file any more:
>
> public class BasePageImplementation extends BasePage {
>     private Log logger;
>
>     public BasePageImplementation() {
>         // Since all page classes are inherited Tapestry generated classes
>         // we use the superclass to initialize the log
>         logger = <getHivemindApplicationObject("logFactory")> // <!--- this 
> is what I am missing! How can I do this?
>     }
>
>     /**
>      * @return Returns the logger.
>      */
>     public Log getLogger() {
>         return logger;
>     }
> }
>
>
> This way, if  want to switch the Log implementation, I can switch the
> LogFactory by just simply changing the hivemind module decriptor.
> So I am just missing the one last part of the puzzle: How can I access
> all the stuff that is defined in the Hivemind configurations from within
> the java objects directly, rather than from the .page files?
>
> Thanks,
>
> MARK
>
>
>
>
> Pedro Viegas wrote:
> > Why not something like...
> >
> > public class BasePageImplementation extends BasePage {
> >     private Log logger;
> >
> >     public BasePageImplementation() {
> >         // Since all page classes are inherited Tapestry generated classes
> >         // we use the superclass to initialize the log
> >         logger = LogFactory.getLog(this.getClass().getSuperclass());
> >     }
> >
> >     /**
> >      * @return Returns the logger.
> >      */
> >     public Log getLogger() {
> >         return logger;
> >     }
> > }
> >
> > Works for me. :-)
> >
> >
> > On 4/9/06, Mark <[EMAIL PROTECTED]> wrote:
> >
> >> Yes, that's what I have done.
> >> But still - let's assume I have something like
> >>
> >> public abstract class LogAwareBasePage extends BasePage implements
> >> PageBeginRenderListener {
> >>     Log log;
> >>     public void setLog(Log log) { ... }
> >>     public Log getLog() { ... }
> >> }
> >>
> >> I still don't have the log property initialized.
> >> Sure, I could do this:
> >>
> >> public abstract class LogAwareBasePage extends BasePage implements
> >> PageBeginRenderListener {
> >>     Log log = new SomeClassThatImplementsLog("param1", "param2", ...);
> >>     public void setLog(Log log) { ... }
> >>     public Log getLog() { ... }
> >> }
> >>
> >> But this is not runtime-configurable...
> >>
> >>
> >> Or I could do it in my .page file:
> >>
> >> <property name="log">ognl:Some OGNL expression</property>
> >>
> >> So I could plug it in the .page files, but that would have to be done in
> >> each .page file again and again. So if I want to switch the Log
> >> implementation, at least I don't have to modify my java code, but I will
> >> have to change every single .page file.
> >>
> >> So I am hoping that I could somehow use Hivemind instead to configure
> >> the injection of the Log implementation, but I don't know how.
> >>
> >>
> >> Also, as an additional challenge: My application architecture is using
> >> Spring for the configuration and property injection on all the other
> >> layers, so ideally, I would like to use Spring to initialize the log
> >> property, so that I do not have to define all the beans twice (once in
> >> Spring and once in Hivemind). Maybe the bridge from the tapestry-spring
> >> project can be used for that???
> >>
> >> Thanks for the help,
> >>
> >> MARK
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >> Sam Gendler wrote:
> >>
> >>> Define a MyBasePage which has all the properties you want, and then
> >>> make all your pages inherit from that.
> >>>
> >>> --sam
> >>>
> >>>
> >>> On 4/9/06, Mark <[EMAIL PROTECTED]> wrote:
> >>>
> >>>
> >>>> Hello,
> >>>>
> >>>> is there a way to "globally" inject certain properties in a large
> >>>>
> >> number
> >>
> >>>> of pages, without having to do it in each page specification file?
> >>>> For example, I expect all my pages to have a "log" Property which is an
> >>>> implementation of the commons-logging Log interface.
> >>>> But I want to plug the particular implementation of the Log interface
> >>>> using injection at runtime, just like all the other page properties are
> >>>> plugged at runtime based on the .page specification file as well.
> >>>> However, I don't want to have to include the same property definition
> >>>>
> >> in
> >>
> >>>> every single page-descriptor, since it is not very well maintainable.
> >>>> Imagine I have 100 pages and now want to change the implementation of
> >>>> the Log interface - I have to change 100 different .page files.
> >>>>
> >>>> So is there a way to do this in a better way?
> >>>>
> >>>> Thanks,
> >>>>
> >>>> MARK
> >>>>
> >>>> ---------------------------------------------------------------------
> >>>> 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]
> >>
> >>
> >>
> >
> >
> > --
> > Pedro Viegas
> >
> >
>
>
> ---------------------------------------------------------------------
> 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