This code will get pictures from the file server then put it in the template
automatically.

.tml



<t:loop t:source="Imagepath" t:value="imagepath1">
     [img src="file:${imagepath1.filename}" /]
</t:loop>



.java



/**
 * Start page of application TapestryAutoLoadPictures.
 */
public class Index
{

    @Inject
    private AssetSource assetSource;

    private File file;
    private File[] listOfFiles;
    private int j;
    private List<Imagepath> listImages;
    private Imagepath imagepath2;
    private List<Imagepath> temp = new ArrayList<Imagepath>();
    
    @Property
    private Imagepath imagepath1;

    public List<Imagepath> getImagepath(){
        
        listImages = temp;
        return listImages;
    }

    public void setupRender(){

        String path = "//fileserver/pictures";
        file = new File(path);
        listOfFiles = file.listFiles();

        // Clear Loaded Pictures
        temp.clear();
        
        if(listOfFiles.length > 0){

            for (j = 0; j < listOfFiles.length; j++) {
                if (listOfFiles[j].isFile()) {

                    // Check for JPG Extension
                    if(listOfFiles[j].getName().contains(".jpg") ||
listOfFiles[j].getName().contains(".JPG")){

                        imagepath2 = new Imagepath(path + "/" +
listOfFiles[j].getName());

                        temp.add(imagepath2);

                        // Clear
                        imagepath2 = null;
                        this.imagepath2 = null;
                    }
                }
            }
        }
    }
}



.class (Custom Imagepath Class)



/**
 *
 * @author alan
 */
public class Imagepath implements java.io.Serializable {

    private String filename;

    public Imagepath(){

    }

    public Imagepath(String filename){
        this.filename = filename;
    }

    public String getFilename() {
        return filename;
    }

    public void setFilename(String filename) {
        this.filename = filename;
    }

}





Note: For documentation purpose only...
-- 
View this message in context: 
http://tapestry.1045711.n5.nabble.com/T5-Auto-Generated-Picture-Gallery-Intranet-tp3298328p3298328.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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

Reply via email to