Client side javascript does not work - xpages

In my application I have a button:
<xp:button value="Say Hello" id="btnHello">
<xp:eventHandler event="onclick" submit="false">
<xp:this.script>
<![CDATA[alert('Hello World!');]]>
</xp:this.script>
</xp:eventHandler>
</xp:button>
It generated this code:
<button class="xspButtonCommand" type="button" name="view:_id1:_id2:_id9:btnHello" id="view:_id1:_id2:_id9:btnHello">Say Hello</button>
<script type="text/javascript">
function view__id1__id2__id9__id28_clientSide_onclick(thisEvent) {
alert('bbbbbbb');
}
XSP.addOnLoad(function() {
XSP.attachEvent("view:_id1:_id2:_id9:_id28", "view:_id1:_id2:_id9:btnExport", "onclick", view__id1__id2__id9__id28_clientSide_onclick, false, 2);
});
</script>
When I click on the btnHello button, nothing happens. Does anyone know where the problem could be?

The problem was with third-party js library. I pasted it into a standard Notes javascript library and used it in xPage as a script resource. But Notes compiler or whatever it is could not resolve this library and therefore no script worked at all. Funny thing is that this library works fine in the normal web environment. Not in Notes environment.
So, problem solved. A third-party library is out and this particular script works all right, now. I guess IBM Notes with xPages is a real old school thing.

Related

SSJS Codes behind the button runs after page is refreshed

I have SSJS code behind a button. When i click the button that code creates a document in another database.
When i click the button It Works fine but I look at the Domino Admin COnsole I realize that The code behind to button Works twice.. I think When the page is refreshed It Works again? How can i prevent it?
What is it thet I miss?
<xp:button value="Label" id="button1">
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete">
<xp:this.action><![CDATA[#{javascript:print("Before createNewDoc()");
createNewDoc();
print("After createNewDoc()");
}]]></xp:this.action>
</xp:eventHandler></xp:button>
Add print statements to the beforePageLoad, afterPageLoad etc events to confirm where it is running. Also, it's worth using XPages OpenLog Logger or some other logging framework that can output a full stack trace. That might identify whether the code is running twice in the refresh, and where from.
There is no reason the code should be running twice from the button. I'm assuming this is an SSJS function in a Script Library, maybe something else is triggering that.

Trying to delete the selected item in the XPages repeat control, but does not work

I am trying to delete the selected item in the Xpages repeat control, but it does not work. Please help?
Here is my code in the repeat control section
<xp:repeat id="repeat1" rows="30" var="eachQuestion" value="#{questions}"
indexVar="rowIndex">
<tr>
<td>...</td>
<td> <xp:link styleClass="btn btn-danger" id="deleteLink">
<xp:eventHandler event="onClick"
action="#{javascript:eachQuestion.getDocument().remove(true);}"
submit="true"
refreshMode="partial"
refreshId="listContainer" />
<i class="fa fa-lg fa-trash-o" />
</xp:link> </td>
</tr>
</xp:repeat>
Here is what I can see in the client page, generated html and JS code:
XSP.addOnLoad(function() {
XSP.attachPartial("view:_id1:repeat1:0:_id44","view:_id1:repeat1:0:deleteLink", null, "onClick", function(){}, 2, "view:_id1:listContainer");
When I click the delete link icon, nothing happened.
I realized function(){} nothing in there.
Is there anything wrong or I have to implement the method in the Java code to handle this deletion?
Thanks,
You just have to change "onClick" to "onclick" in your code and it will work.
Case sensitivity does matter in Xpages. So, your code to delete a document is right but the event "onClick" doesn't gets executed at all.
You don't say what "questions" is. I assume it's a view. The code looks right to me. You certainly do NOT need Java to delete a document from a rpw in a repeat control.
I would ignore the client side stuff. That's server generated. It's supposed to be empty I think. The server knows what to do.
First check the database ACL. Make sure the user has delete access. I'd also add a Display Errors control on the page. If it's not deleting due to a validation issue it should show there. Then I'd go to OpenNTF and get the XPages Log Reader control. It's a small xpages database that let's you see errors more easily.
I'd start with those ideas.
By the way that's not a good way to do a table in a repeat control. It should be producing invalid HTML. You should use Facets. That is NOT your problem though.

xpages application layout: how to make logo clickable?

Is there a way to get the logo clickable when using the application layout? Most web sites go back to the home page when clicking the logo at the top, and my users are asking for this. Couldn't figure out how to it... I'm pretty sure it has to do with the submittedValue, but how do you set it for the logo? Or it may be something totally different, not sure.
I found this: onClick Event Banner in Application Layout but I am not sure I want to add some client side JavaScript to all pages. There must be a better way.
Add a class productLogoClass="applicationLogo" to your logo like shown here.
Add a client side onclick event for this class which executes a partial refresh on an empty panel. This panel has a rendered property which always returns true but executes additional code if partial refresh was executed by client side onclick event.
<xe:applicationLayout
...
<xe:this.configuration>
<xe:oneuiApplication
productLogo="/logo.png"
productLogoClass="applicationLogo">
...
</xe:oneuiApplication>
</xe:this.configuration>
</xe:applicationLayout>
<xp:eventHandler
event="onClientLoad"
submit="false">
<xp:this.script><![CDATA[var applicationLogo = dojo.query('.applicationLogo')[0];
applicationLogo.onclick = function() {
XSP.partialRefreshGet("#{id:onClickApplicationLogo}",
{params: {'onClickApplicationLogo': true}})
}
]]></xp:this.script>
</xp:eventHandler>
<xp:panel id="onClickApplicationLogo">
<xp:this.rendered><![CDATA[#{javascript:
if (param.onClickApplicationLogo) {
print("onClick application icon");
context.redirectToPage("Home.xsp");
}
return true;}]]>
</xp:this.rendered>
</xp:panel>
In this example it writes "onClick application icon" to server console and redirects to "Home.xsp".

Working dialog code from one application does not work in another application

I've working code to open dialog box using SSJS code to show error or warning to user when user click submit button. This button appears at the top of the xpage.
Applied the modified version of the above code in another application but instead of top of xpage, put button in section. If comboBox1 has initial value it is suppose to popup the dialog box. But it is not working. The client side validation is off in working as well as non working application. Why this code is not working? Where to check?
Here is code for a section button:
<xp:button value="Must click to Assign Quote Number" id="button6" style="width:207.0px">
<xp:eventHandler event="onclick" submit="true" refreshMode="complete" immediate="false" save="true">
<xp:this.action>
<xp:executeScript>
<xp:this.script><![CDATA[#{javascript:var comboBox1:com.ibm.xsp.component.xp.XspSelectOneMenu = getComponent("comboBox1");
var a=comboBox1.getValue();
if ( a=="Assign the PE Staff"){
var d=getComponent('dialog2');
d.show();
}
}]]></xp:this.script>
</xp:executeScript>
</xp:this.action></xp:eventHandler>
</xp:button>
Things to check off the top of my head:
Check that Ext Lib is loaded properly in new app (check application properties)
Check that namespace for ExtLib is on the new page (drag any Ext Lib control on the page, and this will be added for you)
Check that resources from the first page are on the new one (script libraries, etc)
Try print("var a=" + a) to see if comboBox1 is giving you a value (check your server log.nsf)
If you give more info on what is happening when it doesn't work then we might be able to suggest more things to check.

XPages SSJS is not started throw Reverse-Proxy

may be someone helps :)
I don't know much about Apache-Reverse-Server
I have a simple X-Page, see the code bellow.
If I open the xpage via
http: //domain1.de/e.nsf/test.xsp
and press the button, in log.nsf i see my print-out "Button is clicked"
If I open the xpage via
https: //example1.someproxy/rp/sproxy/http$domain1.de$80$/e.nsf/test.xsp
and press the button, in log.nsf i DON'T see my print-out "Button is clicked"
The Proxy-Server is installed and configured not by me.
<?xml version="1.0" encoding="UTF-8"?><xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:link escape="true" id="link1" disableTheme="true">
<xp:image id="image1" url="/btn.jpg"></xp:image>
<xp:eventHandler event="onclick" submit="true" refreshMode="complete" >
<xp:this.action><![CDATA[#{javascript:print("Button is clicked");}]]></xp:this.action>
</xp:eventHandler>
</xp:link>
What could be the problem, that the SSJS-code is not started via Reverse-Proxy at all?
Is reverse proxy the problem? Or is the problem that your code is not triggering?
I can't tell from your user id how experienced with XPages you are, but bear in mind a number of steps are performed on the server before it gets to your print statement. One of the key ones is conversion and validation. So if anything on your XPage throws a validation error, it won't run SSJS code.
Do you have a Display Errors control on the XPage and, more importantly, inside the refresh area? If not, add one. We've all spent hours in our early XPages life because validation or data conversion has failed and we didn't add anything to let us know. Once you get more confident, a PhaseListener is another useful tool for checking any or all lifecycle phases are running.

Resources