Change an eventHandlers refreshMode depending on client side value? - xpages

I have a submit button on top that's normally doing a partial refresh of the form.
When I added a fileUpload control that won't due, as I need to do a full refresh. But I only wish this to happen if the user has added a file to be uploaded. So if the file Upload is empty I want to use a partialRefresh to submit.
I can check if a file is added easily enough and I could have two buttons with different refresh modes and hide them using JS, but that's a clunky solution.
What I would like to do is change the refresh mode on the submit button depending on a submitted value in the current form.
Any ideas?
Thanks!
/J

You can do this by adding a second event handler to your button: One event handler is for a full refresh, the other one for the partial refresh.
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:div id="divRefresh">
<xp:label value="#{javascript:java.lang.System.currentTimeMillis()}" id="label1" />
<xp:label value="#{javascript:java.lang.System.currentTimeMillis()}" id="label2" />
</xp:div>
<xp:br></xp:br>
<xp:button value="Refresh" id="button1">
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete">
<xp:this.script>
<![CDATA[alert("Complete!"); return false;]]>
</xp:this.script>
</xp:eventHandler>
<xp:eventHandler event="onclick" submit="true"
refreshMode="partial" refreshId="label2">
<xp:this.script>
<![CDATA[alert("Partial!");return true;]]>
</xp:this.script>
</xp:eventHandler>
</xp:button>
</xp:view>
The CSJS code in the events has to return false to stop the event.

I do this in http://www.intrapages.com when posting new stream content.
in the onchange event for the upload control I set a requestScope variable. and if that is set I perform a full refresh. works great

Related

XPages: can a Depositor modify a document?

I created a user Guest with Depositor rights. He can also Read and Write Public Documents. The test document I created has a field $PublicAccess with value "1". To open the document in the Guest XPage using a browser, I use this URL:
https:://domain/database.nsf/Guest.xsp?documentId=E696&action=editDocument
The page opens, the Summary field is filled from the document with ID=E696, but it stays read-only. If I add a 2nd dominoDocument that creates a new document, that field is editable, and clicking the Save button will save the data.
Is it possible to allow a Depositor to modify a Public document?
Here's my simple XPage:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:this.data>
<xp:dominoDocument var="document1" formName="ABC"></xp:dominoDocument>
<xp:dominoDocument var="document2" formName="XYZ" ignoreRequestParams="true"></xp:dominoDocument>
</xp:this.data>
Summary
<xp:br></xp:br>
<xp:inputText id="inputText1" value="#{document1.Summary}"></xp:inputText>
<xp:br></xp:br>
Code
<xp:br></xp:br>
<xp:inputText id="inputText2" value="#{document2.Code}"></xp:inputText>
<xp:br></xp:br>
<xp:br></xp:br>
<xp:button value="Save" id="button1">
<xp:eventHandler event="onclick" submit="true" refreshMode="complete">
<xp:this.action>
<xp:saveDocument var="document2"></xp:saveDocument>
</xp:this.action>
</xp:eventHandler>
</xp:button>
</xp:view>
What I found out is that the presence of any valid non-empty Authors field (e.g. with a name or a role) will block edit access for Anonymous or a Depositor. My "solution" is to change the Authors property, by using setAuthors(false) on every Authors field.

XPages Dynamic Content Control: Hash does not update when clicking browser's back button

I have a very simple XPage that contains two links and a dynamic content control. If I click on the Page 1 link the hash is set to #content=page1 then I click on Page 2 link and the hash is set to #content=page2. Now I click the browser's back button and the facet switches to page1 but the hash stays at #content=page2 and the browser's forward button is grayed out. It looks like the URL flickers to me so it might be getting overwritten but I can't say for sure.
I am using Extension Library version 901v00_16.20160128-1014 and I have tested using Chrome and Firefox.
My XPage:
<xp:link escape="true" styleClass="list-group-item" text="Page 1" id="link1">
<xp:eventHandler event="onclick" submit="true" refreshMode="partial" id="eventHandler2" refreshId="dynamicContent1">
<xp:this.action><![CDATA[#{javascript:var c = getComponent("dynamicContent1"); c.show("page1")}]]></xp:this.action>
</xp:eventHandler>
</xp:link>
<xp:link escape="true" styleClass="list-group-item" text="Page 2" id="link2">
<xp:eventHandler event="onclick" submit="true" refreshMode="partial" id="eventHandler1" refreshId="dynamicContent1">
<xp:this.action><![CDATA[#{javascript:var c = getComponent("dynamicContent1"); c.show("page2")}]]></xp:this.action>
</xp:eventHandler>
</xp:link>
<xe:dynamicContent id="dynamicContent1" partialEvents="true" useHash="true" defaultFacet="page1">
<xp:this.facets>
<xp:div id="page1" xp:key="page1">Page 1</xp:div>
<xp:div id="page2" xp:key="page2">Page 2</xp:div>
</xp:this.facets>
</xe:dynamicContent>
I have been using the Extension Library Demo database: Core_DynamicPage.xsp page as a reference and this seems to works fine in there.
After changing my xsp property for "Minimum Supported Release" from "Release 9.0.1" to "Minimum release required by the XPage features used" the issue went away.

Setting focus to first field of a tab on a tabbed table

When a user clicks on a tab of a tabbed table, I want to be able to set the focus tot the first field on that tab.
Each tab seems to only have one event mouse onclick. So I tried placing the following code in one of that tab's onclick events.
var f = dojo.byId('#{id:NotInvitedMsg}');
if (f != null)
f.focus();
But when I click on the tab nothing happens. And I mean nothing. The tab can no longer be selected and the script is never executed.
Any way around this?
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:tabbedPanel id="tabbedPanel1">
<xp:tabPanel label="New Tab" id="tabPanel1">
<xp:panel>
<xp:inputText id="inputText1"></xp:inputText>
<xp:eventHandler event="onClientLoad" submit="false">
<xp:this.script><![CDATA[var edit = dojo.byId("#{id:inputText1}");
if (edit) {
edit.focus()
}]]></xp:this.script>
</xp:eventHandler>
</xp:panel>
</xp:tabPanel>
<xp:tabPanel label="New Tab2" id="tabPanel2">
<xp:panel>
<xp:inputText id="inputText2"></xp:inputText>
<xp:eventHandler event="onClientLoad" submit="false">
<xp:this.script><![CDATA[var edit = dojo.byId("#{id:inputText2}");
if (edit) {
edit.focus()
}]]></xp:this.script>
</xp:eventHandler>
</xp:panel>
</xp:tabPanel>
</xp:tabbedPanel>
</xp:view>
This is working code (tested on Chrome and IE9). It uses simple trick I saw few days ago (and I want to apologize to original author, I couldn't manage to find the original post): to create onClientLoad event at XP/CC level, and to move event handler in source view into the panel body. Works like charm...
Try the HTML5 Autofocus attribute:
<xp:inputText id="field1" value="#{document.Field1}">
<xp:this.attrs>
<xp:attr name="autofocus" value="autofocus"></xp:attr>
</xp:this.attrs>
</xp:inputText>
One caveat: The autofocus attribute is supported in all major browsers, except Internet Explorer.
This might not be exactly what you´re looking for, but maybe it can be of some help..
Link -> How can I set focus to Edit Box inside repeat control?

ExtLib Mobile Controls - How to build a button to switch to an appPage

I'm working on an XPage for mobile users for an existing application. I want to use the mobile controls from the ExtLib for this.
I've build an XPage with a SinglePageApp and some AppPages on it. Now I want to build an AppPage with a search menu, a simple inputText and a button to start the search.
The inputText is bind to a sessionScope variable. I want to use the variable in a second appPage to get the search value and show a filtered/searched view.
The problem is the button. I'm not sure how to build this button to move to the other appPage. This is my last attempt, which fails with a runtime error.
Any idea how to get this running or what's wrong ?
Kind regards
Ingo
<xe:appPage id="appPage34" pageName="searchPage" preload="true" resetContent="true">
<xe:djxmHeading id="djxmHeading34" label="Search..." back="Home" moveTo="home">
</xe:djxmHeading>
<xp:inputText id="searchInput" value="#{sessionScope.searchValue}">
</xp:inputText>
<xp:button value="Search" id="button1" refreshMode="complete" type="submit">
<xp:eventHandler event="onclick" submit="true">
<xp:this.action>
<xe:moveTo targetPage="#searchResult"></xe:moveTo>
</xp:this.action>
</xp:eventHandler>
</xp:button>
</xe:appPage>
What does the runtime error say?
If you can not get to the XPages log files on the server directly, then use XPages Log File Reader from OpenNTF to get easy access to the log files from a browser.
Does it work if you use "searchResult" as the value for targetPage (assuming the appPage is called "searchResult")?
I've now come to a solution with a static line item instead of a button, since I couldn't get the button working. I think it has something to do with the way the single page application handles the access to mobile pages.
The search page looks like this :
<xe:appPage id="appPage34" pageName="searchPage" preload="true" resetContent="true">
<xe:djxmHeading id="djxmHeading34" label="Search..." back="Home" moveTo="home">
</xe:djxmHeading>
<xp:inputText id="searchInput" value="#{sessionScope.searchValue}">
<xp:eventHandler event="onblur" submit="true" refreshMode="complete">
<xp:this.action>
<xp:executeScript>
<xp:this.script><![CDATA[#{javascript:var svalue = getComponent("searchInput").getValue(); sessionScope.put("searchValue",svalue);}]]></xp:this.script>
</xp:executeScript>
</xp:this.action>
</xp:eventHandler>
</xp:inputText>
<xp:br></xp:br>
<xp:br></xp:br>
<xe:djxmLineItem id="djxmLineItem41" label="Start Search..." moveTo="#searchResult">
</xe:djxmLineItem>
</xe:appPage>
In the mobile page for showing the search result I simply get the value of the sessionScope variable, issue a full text search with the value and use the resulting document collection in a repeat control.
I still would rather use a button because the static line item is not really what a user expects as a gui element to start the search. But at least this is working.

Disabled Check Box Loses Value When Saving

I have a check box that is disabled. I click a button that sets the value of that check box to be 'checked'. When I go to save, the check box loses its value. Anyone have any ideas? Here is a simple mockup:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view
xmlns:xp="http://www.ibm.com/xsp/core">
<xp:this.data>
<xp:dominoDocument
var="MainForm"
formName="MainForm" />
</xp:this.data>
<xp:checkBox
text="CheckBox"
id="CheckBox"
value="#{MainForm.CheckBox}"
disabled="true"
checkedValue="Y"
uncheckedValue="N">
</xp:checkBox>
<xp:br></xp:br>
<xp:button
id="setBc"
value="Set CheckBox">
<xp:eventHandler
event="onclick"
submit="true"
refreshMode="partial"
refreshId="CheckBox">
<xp:this.action><![CDATA[#{javascript:getComponent("CheckBox").setValue("Y");}]]></xp:this.action>
</xp:eventHandler>
</xp:button>
<xp:button
value="Save"
id="button5">
<xp:eventHandler
event="onclick"
submit="true"
refreshMode="complete">
<xp:this.action><![CDATA[#{javascript:MainForm.save();}]]></xp:this.action>
</xp:eventHandler>
</xp:button>
</xp:view>
Disabled controls are not included in page submissions.
You can combine your disabled check box with a xp:inputHidden control which is a hidden input field that is included in page submissions.
This could be a specific problem to Domino 8.5.3 (if that is what you are using).
We have noticed that since we upgraded to 8.5.3 we get a problem (on normal classic domino pages) where fields tagged as "disabled" don't get saved down to the doc.
We have had to build around this by not using a "proper" field that is disabled for values that has to later be saved.
Another workaround was to remove the disabled setting before posting in the post script.
We are fairly sure this all started to happened with the release of 8.5.3

Resources