|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| package org.apache.tapestry.form; |
|
16 |
| |
|
17 |
| import org.apache.hivemind.HiveMind; |
|
18 |
| import org.apache.tapestry.IForm; |
|
19 |
| import org.apache.tapestry.IMarkupWriter; |
|
20 |
| import org.apache.tapestry.IRequestCycle; |
|
21 |
| import org.apache.tapestry.multipart.MultipartDecoder; |
|
22 |
| import org.apache.tapestry.request.IUploadFile; |
|
23 |
| import org.apache.tapestry.valid.ValidatorException; |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| public abstract class Upload extends AbstractFormComponent implements ValidatableField |
|
38 |
| { |
|
39 |
| public abstract void setFile(IUploadFile file); |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
6
| protected void renderFormComponent(IMarkupWriter writer, IRequestCycle cycle)
|
|
46 |
| { |
|
47 |
| |
|
48 |
6
| IForm form = getForm();
|
|
49 |
| |
|
50 |
6
| form.setEncodingType("multipart/form-data");
|
|
51 |
| |
|
52 |
6
| renderDelegatePrefix(writer, cycle);
|
|
53 |
| |
|
54 |
6
| writer.beginEmpty("input");
|
|
55 |
6
| writer.attribute("type", "file");
|
|
56 |
6
| writer.attribute("name", getName());
|
|
57 |
| |
|
58 |
6
| if (isDisabled())
|
|
59 |
| { |
|
60 |
3
| writer.attribute("disabled", "disabled");
|
|
61 |
| } |
|
62 |
| |
|
63 |
6
| renderIdAttribute(writer, cycle);
|
|
64 |
| |
|
65 |
6
| renderDelegateAttributes(writer, cycle);
|
|
66 |
| |
|
67 |
6
| getValidatableFieldSupport().renderContributions(this, writer, cycle);
|
|
68 |
| |
|
69 |
6
| renderInformalParameters(writer, cycle);
|
|
70 |
| |
|
71 |
6
| writer.closeTag();
|
|
72 |
| |
|
73 |
6
| renderDelegateSuffix(writer, cycle);
|
|
74 |
| } |
|
75 |
| |
|
76 |
| |
|
77 |
| |
|
78 |
| |
|
79 |
| |
|
80 |
9
| protected void rewindFormComponent(IMarkupWriter writer, IRequestCycle cycle)
|
|
81 |
| { |
|
82 |
9
| IUploadFile file = getDecoder().getFileUpload(getName());
|
|
83 |
| |
|
84 |
9
| if (HiveMind.isBlank(file.getFileName()))
|
|
85 |
| { |
|
86 |
0
| file = null;
|
|
87 |
| } |
|
88 |
| |
|
89 |
9
| try
|
|
90 |
| { |
|
91 |
9
| getValidatableFieldSupport().validate(this, writer, cycle, file);
|
|
92 |
| |
|
93 |
9
| setFile(file);
|
|
94 |
| } |
|
95 |
| catch (ValidatorException e) |
|
96 |
| { |
|
97 |
0
| getForm().getDelegate().record(e);
|
|
98 |
| } |
|
99 |
| } |
|
100 |
| |
|
101 |
| |
|
102 |
| |
|
103 |
| |
|
104 |
| public abstract ValidatableFieldSupport getValidatableFieldSupport(); |
|
105 |
| |
|
106 |
| |
|
107 |
| |
|
108 |
| |
|
109 |
| public abstract MultipartDecoder getDecoder(); |
|
110 |
| |
|
111 |
| |
|
112 |
| |
|
113 |
| |
|
114 |
0
| public boolean isRequired()
|
|
115 |
| { |
|
116 |
0
| return getValidatableFieldSupport().isRequired(this);
|
|
117 |
| } |
|
118 |
| } |