Ich habe eine nette Bootstrapped-Datei-Steuerelement.Xpages: So integrieren Sie Bootstrapped Xpage FileUploadControl mit gesicherten Java-Klasse
Diese Datei Kontrolle I bindet die Bahn bekam bilden Quelle zu einem Dokumentdaten. Meine Dokumente werden von einer Java-Bean unterstützt und ich verwende ObjectDataSource, um diese Bean an die X-Seite zu binden.
Ich weiß jedoch nicht, wie das Anlagefeld an das Dateiuploadsteuerelement gebunden wird. Der entsprechende Code in der Xpage
ist wie folgt:
//Data Object
<xp:this.data>
<xe:objectData
saveObject="#{javascript://BuildTaskMaster.save()}" var="task">
<xe:this.createObject><![CDATA[#{javascript:var task = new com.scoular.model.Task();
var unid = sessionScope.get("unid");
if (unid != null) {
task.loadByUnid(unid);
} else {
task.create();
}
return task;}]]></xe:this.createObject>
</xe:objectData>
</xp:this.data>
//Bootstraped File Uploaded
<script type="text/javascript" src="bootstrapfileinput4/js/fileinput.js"></script>
<link rel="stylesheet" href="bootstrapfileinput4/css/fileinput.css" media="all" type="text/css" />
<xp:scriptBlock id="scriptBlockInitFile">
<xp:this.value>
<![CDATA[
$(document).ready(
function() {
$('input[type=file]').fileinput({
previewFileType: "image",
browseClass: "btn btn-primary",
browseLabel: "Browse",
browseIcon: '<i class="glyphicon glyphicon-plus"></i>',
removeClass: "btn btn-danger",
removeLabel: "Delete",
removeIcon: '<i class="glyphicon glyphicon-trash"></i>',
uploadClass: "btn btn-info",
uploadLabel: "Upload",
uploadIcon: '<i class="glyphicon glyphicon-upload"></i>',
});
}
);
]]>
</xp:this.value>
</xp:scriptBlock>
<xp:fileUpload id="fileUpload2" value="#{task.attachments}">
<xp:this.attrs>
<xp:attr name="accept" value="*" />
</xp:this.attrs>
</xp:fileUpload>
<xp:br></xp:br>
<xp:fileDownload rows="30" id="fileDownload1"
displayLastModified="true" value="#{task.attachments}"
hideWhen="true" allowDelete="true">
</xp:fileDownload>
<xp:button value="Save Document" id="button3" styleClass="btn btn-primary">
<xp:eventHandler event="onclick" submit="true" refreshMode="complete">
<xp:this.action>
<xp:actionGroup>
<xp:saveDocument></xp:saveDocument>
<xp:openPage name="/BootstrapFileInput4.xsp"></xp:openPage>
</xp:actionGroup>
</xp:this.action>
</xp:eventHandler>
</xp:button>
</xp:panel>
<xp:eventHandler event="onClientLoad" submit="true"
refreshMode="norefresh">
<xp:this.action><![CDATA[#{javascript:try {
dojo.byId("#{id:inputText1}").focus();
}
catch(e)
{}}]]></xp:this.action>
</xp:eventHandler>
<xp:scriptBlock id="scriptBlock1" loaded="false">
<xp:this.value><![CDATA[$(document).ready(
function() {
$('input[type=file]').fileinput({
previewFileType: "image",
browseClass: "btn btn-primary",
browseLabel: "Browse",
browseIcon: '<i class="glyphicon glyphicon-plus"></i>',
removeClass: "btn btn-danger",
removeLabel: "Delete",
removeIcon: '<i class="glyphicon glyphicon-trash"></i>',
uploadClass: "btn btn-info",
uploadLabel: "Upload",
uploadIcon: '<i class="glyphicon glyphicon-upload"></i>'
});
}
);]]></xp:this.value>
</xp:scriptBlock>
Der relevante Teil der Java-Klasse
public class Task implements Serializable {
private static final long serialVersionUID = 1L;
// Common Fields
private String unid;
private Boolean newNote;
private DateTime crtDte;
private String crtUsr;
// Custom Fields
private Number order;
private String title;
private String notes;
private UploadedFile attachments;
//In save method
if (attachments != null) {
//get the uploaded file
IUploadedFile attachment = attachments.getUploadedFile();
//get the server file (with a cryptic filename)
File serverFile = attachment.getServerFile();
//get the original filename
String fileName = attachment.getClientFileName();
File correctedFile = new File(serverFile.getParentFile().getAbsolutePath() + File.separator + fileName);
//rename the file to its original name
boolean success = serverFile.renameTo(correctedFile);
if (success) {
//do whatever you want here with correctedFile
//example of how to embed it in a document:
RichTextItem rtFiles = doc.createRichTextItem("attachments");
rtFiles.embedObject(lotus.domino.EmbeddedObject.EMBED_ATTACHMENT, "", correctedFile.getAbsolutePath(), null);
doc.save();
//if we're done: rename it back to the original filename, so it gets cleaned up by the server
correctedFile.renameTo(attachment.getServerFile());
}
}
public UploadedFile getAttachments() {
return attachments;
}
public void setFileUpload(UploadedFile to) {
this.attachments = to;
}
ich den Benutzer möchte in der Lage sein mehr Anlagen zu wählen, nicht eine ta Zeit.