我有一个自定义UIInput包装在一个复合组件中,如下所示:
<cc:interface componentType="SingleUpload">
<cc:attribute name="value" required="true" />
...
</cc:interface>
<cc:implementation>
...
<p:fileUpload id="fileUpload" update="@form" auto="true"
fileUploadListener="#{cc.fileUploaded}" rendered="#{cc.attrs.value == null}"/>
...
<h:commandButton rendered="#{cc.attrs.value != null}" action="#{cc.removeFile}">
<p:ajax execute="@this" update="@form" />
</h:commandButton>
...
</cc:implementation>
支持组件如下所示:
@FacesComponent(value = "SingleUpload")
public class SingleUpload extends UIInput implements NamingContainer, Serializable {
/** */
private static final long serialVersionUID = 2656683544308862007L;
@Override
public String getFamily() {
return "javax.faces.NamingContainer";
}
public void fileUploaded(FileUploadEvent event) throws IOException {
FileData file = new FileData();
file.setContentMimeType(MimeTypeUtils.getContentType(event.getFile().getContentType(), event.getFile().getFileName()));
file.setInputStream(event.getFile().getInputstream());
file.setName(FilenameUtils.getName(event.getFile().getFileName()));
setValue(file);
}
public void removeFile() {
resetValue();
// value should be null now, but it is not, why??
FileData value=(FileData) getValue();
}
}
以这种方式使用:
<ki:singleUpload value="#{fileModel.file}" title="File Upload" />
因此,当调用动作removeFile
时,我想将值设置为null。当我按照以下步骤操作时,这是有效的:
fileModel.file == null
)value
不再为空但是,当我做以下
时fileModel.file != null
)removeFile
)=&GT;从组件中删除值似乎是不可能的。为什么?