You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by fante <ca...@gmail.com> on 2011/07/22 16:23:43 UTC

T5: Dynamically add section of upload files in form

Hey all

I have recently integrated the Tawus T5 component for Ajax upload in my
application.
See his blogg at
http://tawus.wordpress.com/2011/06/25/ajax-upload-for-tapestry/
(Kudos to tawus for providing that)

 I created a Component that contains this upload and some additional form
fields, so that the user can define some metadata for the uploaded files.

And now I would like to dynamically add  a new section, that contains that
same component.
I really cant figure out how to do this on my own. 

Can anybody give a hint or direction?

Btw T5 rocks
Fante

--
View this message in context: http://tapestry.1045711.n5.nabble.com/T5-Dynamically-add-section-of-upload-files-in-form-tp4623273p4623273.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: T5: Dynamically add section of upload files in form

Posted by fante <ca...@gmail.com>.
Ohh still not shows..

My Ajaxform Lopp is withing a span, therefor it seesm it wont display
properly
_SPAN_=span

    <_SPAN_ t:type="AjaxFormLoop" t:source="files" t:value="file"
t:encoder="encoder">
                        <t:submitnotifier>
                            ${file.key} <input t:type='tawus/ajaxupload' 
t:maxfiles="1" class="file"  t:value="file.file" /> <br/>
                        </t:submitnotifier>
                    <p:addRow>
                            <br/>
                            <t:addrowlink>Add a row</t:addrowlink>
                    </p:addRow>
                </_SPAN_>



--
View this message in context: http://tapestry.1045711.n5.nabble.com/T5-Dynamically-add-section-of-upload-files-in-form-tp4623273p4626089.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: T5: Dynamically add section of upload files in form

Posted by fante <ca...@gmail.com>.
It is obviousy difficult for me to paste correctly

Here it comes
<t:form>
      
                        <t:submitnotifier>
                            ${file.key} <input t:type='tawus/ajaxupload' 
t:maxfiles="1" class="file"  t:value="file.file" /> <br/>
                        </t:submitnotifier>
                    <p:addRow>
                            <br/>
                            <t:addrowlink>Add a row</t:addrowlink>
                    </p:addRow>
                
</t:form>

Well file is of type FileHolder, and file.file of type
ArrayList<UploadedFile> 

--
View this message in context: http://tapestry.1045711.n5.nabble.com/T5-Dynamically-add-section-of-upload-files-in-form-tp4623273p4626086.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: T5: Dynamically add section of upload files in form

Posted by Taha Hafeez <ta...@gmail.com>.
Hi Fante

I still can't see the loop... :)

On Sat, Jul 23, 2011 at 6:52 PM, fante <ca...@gmail.com> wrote:
> hi Taha,
>
> I do have a ajaxformLoop, is should look like this:
> (Aplogize for  the incomplete codesnippet above)
>
>    <t:form>
>
>                        <t:submitnotifier>
>                            ${file.key} <input t:type='tawus/ajaxupload'
> t:maxfiles="1" class="file"  t:value="file.file" />
>  <br/>
>                        </t:submitnotifier>
>                    <p:addRow>
>                            <br/>
>                            <t:addrowlink>Add a row</t:addrowlink>
>                    </p:addRow>
>
> </t:form>
>
> file.file is of type private List<UploadedFile> and is like you said null.
> How can I make sure to initialise it properly?
> In the FileHolder I initialse the it to an empty ArrayList<UploadedFile>,
> but that does not seem to do the trick.
>
> Again thanks helping me out!
> fante
>
>
>
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/T5-Dynamically-add-section-of-upload-files-in-form-tp4623273p4626042.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

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


Re: T5: Dynamically add section of upload files in form

Posted by fante <ca...@gmail.com>.
hi Taha,

I do have a ajaxformLoop, is should look like this:
(Aplogize for  the incomplete codesnippet above)

    <t:form>
      
                        <t:submitnotifier>
                            ${file.key} <input t:type='tawus/ajaxupload' 
t:maxfiles="1" class="file"  t:value="file.file" />
 <br/>
                        </t:submitnotifier>
                    <p:addRow>
                            <br/>
                            <t:addrowlink>Add a row</t:addrowlink>
                    </p:addRow>
                
</t:form>

file.file is of type private List<UploadedFile> and is like you said null.
How can I make sure to initialise it properly? 
In the FileHolder I initialse the it to an empty ArrayList<UploadedFile>,
but that does not seem to do the trick.

Again thanks helping me out!
fante



--
View this message in context: http://tapestry.1045711.n5.nabble.com/T5-Dynamically-add-section-of-upload-files-in-form-tp4623273p4626042.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: T5: Dynamically add section of upload files in form

Posted by Taha Hafeez <ta...@gmail.com>.
Hi

The error is not a javascript error but a server side error which
tapestry.js flashes at the top (in red color). You can verify it by
looking at the stack trace.

The error clearly says that the file property is null. The property
will be initialized when you are inside the ajaxformloop. But in the
template I can't see the ajaxformloop. Where is it ?

regards
Taha


On Sat, Jul 23, 2011 at 12:12 AM, fante <ca...@gmail.com> wrote:
> Thanks for you advice, it feels like im getting closer to what I want to
> achieve.
> Below I posted the Java/Tml for my Page.
> (Initially I wanted this to be under components instead, but for clarity I
> converted to a Page)
>
> It seems to render stuff, but I still get Javascript Errors when I try to
> use it.
>  ---- ERROR----
> Failure reading parameter 'value' of component Index:ajaxupload: Property
> 'file' (within property expression 'file.file', of
> com.fante.pages.Index@1c8a395d) is null.
> Communication with the server failed: Failure reading parameter 'value' of
> component Index:ajaxupload: Property 'file' (within property expression
> 'file.file', of com.fante.pages.Index@1c8a395d) is null.
> ----------
>
> I must admit, that I am not very proficient with Javascript.
> Can you tell if Im on the right track here?
>
>
>
>
>
> package com.fante.components;
>
> public class Index {
>
>    @Persist
>    @Property
>    private List<FileHolder> files;
>
>    @Property
>    private FileHolder file;
>
>    @Persist
>    private int nrFiles;
>
>    public void beginRender() {
>        files = new ArrayList<FileHolder>();
>    }
>
>
>
>    @SuppressWarnings("rawtypes")
>    public ValueEncoder getEncoder() {
>        return new ValueEncoder<FileHolder>() {
>
>            public String toClient(FileHolder value) {
>
>                return value.getKey();
>            }
>
>            public FileHolder toValue(String keyAsString) {
>                Long key = new Long(keyAsString);
>                for (FileHolder holder : files) {
>                    if (keyAsString.equalsIgnoreCase("" + holder.getKey()))
> {
>                        return holder;
>                    }
>                }
>                throw new IllegalArgumentException("Received key \"" + key
>                        + "\" which has no counterpart in this collection: "
> + files);
>            }
>        };
>    }
>
>    FileHolder onAddRow() {
>        // Create a skeleton Person and add it to the displayed list with a
> unique key
>        FileHolder newFileHolder = new FileHolder();
>        files.add(newFileHolder);
>
>        return newFileHolder;
>    }
>
>    public class FileHolder {
>        private List<UploadedFile> file;
>        private String key;
>
>        public FileHolder() {
>            file = new ArrayList<UploadedFile>();
>            key = "" + nrFiles;
>            nrFiles++;
>        }
>        public List<UploadedFile> getFile() {
>            return file;
>        }
>
>        public void setFile(List<UploadedFile> file) {
>            this.file = file;
>        }
>        public String getKey() {
>            return key;
>        }
>        public void setKey(String key) {
>            this.key = key;
>        }
>
>
>    }
> }
> In tml:
>
>  <t:form>
>
>                        <t:submitnotifier>
>                            ${file.key} <input t:type='tawus/ajaxupload'
> t:maxfiles="1" class="file"  t:value="file.file" /> <br/>
>                        </t:submitnotifier>
>                    <p:addRow>
>                            <br/>
>                            <t:addrowlink>Add a row</t:addrowlink>
>                    </p:addRow>
>
> </t:form>
>
>
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/T5-Dynamically-add-section-of-upload-files-in-form-tp4623273p4624251.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

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


Re: T5: Dynamically add section of upload files in form

Posted by fante <ca...@gmail.com>.
Thanks for you advice, it feels like im getting closer to what I want to
achieve.
Below I posted the Java/Tml for my Page.
(Initially I wanted this to be under components instead, but for clarity I
converted to a Page)

It seems to render stuff, but I still get Javascript Errors when I try to
use it.
 ---- ERROR----
Failure reading parameter 'value' of component Index:ajaxupload: Property
'file' (within property expression 'file.file', of
com.fante.pages.Index@1c8a395d) is null.
Communication with the server failed: Failure reading parameter 'value' of
component Index:ajaxupload: Property 'file' (within property expression
'file.file', of com.fante.pages.Index@1c8a395d) is null.
----------

I must admit, that I am not very proficient with Javascript. 
Can you tell if Im on the right track here?





package com.fante.components;

public class Index {

    @Persist
    @Property
    private List<FileHolder> files;

    @Property
    private FileHolder file;
    
    @Persist
    private int nrFiles;
    
    public void beginRender() {
        files = new ArrayList<FileHolder>();
    }
    
    
    
    @SuppressWarnings("rawtypes")
    public ValueEncoder getEncoder() {
        return new ValueEncoder<FileHolder>() {

            public String toClient(FileHolder value) {
        
                return value.getKey();
            }

            public FileHolder toValue(String keyAsString) {
                Long key = new Long(keyAsString);
                for (FileHolder holder : files) {
                    if (keyAsString.equalsIgnoreCase("" + holder.getKey()))
{
                        return holder;
                    }
                }
                throw new IllegalArgumentException("Received key \"" + key
                        + "\" which has no counterpart in this collection: "
+ files);
            }
        };
    }
    
    FileHolder onAddRow() {
        // Create a skeleton Person and add it to the displayed list with a
unique key
        FileHolder newFileHolder = new FileHolder();
        files.add(newFileHolder);

        return newFileHolder;
    }

    public class FileHolder {
        private List<UploadedFile> file;
        private String key;

        public FileHolder() {
            file = new ArrayList<UploadedFile>();
            key = "" + nrFiles;
            nrFiles++;
        }
        public List<UploadedFile> getFile() {
            return file;
        }

        public void setFile(List<UploadedFile> file) {
            this.file = file;
        }
        public String getKey() {
            return key;
        }
        public void setKey(String key) {
            this.key = key;
        }
        
        
    }
}
In tml:

 <t:form>
      
                        <t:submitnotifier>
                            ${file.key} <input t:type='tawus/ajaxupload' 
t:maxfiles="1" class="file"  t:value="file.file" /> <br/>
                        </t:submitnotifier>
                    <p:addRow>
                            <br/>
                            <t:addrowlink>Add a row</t:addrowlink>
                    </p:addRow>
                
</t:form>


--
View this message in context: http://tapestry.1045711.n5.nabble.com/T5-Dynamically-add-section-of-upload-files-in-form-tp4623273p4624251.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: T5: Dynamically add section of upload files in form

Posted by Taha Hafeez <ta...@gmail.com>.
All form fields are bound to some values. If you want to add list of
these fields to the form you need to store these values in some list
:)

May be you can explain with some code

regards
Taha

On Fri, Jul 22, 2011 at 9:25 PM, fante <ca...@gmail.com> wrote:
> Hi Taha,
>
> I really appreciate your advice here.
>
> But how would I use an AjaxFormLoop here? I only used the AjaxFormLoop when
> I have a collection of
> data Item before, Can I really use it with components?
>
>
> Cheers
> Fante
>
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/T5-Dynamically-add-section-of-upload-files-in-form-tp4623273p4623670.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

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


Re: T5: Dynamically add section of upload files in form

Posted by fante <ca...@gmail.com>.
Hi Taha,

I really appreciate your advice here. 

But how would I use an AjaxFormLoop here? I only used the AjaxFormLoop when
I have a collection of 
data Item before, Can I really use it with components? 


Cheers
Fante

--
View this message in context: http://tapestry.1045711.n5.nabble.com/T5-Dynamically-add-section-of-upload-files-in-form-tp4623273p4623670.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: T5: Dynamically add section of upload files in form

Posted by Taha Hafeez <ta...@gmail.com>.
How about http://tapestry.apache.org/current/tapestry-core/ref/org/apache/tapestry5/corelib/components/AjaxFormLoop.html
or http://tapestry.apache.org/current/tapestry-core/ref/org/apache/tapestry5/corelib/components/FormInjector.html

regards
Taha

On Fri, Jul 22, 2011 at 8:28 PM, fante <ca...@gmail.com> wrote:
> Hi Taha,
>
> If using a FormFragment, I need to know exactly how many sections in
> advance.
> By dynamically, I mean to supply a button/link that when clicked, displays a
> new section
> with the Ajax upload File component and the additional meta data that goes
> with it, underneath the original one.
>
>
>
> Thanks for you quick reply
> Fante
>
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/T5-Dynamically-add-section-of-upload-files-in-form-tp4623273p4623466.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

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


Re: T5: Dynamically add section of upload files in form

Posted by fante <ca...@gmail.com>.
Hi Taha,

If using a FormFragment, I need to know exactly how many sections in
advance.
By dynamically, I mean to supply a button/link that when clicked, displays a
new section 
with the Ajax upload File component and the additional meta data that goes
with it, underneath the original one.



Thanks for you quick reply
Fante

--
View this message in context: http://tapestry.1045711.n5.nabble.com/T5-Dynamically-add-section-of-upload-files-in-form-tp4623273p4623466.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: T5: Dynamically add section of upload files in form

Posted by Taha Hafeez <ta...@gmail.com>.
Hi

I am confused about the "dynamically" thing but may be this will help

http://tapestry.apache.org/current/tapestry-core/ref/org/apache/tapestry5/corelib/components/FormFragment.html

regards
Taha

On Fri, Jul 22, 2011 at 7:53 PM, fante <ca...@gmail.com> wrote:
> Hey all
>
> I have recently integrated the Tawus T5 component for Ajax upload in my
> application.
> See his blogg at
> http://tawus.wordpress.com/2011/06/25/ajax-upload-for-tapestry/
> (Kudos to tawus for providing that)
>
>  I created a Component that contains this upload and some additional form
> fields, so that the user can define some metadata for the uploaded files.
>
> And now I would like to dynamically add  a new section, that contains that
> same component.
> I really cant figure out how to do this on my own.
>
> Can anybody give a hint or direction?
>
> Btw T5 rocks
> Fante
>
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/T5-Dynamically-add-section-of-upload-files-in-form-tp4623273p4623273.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

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