On Thu, Nov 1, 2012 at 6:46 AM,  <devnull2...@gmx.de> wrote:
> public class Foo extends _Foo {
>
>    @Inject @Symbol(value="baseDir")  // not possible
>    String baseDir;
>
>    public String getAbsoluteLocalFilepath() {
>
>        return baseDir + "/" + toUser.getId() + "/" + getFilename();
>      }
> }
>
> The return value is a path to a file. The files get uploaded by users and 
> each user has their own folder inside of baseDir. Each foo object has a 
> relation to a user object and a field filename.
>
> baseDir is a symbol read from myApp.properties. On the production server it 
> could be /var/myApp/userfiles/, on another machine it could be 
> /home/username/myApp/userfiles, set in eclipse as VM argument -DbaseDir=...
>
> getAbsoluteLocalFilepath() is called in page classes, e. g. to store a file 
> under this path. Another example for a method in Foo could be
> public InlineFileStreamResponse getImageAsStream() ...
> where we also need the baseDir.
>
> The files are uploaded by users. They can't be Assets and we don't want blobs 
> in the database.


If you are going to do -DbaseDir=... as a VM argument, why not just
use System.getProperty("baseDir") to read the value?  No need to
@Inject it.


>> > The other approach would be to use a servlet filter, which is much
>> > more complex.  You'd probably have to register a thread local to bind
>> > your Tapestry symbol values into and then retrieve them inside your
>> > CayenneDataObject subclasses (Foo, Bar, etc) using a lifecycle
>> > callback.  I think this approach would be more work and more magic
>> > (harder to implement and understand/maintain later), but if you would
>> > like to explore this avenue instead of a Tapestry service, just ask.
>
> There are few methods like the example above and the baseDir and a second 
> value are injected in page classes since the example with the Inject doesn't 
> work. Then the baseDir is passed to the method:
> getAbsoluteLocalFilepath(baseDir);
>
>
> If I wrote a TapestryCayenneService, would I have to use it for the creation 
> of every Cayenne object? There are 13 classes and only two of them would use 
> two injected symbol values.


I think you are trying to do something different that I initially
thought, so I'd skip the service part for now and just keep creating
your Cayenne objects the way you are currently creating them.


mrg

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org

Reply via email to