1 15 package org.apache.tapestry.form; 16 17 import org.apache.tapestry.IForm; 18 import org.apache.tapestry.IMarkupWriter; 19 import org.apache.tapestry.IRequestCycle; 20 import org.apache.tapestry.multipart.MultipartDecoder; 21 import org.apache.tapestry.request.IUploadFile; 22 import org.apache.tapestry.valid.ValidationStrings; 23 import org.apache.tapestry.valid.ValidatorException; 24 25 34 35 public abstract class Upload extends AbstractRequirableField 36 { 37 40 public void bind(IMarkupWriter writer, IRequestCycle cycle) throws ValidatorException 41 { 42 setFile(getUploadFile()); 43 } 44 45 48 protected void finishLoad() 49 { 50 setRequiredMessage(ValidationStrings.getMessagePattern( 51 ValidationStrings.REQUIRED_FILE_FIELD, 52 getPage().getLocale())); 53 } 54 55 private IUploadFile getUploadFile() 56 { 57 return getDecoder().getFileUpload(getName()); 58 } 59 60 public String getSubmittedValue(IRequestCycle cycle) 61 { 62 return getUploadFile().getFilePath(); 63 } 64 65 protected void renderFormComponent(IMarkupWriter writer, IRequestCycle cycle) 66 { 67 super.renderFormComponent(writer, cycle); 68 69 IForm form = getForm(); 71 72 form.setEncodingType("multipart/form-data"); 73 74 renderDelegatePrefix(writer, cycle); 75 76 writer.beginEmpty("input"); 77 writer.attribute("type", "file"); 78 writer.attribute("name", getName()); 79 80 if (isDisabled()) 81 { 82 writer.attribute("disabled", "disabled"); 83 } 84 85 form.getDelegate().writeAttributes(writer, cycle, this, null); 86 87 renderIdAttribute(writer, cycle); 88 89 renderDelegateAttributes(writer, cycle); 90 91 renderDelegateSuffix(writer, cycle); 92 } 93 94 public abstract void setFile(IUploadFile file); 95 96 public abstract MultipartDecoder getDecoder(); 97 } | Popular Tags |