XPage file upload control loses filename on refresh - xpages

I'm sure I must be just missing something simple here but I've searched everywhere for an answer and no luck.
I have a bog standard file upload control on my xpage showing initially the standard "No file chosen", I select the "Choose file" button which overwrites the "No file chosen" with the selected filename - all good! BUT on any subsequent partial or full refresh of the page the filename is disappearing and reverting to "No file chosen". If I submit the form anyway the file is still uploaded correctly to the server but this is obviously no good for the user who thinks they have to reselect the file.
Can someone just tell me what I'm doing wrong here??
<xp:fileUpload id="songAlbumUpload1" value="#{submitfile.File1}">
<xp:eventHandler event="onchange" submit="true"
refreshMode="complete" disableValidators="true">
</xp:eventHandler>
</xp:fileUpload>
Note this was my latest attempt using a full refresh but I've tried all other partial refresh options too. Also my upload control is in a formTableRow so I tried moving it out into the main panel but the issue still occurs.
(I have also discovered the bug where a refresh ends up uploading multiple instances of the same file which as I understand it is fixed by a partial refresh of the panel the upload control is contained in - but of course this required refresh then causes the above issue anyway)!
Many thanks.

As indicated by Frantisek, upon refresh the fileUpload returns to a "No File Chosen" display indicating its ready to upload another file. Try removing the eventHandler to preserve the uploaded filename:
<xp:fileUpload id="songAlbumUpload1" value="#{submitfile.File1}"></xp:fileUpload>
Or add a fileDownload and bind it to the same RTF to display the status of the uploaded files.
<xp:fileDownload rows="30" id="fileDownload1" value="#{submitfile.File1}" displayLastModified="true"
allowDelete="true" hideWhen="false" style="width:100.0%">
</xp:fileDownload>

Related

Clear FacesMessage on clicking FileUpload

I have a page to upload a file. If there is a message on the page previously due to success/failure of some operation, I want it to go away as soon as I click the button to Upload a file. But I saw that update only works after the file upload completes.
Assuming you are using PF8+ since you did not mention your version you can remove it with Jquery on Adding of file...
<p:fileUpload onAdd="$('.ui-messages').css('display','none');" ...
The above is shortened for brevity but basically hides the messages when you add a file.

Error when opening an XPage - cannot load document

Am coming across an intermittent problem when opening an Xpage. I have a button on a dialog to open another XPage in a new browser window, the code in the button is
var path = facesContext.getExternalContext().getRequest().getContextPath();
var xpage = "Claim.xsp"
var fullpath = path + "/" + xpage;
var url = fullpath + "?action=openDocument&documentId="+ Action.claimDocID
view.postScript("window.open('" + url + "')"
(if anyone has another way instead of the view.postScript let me know, just couldn't figure out how to open in a new browser window)
Occasionally when the window opens I'll get an error - Could not open document, below is the entry in the log.
05/04/2017 08:26:10 AM HTTP JVM: CLFAD0131E: Unable to push data because: Could not open the document. For more detailed information, please consult error-log-0.xml located in C:/IBM/Domino/data/domino/workspace/logs
05/04/2017 08:26:10 AM HTTP JVM: com.ibm.xsp.webapp.FacesServlet$ExtendedServletException: com.ibm.xsp.FacesExceptionEx: Could not open the document
CLFAD0131E: Unable to push data because: Could not open the document com.ibm.xsp.FacesExceptionEx: Could not open the document at com.ibm.xsp.model.domino.DominoDocumentData.doOpenDocument(DominoDocumentData.java:529) at com.ibm.xsp.model.AbstractDocumentDataSource.openDocument(AbstractDocumentDataSource.java:148) at com.ibm.xsp.model.AbstractDocumentDataSource.load(AbstractDocumentDataSource.java:100) at com.ibm.xsp.model.AbstractDataSource.getDataContainer(AbstractDataSource.java:474) at com.ibm.xsp.model.domino.DominoDocumentData.getDataObject(DominoDocumentData.java:165) at com.ibm.xsp.model.AbstractDataSource.pushData(AbstractDataSource.java:576) at com.ibm.xsp.util.DataPublisher.publishControlData(DataPublisher.java:181) at com.ibm.xsp.component.UIViewRootEx.publishControlData(UIViewRootEx.java:1288) at com.ibm.xsp.component.UIViewRootEx.initBeforeContents(UIViewRootEx.java:1615) at com.ibm.xsp.page.compiled.AbstractCompiledPage.init
<-- is from the error-log-0.xml
BUT, when I press reload on the browser the page loads, so the URL is correct. I placed all sorts of print statements on the XPage, in the Java managed bean it also uses, and when the error occurs nothing is printed. The error is immediate, whereas when reloading it takes time and the messages are printed. After the first error, it doesn't occur again.
A couple of other things about this application, it is password protected, it is running on HTTPS. The XPage it loads does have a Notes document that's located in another database plus it uses a Managed bean. If anyone has any ideas be grateful.
Thanks
Cameron
In regards to opening a given page in a new tab: have you tried using a link control instead of a button? Set a computed target url (preferably under "All Properties >> data >> value") AND set the target property to "_blank" ("All Properties >> basics >> target")
Using css you can later on modify the link to look like a button, if that's needed.
Btw: in general there's no need to calculate the path if you stay within the same database; the XSPcontext sees the .nsf as a common root. Just have your url point to "/myNewPage.xsp" then add the query string accordingly, like
var url = "/" + xpage + "?action=openDocument&documentId="+ Action.claimDocID
This error happens when universal ID provided to documentId URL parameter is invalid - possibly a document from another database or user has no access to it (readers field).
Just use a link with a target="_blank" parameter:
<xp:link value="/my_page_name.xsp" text="to the infinity and beyond" target="_blank">
<xp:this.parameters>
<xp:parameter name="action" value="openDocument" />
<xp:parameter name="documentId" value="#{Action.claimDocID}" />
</xp:this.parameters>
</xp:link>
I have same error. In My Case I was remove field In Shared Elements. After Field was restored, error is disappear.

XPages: Wait for backend document to be saved and reload

In one of my XPages application (for Client, XPiNC) I have a link to "Edit" an attachment of this document. I use the technology described in this blog article to get the attachment edited.
In that scenario I have three windows interacting:
The XPage (XPiNC) containing the document where the link is clicked
The Notes Document (called by notes:// URL) containing the attachment
The application window containing the launched attachment (e.G. MS Word).
I managed to let the notes document (2) wait for the application (3) to finish and upload the modified attachment.
Now I need the XPage to wait for the backend change to occur and then to reload the XSP Document from the backend document to prohibit save conflicts.
I think the easiest way would be to pull out the attachments to attachment documents that are responses to the current document, but this is a rather old application that has large amounts of data in many many databases, and it is not feasible to convert all of these existing documents for that.
Now I search for the second best way to do it.
So again the question: How can I make the XPage "wait" for a backend change to occur and then reload the current page.
Second: How do I best "visualize" to the user, that something is running in the backend (Spinner, fade out, etc.).
The servers are 9.0.1FP2, the Clients unfortunately are 8.5.3 (cannot be updated at the moment).
Here is the Code, that I use in my "Open" Link:
<xp:link escape="true" text="Edit" id="attachmentEdit">
<xp:eventHandler event="onclick"
submit="true" refreshMode="partial" refreshId="tableAttachment">
<xp:this.action><![CDATA[#{javascript:var strAttachmentName:String = docs.toString();
var strReplid = database.getReplicaID();
var strUnid = document1.getDocument().getUniversalID();
var strServer = #Name( "[CN]" , database.getServer() );
var strUrl:String = "notes://" + strServer + "/"+strReplid+"/(ShowAttachment)?OpenForm";
session.setEnvironmentVar("InfothekCurrentAction","EDIT~" + strUnid + "~" + strAttachmentName);
view.postScript('window.location.href="'+strUrl+'"');}]]>
</xp:this.action>
</xp:eventHandler>
</xp:link>
I am using an xagent for that. Thats what i do:
1) I am setting the background of a div to a moving css gradient.
2) Set the src of the div to an xagent that is doing some things in the backend
3) The xagent is calling some csjs after its loaded(in your case, you could call a button to refresh the page)
Take a look at this proof-of-concept demo: http://dontpanic82.blogspot.sk/2010/01/xpages-custom-control-that-can-help.html
Simple CSJS chcecks for updated property of the document. In case it was modified (attachment saved), you can show pop up or just reload the XPage.

File validation on XPages

I am working on application in XPages and I need to do file upload validation on the server side.
I read that file upload only works on client side, so I tried to validate another filed that stores file name attached. I did it on the on change event of the file upload. The problem occurs when I delete an attached file- there is no on change event on file download control… any suggestions? Or maybe different way?
Thanks
Unsaved list of attachments can be accessed from the getAttachmentList("RTFieldName") method of the data source.
I suggest using a hidden input and custom validator to have more control, like:
<xp:message
id="message1"
for="inputHidden1"></xp:message>
<xp:br></xp:br>
<xp:inputHidden
id="inputHidden1"
value="arbitrary">
<xp:this.validators>
<xp:customValidator>
<xp:this.validate><![CDATA[{javascript:
// RTField the name of the rich text field that holds attachments
if(document1.getAttachmentList("RTField").size()==0) {
// You might want to do more checks here.
var inputHidden1 = getComponent("inputHidden1");
inputHidden1.setValid(false);
return "You have to upload a file!" // your error message
}}]]></xp:this.validate>
</xp:customValidator>
</xp:this.validators>
</xp:inputHidden>
Remember, value="arbitrary" is important. Empty fields will not trigger custom validators.

To fire file upload control on click event - xpage

Can anyone please advise how to fire file upload control in Xpage during OnClick or Onfocus event in IE? it works by default in Firefox.
Strictly speaking, when a person selects a file in the File Upload control, after it associates with the file, it is prepared for uploading (request phase data). The native control has a couple things to lack that I wish for in future releases, but basically to achieve "Upload" button functionality, which I recommend for reasons below, you should:
Create a button control which triggers a Full Refresh (returning true if the SSJS getFilename() off the fileUpload control is true); note it must be a Full Refresh!
Make sure you run it with "Process data without validation" checked (aka- disableValidators="true")
Your button should read like:
<xp:button value="Upload" id="button1">
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete" disableValidators="true">
<xp:this.action><![CDATA[#{javascript:
getComponent("fileUpload1").getFilename()?true:false}]]></xp:this.action>
</xp:eventHandler>
</xp:button>
All the users I've run into expect an "Upload" button. I'm not saying this is the best or most optimal way, but it is what people look for. My experience has taught me to cater to the users' expectations. They may be wrong to expect such, but it makes sense in the context of what we're doing here at least.
I'm sure there's a way of triggering a full refresh automatically, possibly with an onComplete event. I'm not sure whether this could be an onBlur event for the xp:fileUpload control or would be a different listener off the getComponent("fileUpload1").getFilename() value. Perhaps a more experienced XPage Dev. can answer that specifically.
Hope this helps.

Resources