I have the following code logging out the user from app and "send" him back to the session based authentication page ( Thanks Paul Withers ):
clearing_function(sessionScope);
var appUrl = facesContext.getExternalContext().getRequest().getContextPath();
var url = appUrl + "?logout&redirectto=" + appUrl;
facesContext.getExternalContext().redirect(url);
Is there any chance to have like a #prompt formula with yes/no and just in case if user selects yes the above code ( from ssjs ) to be executed? Or I must write the confirmation message in csjs. But, then, how can I transform the above code in csjs?
You can use the Dialog component from extension library to build a confirmation box with two buttons where the positive button runs your logout code
<xe:dialog id="dialog1">
<xp:panel>
<xp:button value="OK" id="button1">
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete">
<xp:this.action><![CDATA[#{javascript:clearing_function(sessionScope);
var appUrl = facesContext.getExternalContext().getRequest().getContextPath();
var url = appUrl + "?logout&redirectto=" + appUrl;
facesContext.getExternalContext().redirect(url);}]]></xp:this.action>
</xp:eventHandler></xp:button>
<xp:button value="Cancel" id="button2">
<xp:eventHandler event="onclick" submit="true"
refreshMode="partial" refreshId="dialog1">
<xp:this.action><![CDATA[#{javascript:getComponent("dialog1").hide();}]]> </xp:this.action>
</xp:eventHandler></xp:button></xp:panel>
</xe:dialog>
To hide the default x button just override the relevant css classes:
for oneui themes it's the "lotusBtnImg" class
for webstandard it's the ".dijitDialogCloseIcon" class
Related
I got the problem, that my dialog boxes are stacking each time I click the button that opens the dialog. So if I've clicked three times I get this:
I couldn't find out how to prevent this. No matter which button I click (OK does a partial refresh | Abbrechen (Cancel) does a full update) I get another box each time I click the button.
Code of the button that opens the dialog:
<xp:button value="Plan meeting" id="buttonPlanMeeting">
<xp:eventHandler event="onclick" submit="true" refreshMode="complete">
<xp:this.action><![CDATA[#{javascript:try {
var c = getComponent("dPlanMeeting")
c.show();
} catch(e) {
dBar.error(location + e);
}}]]></xp:this.action>
</xp:eventHandler>
</xp:button>
Code for the complete dialog box:
<xe:dialog id="dPlanMeeting" title="Plan meeting" keepComponents="true">
<xp:panel>
<xp:text escape="true" id="MBPlanMeeting">
<xp:this.value><![CDATA[#{javascript:specialstrings.getString("ccEsgDocWflContentEditInfos.dPlanMeeting.MBPlanMeeting")}]]></xp:this.value>
</xp:text>
</xp:panel>
<xe:dialogButtonBar>
<xp:button value="Ok" id="buttonDelegateOk" styleClass="lotusFormButton">
<xp:eventHandler event="onclick" submit="true" refreshMode="complete">
<xp:this.action><![CDATA[#{javascript:try {
//will create a meeting for every day the visit is registered
var wfDoc:NotesDocument = docApplication.getDocument(true);
specialMeetingCreate(wfDoc);
var c = getComponent("dPlanMeeting");
c.hide();
var c = getComponent("dMeetingCreated")
c.show();
} catch (e) {
dBar.error(location + e);
}
}]]></xp:this.action>
</xp:eventHandler>
</xp:button>
<xp:button value="Cancel" id="buttonDelegateCancel" styleClass="lotusFormButton">
<xp:eventHandler event="onclick" submit="true" refreshMode="complete">
<xp:this.action><![CDATA[#{javascript:try {
var c = getComponent("dPlanMeeting");
c.hide();
} catch (e) {
dBar.error(location + e);
}
}]]></xp:this.action>
</xp:eventHandler></xp:button>
</xe:dialogButtonBar>
</xe:dialog>
Does this have anything to do with keepComponents? I've tried true and false, but the effect stays the same.
Any idea?
Ok it seems that the solution was just to set "keepComponents = false". I've tried that before, but now it'S working. I get the dialog box only once no matter how often I click the button
I have a simple form with an onchange event on a field of type inputText.
Onchange event start when I click another object. Example the save button.
The code runs but the onchange click on the Save button is lost.
I enclose the sample code of a page that reproduces the problem.
Suggestions?
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:div style="padding:20px;"></xp:div>
<xp:button value="Save" id="button1" style="margin:20px;">
<xp:eventHandler event="onclick" submit="true" refreshMode="complete">
<xp:this.action><![CDATA[#{javascript:print('click');}]]></xp:this.action>
<xp:this.script><![CDATA[alert('click');]]></xp:this.script>
</xp:eventHandler>
</xp:button>
<xp:radioGroup id="radioGroup1" style="margin:20px;">
<xp:selectItem itemLabel="val1"></xp:selectItem>
<xp:selectItem itemLabel="val2"></xp:selectItem>
<xp:selectItem itemLabel="val3"></xp:selectItem>
<xp:eventHandler event="onchange" submit="true" refreshMode="complete">
<xp:this.action><![CDATA[#{javascript:print('onchange - radiobutton');}]]></xp:this.action>
</xp:eventHandler>
</xp:radioGroup>
<xp:inputText id="inputText1" style="margin:20px;">
<xp:eventHandler event="onchange" submit="true" refreshMode="complete">
<xp:this.action><![CDATA[#{javascript:print('onchange - start');
var millis = 10000;
var date = new Date();
var curDate = null;
do { curDate = new Date(); }
while(curDate-date < millis);
print('onchange - finish');}]]></xp:this.action>
</xp:eventHandler>
</xp:inputText>
</xp:view>
You can do it by oninput event instead of onchange. Just change the event attribute in the eventHandler. However,
It's not supported before IE9,
Every keystroke will trigger the event which could be bad for user-experience
In case of a partial refresh, when the refresh is over, the focus will be shifted to another component if it's not the first item in the form. Again, bad for UX.
You may also fire a CSJS code on onkeyup event to focus another component on the page. Therefore it will refresh the page. You may do this with setTimeout() function therefore, if the user does not press any keys for a moment, it will fire the refresh.
Thanks for reply but I think that these solutions are not good for UX.
I think that only possible solutions are:
1 disable server onchange event and add refresh button
2 when possible use onchange client js event
Others suggestion?
I would like to put a combox on an xpages so the user can choose to witch page he wants to go.
for example if he chooses google he would go to google.com etc
I tried :
<xp:comboBox id="comboBox1">
<xp:selectItem itemLabel="Google"
itemValue="Google">
</xp:selectItem>
<xp:selectItem itemLabel="Yahoo" itemValue="Yahoo"></xp:selectItem>
<xp:eventHandler event="onchange"
submit="true" refreshMode="complete">
<xp:this.action><![CDATA[#{javascript:var item = getComponent("comboBox1").getValue();
if (item == 'Google') {
window.location.href = 'http://google.com';
};
}]]>
</xp:this.action>
</xp:eventHandler>
</xp:comboBox>
You are mixing server-side Javascript with client-side Javascript.
Do this instead:
<xp:eventHandler event="onchange" submit="true" refreshMode="complete">
<xp:this.action><![CDATA[#{javascript:
var item = getComponent("comboBox1").getValue();
if (item == 'Google') {
facesContext.getExternalContext().redirect("http://google.com");
};
}]]></xp:this.action>
</xp:eventHandler>
Try:
facesContext.getExternalContext().redirect("http://example.com")
This and more things are available on xpagescheatsheet.com. Note in addition to the printed cheatsheet there's a link to an online "URL Cheatsheet" that has a bunch or URL Examples.
Bind your combo to a document datasource field or to a scoped variable ?
After I click the button it goes to the next tab, however, if I click the previous tab to edit something then click the button again, nothing happens. Any idea why? Here is the button code:
<xp:button value="Next" id="buttonNext1">
<xp:eventHandler event="onclick"
submit="true" refreshMode="partial" refreshId="panelMain">
<xp:this.action><![CDATA[#{javascript:
viewScope.currentTab = "tpCompanyInformation";
}]]></xp:this.action>
</xp:eventHandler>
</xp:button>
I see you bound the SelectedTab or even the defaultTab value of to your viewScope.currentTab and set the viewScope variable in every button with your viewScope.currentTab = "id".
I would recomend setting the tab direct in the component by using getComponent('tabbedPanel').setSelectedTab('tabid').
As a little goody: maby this Code helps you it will Create two buttons ('back' & 'next'), no mather how much tabs you will add to your panel the buttons should always work as forward and backward buttons.
ButtonBack:
<xp:button id="button1" value="back">
<xp:eventHandler event="onclick" submit="true"
refreshMode="partial" refreshId="tabbedPanel1">
<xp:this.action><![CDATA[#{javascript:var panel:com.ibm.xsp.component.xp.XspTabbedPanel = getComponent('tabbedPanel1');
var list:Array = panel.getChildren().toArray();
var currentTab = panel.getSelectedTab();
for(var i = 0; i < list.length;i++){
if(currentTab.equals(list[i].id)){
if(i > 0)
panel.setSelectedTab(list[i-1].id);
else
panel.setSelectedTab(list[list.length - 1].id);
}
}
}]]></xp:this.action>
</xp:eventHandler>
</xp:button>
Button Next:
<xp:button value="Next" id="buttonNext1">
<xp:eventHandler event="onclick" submit="true"
refreshMode="partial" refreshId="tabbedPanel1">
<xp:this.action><![CDATA[#{javascript://
var panel:com.ibm.xsp.component.xp.XspTabbedPanel = getComponent('tabbedPanel1');
var i:java.util.Iterator = panel.getChildren().iterator();
var currentTab = panel.getSelectedTab();
while(i.hasNext()){
if(currentTab.equals(i.next().id)){
if(i.hasNext())
panel.setSelectedTab(i.next().id);
else
panel.setSelectedTab(panel.getChildren().iterator().next().id);
}
}
}]]></xp:this.action>
</xp:eventHandler>
</xp:button>
I am working on application and I got stuck when I wanted to open a link on new tab or window.
I am using Lotus Notes Designer Release 8.5.2FP1.
I have attached my piece of code.
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete">
<xp:this.action><![CDATA[#{javascript:try{
var doc = database.getProfileDocument("frmConfiguration","");
var url = doc.getItemValueString("HeaderLink1URL");
view.postScript("var tempwindow =window.open('" +url+"','_blank');tempwindow.focus();");
}catch(e){
}}]]></xp:this.action>
Based on your updated code in comment you can simply add target="_blank" and instead of using the onClick event use the value attribute which would point to the URL to be opened. So your code would be something like this:
<xp:link escape="false" id="link1" target="_blank">
<xp:this.text>some code</xp:this.text>
<xp:this.value><![CDATA[#{javascript:var doc = database.getProfileDocument("frmConfiguration","");
var href = doc.getItemValueString("HeaderLink1URL");
return href;}]]></xp:this.value>
</xp:link>
The simpliest way to do this would be something like:
<xp:text escape="false" id="newTab"><xp:this.value><![CDATA[#{javascript:return "Google";}]]></xp:this.value></xp:text>
This will open google in a addtional tab.
Update:
If you want to use a xp:link you could try:
<xp:link escape="false" id="newTab" text="test">
<xp:this.onclick><![CDATA[var ret = window.open("http://www.google.com",'_blank');
]]></xp:this.onclick>
</xp:link>
If you want to open the link in a seperate window or tab i recomend dont use the aktion use the onclick client side event in the option tab.
Here is some sample code of opening a URL both client side and server side.
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:button value="Client Side Open Button." id="ClientSideButton">
<xp:eventHandler event="onclick" submit="false">
<xp:this.script><![CDATA[var href = "http://www.ibm.com";
var tempwindow = window.open(href,'_blank');
tempwindow.focus();
]]></xp:this.script>
</xp:eventHandler>
</xp:button>
<xp:br></xp:br>
<xp:br></xp:br>
<xp:button id="serverSideButton" value="Server Side Open Button ">
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete">
<xp:this.action><![CDATA[#{javascript:var href = "http://www.ibm.com";
view.postScript("var tempwindow = window.open('" + href + "','_blank'); tempwindow.focus();");
}]]></xp:this.action>
</xp:eventHandler>
</xp:button>
</xp:view>
If this code does not work as expected, two things to check.
Check that the url variable is being set correctly.
Make sure you are on the latest release. window.open() didn't work as expected until 8.5.1FP2.