Customize adding of files using Temp. Attachment Provider

Hi everybody,
I want to restrict users to add only one file with the same name.
I am using Temporary Attachment Provider.
Do anyone know how to do it?

Regards,

Marcelo

In 8.x, after you drop the Attachments List Control onto the canvas, you can right click and “Customize” that control which will decompose the control into all the Dialogs and other controls. This is useful for many types of customization, but i’m not sure it will solve your scenario.

The browser won’t allow you to script anything to do with file input controls (Major Security Hole), so your validation will have to be done on the server side. I’d recommend adapting the sample provided with this thread: http://tech.forums.softwareag.com/viewtopic.php?p=67769#67769&sid=fdb0962e6440d5c954575304270fc2c0

and add your validation to the server side.

Regards,
–mark

Mark,
Thanks for your response. I tell you that I could solve the problem.
As you said, I Customized the Attachments List Control. I replaced the Action that was called in the Save Button that appeared in the pop-up window for attaching the file.
The Action that I wrote is the following:

 
public void buttonSave() throws Exception { 
  getAttachmentsListControlBean_1().button1_action(); 
 
  List<IAttachmentItem> files =  getTemporaryAttachmentsProvider().listAttachments(); 
  int listSize = files.size(); 
  IAttachmentItem lastFile = files.get(listSize-1); 
  int ind = lastFile.getFileName().indexOf(" [1]"); 
	     
  if (ind != -1){ 
    String fileName = lastFile.getFileName().substring(0, ind);  
    for (int i = 0; i < listSize-1; i++) { 
      IAttachmentItem f = files.get(i); 
      if (f.getFileName().equals(fileName)){			          getTemporaryAttachmentsProvider().removeAttachment(lastFile.getId()); 
      error(FacesMessage.SEVERITY_WARN, "MESSAGE", null); 
      break; 
    } 
   } 
 } 
} 

[/code]

Regards,

Marcelo

1 Like