Couldn't you use a list of "placeholders"/wrappers?
This is what I've done in the past in similar sorts of scenarios,
although it wasn't ajax-based.
I created a list of "UploadContainers". This ended up being useful
because then I could associate other sorts of values to each upload
row (extract archives, create xyz, and so forth), and they would all
be "nicely" associated. So then you don't have to worry about not
having an upload file, b/c you can easily create your container, and
bind the file upload component's value to the UploadContainer's "file"
property.
Robert
On Jun 10, 2008, at 6/1011:28 AM , Ognen Ivanovski wrote:
Hi all,
I'm trying to write a page that mimics an email composition form. On
this form the user should be allowed to add any number of
attachments (files).
My idea is to use an AjaxFormLoop and a file upload component
inside. The problem is - I can't.
The loop needs an iterable to work over - ok - that is a list of
UploadedFiles. But, the 'addRow' event says it needs to return a non-
null value so that the loop can correctly use it. But - i don't have
an uploaded file yet - i just want a new Upload component to render
itself.
Second problem - how would I process the files at the end?
My code - so far:
public class Test {
@Property private List<UploadedFile> files = new
ArrayList<UploadedFile>();
@Property private UploadedFile currentValue;
@Property private DefaultPrimaryKeyEncoder<Integer, UploadedFile>
encoder = new DefaultPrimaryKeyEncoder<Integer, UploadedFile>();
@InjectComponent private Block newFileBlock;
public int getNumOfFiles() {
return files.size();
}
public void onSubmit() {
// what do i do here?
}
public Block onAddRow() {
return null; // what do i do here? this causes illegal state
excepton
}
}
Test.tml:
<t:form>
<t:ajaxformloop source="files" value="currentValue"
encoder="encoder">
<t:submitnotifier>
<t:upload t:id="currentValue" value="currentValue" />
<t:removerowlink>remove</t:removerowlink>
</t:submitnotifier>
<t:parameter name="addRow">
<t:addrowlink>Add a row</t:addrowlink>
</t:parameter>
</t:ajaxformloop>
<div class="t-beaneditor-row">
<input type="submit" value="Submit"/>
</div>
</t:form>
<p>Number of strings (after submit): ${numOfFiles}</p>
<t:grid source="files"/>
---------------------------------------------------------------------
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]