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 |
2
| protected void renderFormComponent(IMarkupWriter writer, IRequestCycle cycle)
|
46 |
| { |
47 |
| |
48 |
2
| IForm form = getForm();
|
49 |
| |
50 |
2
| form.setEncodingType("multipart/form-data");
|
51 |
| |
52 |
2
| renderDelegatePrefix(writer, cycle);
|
53 |
| |
54 |
2
| writer.beginEmpty("input");
|
55 |
2
| writer.attribute("type", "file");
|
56 |
2
| writer.attribute("name", getName());
|
57 |
| |
58 |
2
| if (isDisabled())
|
59 |
| { |
60 |
1
| writer.attribute("disabled", "disabled");
|
61 |
| } |
62 |
| |
63 |
2
| renderIdAttribute(writer, cycle);
|
64 |
| |
65 |
2
| renderDelegateAttributes(writer, cycle);
|
66 |
| |
67 |
2
| getValidatableFieldSupport().renderContributions(this, writer, cycle);
|
68 |
| |
69 |
2
| renderInformalParameters(writer, cycle);
|
70 |
| |
71 |
2
| writer.closeTag();
|
72 |
| |
73 |
2
| renderDelegateSuffix(writer, cycle);
|
74 |
| } |
75 |
| |
76 |
| |
77 |
| |
78 |
| |
79 |
| |
80 |
3
| protected void rewindFormComponent(IMarkupWriter writer, IRequestCycle cycle)
|
81 |
| { |
82 |
3
| IUploadFile file = getDecoder().getFileUpload(getName());
|
83 |
| |
84 |
3
| if (HiveMind.isBlank(file.getFileName()))
|
85 |
| { |
86 |
0
| file = null;
|
87 |
| } |
88 |
| |
89 |
3
| try
|
90 |
| { |
91 |
3
| getValidatableFieldSupport().validate(this, writer, cycle, file);
|
92 |
| |
93 |
3
| 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 |
| } |