2017-04-26 72 views
0

我正在嘗試使用類似Bootstrap的外觀編寫fileUpload/fileDownload自定義控件。我很滿意這個外觀(見下文)。在Xpages中處理附件時遇到問題

enter image description here

不過,我變得非常不一致的行爲。我非常希望用戶能夠點擊刪除按鈕,並且刪除附件並刷新重複控件。以類似的方式,如果用戶選擇「上傳」,我認爲附件應該上傳到文檔,重複控制也會刷新。

我將附件存儲在與主文檔分開的單個文檔中[它存儲在與代碼分開的數據庫中]。

我正在使用上傳控件的js fileInput庫。

我正在使用重複控制滾動我自己的文件下載查看器。

該代碼適用於某些時間,但並非總是如此。當頁面失敗時,我得到這個錯誤信息(見下文)。

任何建議將不勝感激。

Context Path: /scoApps/OTM1/OTM1.nsf 
Page Name: /xpTest.xsp 
javax.faces.FacesException 
    at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:106) 
    at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:210) 
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:96) 
    at com.ibm.xsp.controller.FacesControllerImpl.execute(FacesControllerImpl.java:256) 
    at com.ibm.xsp.webapp.FacesServlet.serviceView(FacesServlet.java:228) 
    at com.ibm.xsp.webapp.FacesServletEx.serviceView(FacesServletEx.java:157) 
    at com.ibm.xsp.webapp.FacesServlet.service(FacesServlet.java:160) 
    at com.ibm.xsp.webapp.FacesServletEx.service(FacesServletEx.java:138) 
    at com.ibm.xsp.webapp.DesignerFacesServlet.service(DesignerFacesServlet.java:103) 
    at com.ibm.designer.runtime.domino.adapter.ComponentModule.invokeServlet(ComponentModule.java:576) 
    at com.ibm.domino.xsp.module.nsf.NSFComponentModule.invokeServlet(NSFComponentModule.java:1335) 
    at com.ibm.designer.runtime.domino.adapter.ComponentModule$AdapterInvoker.invokeServlet(ComponentModule.java:853) 
    at com.ibm.designer.runtime.domino.adapter.ComponentModule$ServletInvoker.doService(ComponentModule.java:796) 
    at com.ibm.designer.runtime.domino.adapter.ComponentModule.doService(ComponentModule.java:565) 
    at com.ibm.domino.xsp.module.nsf.NSFComponentModule.doService(NSFComponentModule.java:1319) 
    at com.ibm.domino.xsp.module.nsf.NSFService.doServiceInternal(NSFService.java:662) 
    at com.ibm.domino.xsp.module.nsf.NSFService.doService(NSFService.java:482) 
    at com.ibm.designer.runtime.domino.adapter.LCDEnvironment.doService(LCDEnvironment.java:357) 
    at com.ibm.designer.runtime.domino.adapter.LCDEnvironment.service(LCDEnvironment.java:313) 
    at com.ibm.domino.xsp.bridge.http.engine.XspCmdManager.service(XspCmdManager.java:272) 
Caused by: java.lang.IllegalArgumentException 
    at javax.faces.model.ListDataModel.getRowData(ListDataModel.java:141) 
    at com.ibm.xsp.component.UIRepeatContainer.addIndexedDataContext(UIRepeatContainer.java:173) 
    at com.ibm.xsp.component.UIRepeatContainer.getDataContexts(UIRepeatContainer.java:86) 
    at com.ibm.xsp.util.DataPublisher.getDataContextList(DataPublisher.java:349) 
    at com.ibm.xsp.util.DataPublisher.revokeControlData(DataPublisher.java:271) 
    at com.ibm.xsp.component.UIDataPanelBase.revokeControlData(UIDataPanelBase.java:319) 
    at com.ibm.xsp.component.UIDataPanelBase.processDecodes(UIDataPanelBase.java:334) 
    at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1177) 
    at com.ibm.xsp.component.UIRepeat.processDecodes(UIRepeat.java:526) 
    at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1177) 
    at com.ibm.xsp.component.UIDataPanelBase.processDecodes(UIDataPanelBase.java:331) 
    at javax.faces.component.UIForm.processDecodes(UIForm.java:166) 
    at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1177) 
    at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1177) 
    at javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:343) 
    at com.ibm.xsp.component.UIViewRootEx._processDecodes(UIViewRootEx.java:1438) 
    at com.ibm.xsp.component.UIViewRootEx.processDecodes(UIViewRootEx.java:1399) 
    at com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:98) 
<?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" databaseName="scoApps\OTM1\OTM1Data.nsf" formName="attachment" action="editDocument" documentId="349CDB2FB259D5D3862581090076AC50" /> 
    </xp:this.data> 
    <script src="fileinput/js/fileinput.js" type="text/javascript" /> 
    <link href="fileinput/css/fileinput.min.css" media="all" rel="stylesheet" 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", 
}); 
} 
);]]></xp:this.value> 
    </xp:scriptBlock> 
    <xp:div themeId="container" style="width:800px"> 
     <xp:br /> 
     <xp:fileUpload id="fileUpload1" value="#{document1.attachments}"> 
     <xp:this.attrs> 
      <xp:attr name="multiple" value="true" /> 
      <xp:attr name="data-show-preview" value="false" /> 
     </xp:this.attrs> 
     </xp:fileUpload> 
     <xp:br /> 
     <xp:button value="Save Changes" id="button1" styleClass="btn btn-primary"> 
     <xp:eventHandler event="onclick" submit="true" refreshMode="complete" disableValidators="true"> 
      <xp:this.action> 
       <xp:actionGroup> 
        <xp:save /> 
       </xp:actionGroup> 
      </xp:this.action> 
     </xp:eventHandler> 
     </xp:button> 
    </xp:div> 
    <xp:repeat rows="30" id="attrepeat" first="0" var="att" indexVar="attachmentIndex"> 
     <xp:this.facets> 
     <xp:text disableTheme="true" xp:key="header" escape="false"> 
      <xp:this.value><![CDATA[<table class="table table-striped table-bordered table-hover"><col width="150"><col width="450"><th>File Name</th><th style="text-align:right">Delete</th>]]></xp:this.value> 
     </xp:text> 
     <xp:text disableTheme="true" xp:key="footer" escape="false"> 
      <xp:this.value><![CDATA[</table>]]></xp:this.value> 
     </xp:text> 
     </xp:this.facets> 
     <xp:this.value><![CDATA[#{javascript:var bckDoc = document1.getDocument() 
var attachments:java.util.Vector = session.evaluate("@AttachmentNames",bckDoc); 
attachments}]]></xp:this.value> 
     <xp:tr> 
     <xp:td> 
      <xp:link escape="true" id="link1" target="_blank" text="#{javascript:att.toString();}"> 
       <xp:this.value><![CDATA[#{javascript:var tmpStr:String; 
var str:String; 
var bckDoc = document1.getDocument()  
var attachments:java.util.Vector = session.evaluate("@AttachmentNames",bckDoc); 
tmpStr = attachments.toString; 
tmpStr 

var bckDoc = document1.getDocument()  
var attachments:java.util.Vector = session.evaluate("@AttachmentNames",bckDoc); 
tmpStr = attachments.elementAt(0); 


var unid = "349CDB2FB259D5D3862581090076AC50" 


var dbPath = "scoApps/OTM1/OTM1.nsf/" 
var dbDataPath = "scoApps/OTM1/OTM1Data.nsf/" 

var url = "http://localhost/"; 
url += dbPath; 
url += "/xsp/.ibmmodres/domino/OpenAttachment/"; 
url += dbDataPath + "/"; 
url += unid 
url += "/" + "attachments" + "/"; 
url += tmpStr; 
url}]]></xp:this.value> 
       <xp:image id="image1" rendered="false"> 
        <xp:this.url><![CDATA[#{javascript:var pdfImage = 'pdf.gif'; 
//if(attachment.indexOf("pdf")> 0) 
return pdfImage;       }]]></xp:this.url> 
       </xp:image> 
       &amp;#160; 
      </xp:link> 
     </xp:td> 
     <xp:td style="text-align:right"> 
      <xp:button value="Delete" id="button2" styleClass="btn btn-danger"> 
       <xp:eventHandler event="onclick" submit="true" refreshMode="complete"> 
        <xp:this.action><![CDATA[#{javascript:function removeAttachment(targDB,doc_Url,fileName,docUnid2) { 

//passing parameters by reference 
var docUrl:String= doc_Url; 


var targetDB:NotesDatabase = session.getDatabase(session.getCurrentDatabase().getServer(),targDB); 
var attachmentName:String =fileName; 

//deducing the document's unid from the document's url 
//[email protected](docUrl,"?"); 
//var [email protected](docUrl,"/"); 
print (docUnid2); 

//setting the handle to the document 
var docContext:NotesDocument=targetDB.getDocumentByUNID(docUnid2); 
if (docContext==null) { 
    viewScope.CodeError="Either the UNID is invalid or the target db does not contain the doc or both"; 
    return; 
} 


//getting the handle to the concerned attachment 
var embObj:NotesEmbeddedObject=docContext.getAttachment(attachmentName); 
if (embObj==null) { 
    viewScope.CodeError="No attachment is found by the name "+ attachmentName; 
    return; 
} 

//remove the attachment 
embObj.remove() 
docContext.save(true,false); 
} 

var fleNme = att.toString(); 
print (fleNme); 
removeAttachment("scoApps/OTM1/OTM1Data.nsf","http://localhost/scoApps/OTM1/OTM1.nsf//xsp/.ibmmodres/domino/OpenAttachment/scoApps/OTM1/OTM1Data.nsf//349CDB2FB259D5D3862581090076AC50/attachments/ITReport.xlsx",fleNme,"349CDB2FB259D5D3862581090076AC50");}]]></xp:this.action> 
       </xp:eventHandler> 
      </xp:button> 
     </xp:td> 
     </xp:tr> 
    </xp:repeat> 
</xp:view> 

回答

1

它的失敗在ApplyRequestValues階段,涉及到的重複行內代碼運行的東西。我之前在數據視圖中使用緩存僅爲ID。關鍵是確定哪個組件的代碼失敗(重複的值,鏈接,圖像或按鈕 - 如果它是一個組件,哪個屬性)以及是否需要在該階段運行。它可能不會。

看着堆棧跟蹤,getRowData()上的「原因」位失敗意味着它可能是重複的value的問題,但我不完全確定。它可能是重複的子組件之一失敗。

如果它是一個只讀的代碼位,它可以封裝在一個if (view.isRenderingPhase())塊中。只要確保輸出了一些對其他階段有效的東西!例如。對於rendered屬性,設置結果爲其它階段true(我已經錯過了前並造成自己的問題!)

如果是因爲document數據源尚未在該階段初始化,在面板中包一切可能通過將dominoDocument數據源關聯到面板的子項來解決問題,這可能會促使它在restoreView階段更好地重新初始化。這是在黑暗中的總刺傷,但我知道在頁面加載時,dominoDocument數據源在不同時間加載時,它是Panel的子項,而不是XPage本身的子項。

相關問題