0
votes

I need to include a Bootstrap style file upload control in my application. The file attachments will be stored in a document in a richtextfield called "attachments". Using Java to save fields.

I have looked at the web sites listed below as well as one that Oliver Busse did, but I cannot find his link now.

I would like a custom control eventually.

I have added the bootstrapfileinput4 folder to my WebContent folder.

enter image description here

When I run the following Xpage code I get an error.

enter image description here

Xpage code:

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"
xmlns:xc="http://www.ibm.com/xsp/custom">
<xp:this.data>
<xp:dominoDocument var="document1" formName="Contact"></xp:dominoDocument>
</xp:this.data>
<xp:this.resources>
<xp:script src="/jQueryXSnippet.js" clientSide="true"></xp:script>
</xp:this.resources>
<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>
<xc:ccLayoutBootstrap>
<xp:this.facets>
<xp:panel xp:key="facetMiddle">
<xp:br></xp:br>
<div class="page-header">
<h1>
FileInput
<xp:span style="color:rgb(255,255,255)"></xp:span><small>Bootstrap FileInput Plugin</small>
</h1>
</div>    
<xp:fileUpload id="fileUpload1"
value="#{document1.fileAttachment}">
<xp:this.attrs>
<xp:attr name="accept" value="image/*" />
</xp:this.attrs>
</xp:fileUpload>
<xp:br></xp:br>
<xp:fileDownload rows="30" id="fileDownload1"
displayLastModified="true" value="#{document1.fileAttachment}"
hideWhen="true" allowDelete="true">
</xp:fileDownload>    
<xp:button value="Save Document" id="button1" 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:br></xp:br>
</xp:panel>
</xp:this.facets>
</xc:ccLayoutBootstrap>
</xp:view>

Links that I have used:

Bootstrap UI for XPages File Upload component

Bootstrap in XPages: Using the new Bootstrap Fileinput Plugin in XPages Part I

1
Are you sure that bootstrapfileinput4/js/fileinput.js is loaded? Check network properties and make sure it doesn't return 404. You might need to add the full path including the folder and filename of your nsf to the src tag.Per Henrik Lausten
Per, that is what I originally thought, but I checked in Chrome and fileinput.js and fileinput.css are both loaded.Bryan Schmiedeler
Can you run $('input[type=file]').fileinput() manually in the console once the page has loaded?Per Henrik Lausten
I get the same message. This is really weird. I believe I have already restarted the test web server and rebuilt the project.Bryan Schmiedeler
No rebuild needed since this is pure front end. I guess it's an AMD loader issue. Check if fileinput.js uses AMD and if so then remove that part from the js filePer Henrik Lausten

1 Answers

1
votes

I guess it's an AMD loader issue. Check if fileinput.js uses AMD and if so then remove that part from the js file (see this answer for instance).