【发布时间】:2016-04-29 03:51:30
【问题描述】:
我需要在我的应用程序中包含一个 Bootstrap 样式的文件上传控件。文件附件将存储在名为“附件”的富文本字段中的文档中。使用 Java 保存字段。
我查看了下面列出的网站以及 Oliver Busse 的网站,但我现在找不到他的链接。
我最终想要一个自定义控件。
我已将 bootstrapfileinput4 文件夹添加到我的 WebContent 文件夹中。
当我运行以下 Xpage 代码时出现错误。
Xpage 代码:
<?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>
我使用过的链接:
Bootstrap UI for XPages File Upload component
Bootstrap in XPages: Using the new Bootstrap Fileinput Plugin in XPages Part I
【问题讨论】:
-
你确定 bootstrapfileinput4/js/fileinput.js 已经加载了吗?检查网络属性并确保它不返回 404。您可能需要将完整路径(包括 nsf 的文件夹和文件名)添加到 src 标记。
-
Per,我最初是这么想的,但是我在 Chrome 中检查了,fileinput.js 和 fileinput.css 都加载了。
-
页面加载完成后,你能在控制台中手动运行 $('input[type=file]').fileinput() 吗?
-
我收到了同样的信息。这真的很奇怪。我相信我已经重启了测试网络服务器并重建了项目。
-
不需要重建,因为这是纯前端。我猜这是AMD加载程序的问题。检查 fileinput.js 是否使用 AMD,如果是,则从 js 文件中删除该部分