You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Jan Fryblik <ja...@ebrothers.cz> on 2013/05/11 22:42:34 UTC

load all assets in folder


Hi guys,

i just created simple slider component. Now i'm wondering, is somehow  
possible to load all images from context path? I mean, i have for instance  
folder /webapp/images/slider and i need to get all images in the directory  
without knowing image names. Thanks for answer.


BR,
Jan

Re: load all assets in folder

Posted by Jan Fryblik <ja...@ebrothers.cz>.
Oh, i thought there is some trick for that in Tapestry (as usually :)).

So for completeness i'm sending my raw solution...   Thank you for advise.

@Inject
private Context context;
@Inject
private PersistentLocale persistentLocale;
@Inject
private AssetSource assetSource;

File resource = context.getRealFile("/images/backgrounds/");
String[] list = resource.list();

if (list != null)
{
     Random r = new Random();
    int index = r.nextInt(list.length);

    Asset result = assetSource.getContextAsset(
       "context:/images/backgrounds/" + list[index],
       persistentLocale.get());

    return result;
}

return null;


BR,
Jan

On Sat, 11 May 2013 23:49:50 +0200, Thiago H de Paula Figueiredo  
<th...@gmail.com> wrote:

> On Sat, 11 May 2013 17:42:34 -0300, Jan Fryblik  
> <ja...@ebrothers.cz> wrote:
>
>> Hi guys,
>
> Hi!
>
>> i just created simple slider component. Now i'm wondering, is somehow  
>> possible to load all images from context path? I mean, i >>have for  
>> instance folder /webapp/images/slider and i need to get all images in  
>> the directory without knowing image names. Thanks >>for answer.
>
> Just do what you'd do in a Servlet environment without Tapestry. See  
> first answer to  
> http://stackoverflow.com/>questions/11195532/in-java-is-it-possible-to-get-a-directory-file-listing-inside-a-war-classpath-us.
>
> --Thiago H. de Paula Figueiredo

Re: load all assets in folder

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Sat, 11 May 2013 17:42:34 -0300, Jan Fryblik <ja...@ebrothers.cz>  
wrote:

> Hi guys,

Hi!

> i just created simple slider component. Now i'm wondering, is somehow  
> possible to load all images from context path? I >mean, i have for  
> instance folder /webapp/images/slider and i need to get all images in  
> the directory without knowing image >names. Thanks for answer.

Just do what you'd do in a Servlet environment without Tapestry. See first  
answer to  
http://stackoverflow.com/questions/11195532/in-java-is-it-possible-to-get-a-directory-file-listing-inside-a-war-classpath-us.

-- 
Thiago H. de Paula Figueiredo