How to make headingText of navBar clickable? - xpages

I want the headingText be clickable. Well I can make it as a navbarBeforeLinks node but don't believe there is no way to make headingText clickable. E.g. I want the app redirect to Homepage by clicking on it.
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlns:xe="http://www.ibm.com/xsp/coreex">
<xe:navbar id="navbar1" headingText="My application name"></xe:navbar>
</xp:view>

Use client side JavaScript to add an onclick event and style "pointer" to navBar's headingText:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view
xmlns:xp="http://www.ibm.com/xsp/core"
xmlns:xe="http://www.ibm.com/xsp/coreex">
<xe:navbar
id="navbar1"
headingText="My application name">
</xe:navbar>
<xp:eventHandler
event="onClientLoad"
submit="false">
<xp:this.script><![CDATA[
function goHome() {
window.location.href = "... your home URL ..."
}
dojo.query(".navbar-brand").forEach(function(node, index, arr){
node.style.cursor = "pointer";
node.addEventListener("click", goHome);
});
]]></xp:this.script>
</xp:eventHandler>
</xp:view>
You can find headingText's node element in DOM with the help of class "navbar-brand".

Related

Passing xp:link parameters through custom control

I have a custom control with the following code:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:panel tagName="li">
<xp:this.styleClass><![CDATA[${javascript:#If(view.getPageName().equals(compositeData.linkPage), "active", "")}]]></xp:this.styleClass>
<xp:link escape="true"
text="${javascript:compositeData.LinkLabel}"
value="${javascript:compositeData.linkPage}"
parameters="${javascript:compositeData.parameters}">
</xp:link>
</xp:panel>
</xp:view>
This is the property definition tree of the control:
I try to use the custom control like this:
<xc:sideMenuPageLink LinkLabel="Registration"
linkPage="/Registration.xsp">
<xc:this.parameters>
<xc:parameters name="id" value="new"></xc:parameters>
</xc:this.parameters>
</xc:sideMenuPageLink>
When I build my application, I get the following error:
The method addParameter(Parameter) in the type UIOutputLink is not applicable for the arguments (Object)
on SideMenuPageLink.java (my custom control)
How can I pass the parameters for the link from my Xpage to the Custom Control?
It seems that parameters have to passed one by one, not as a single object.
You may want to try the following code, which works for me:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:panel tagName="li">
<xp:this.styleClass><! [CDATA[${javascript:#If(view.getPageName().equals(compositeData.linkPage), "active", "")}]]></xp:this.styleClass>
<xp:link escape="true"
text="${compositeData.LinkLabel}"
value="${compositeData.linkPage}">
<xp:this.parameters>
<xp:parameter
name="${compositeData.parameters.name}"
value="${compositeData.parameters.value}">
</xp:parameter>
</xp:this.parameters>
</xp:link>
</xp:panel>
</xp:view>
Edit 2019-01-30: Corrected typos

XSP JSF FacesContext addMessage does not always work

I have a JSF page where the user is entering several information. When the user submits the data it is first validated and if the submission is succesful the user should get a FacesMessage also.
I have a custom control for a menubar which I am using in every single page:
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlns:xc="http://www.ibm.com/xsp/custom">
<xp:panel>
<xp:this.facets>
<!-- Some Logos and stuff -->
<xp:panel xp:key="contentFacet">
<xp:callback facetName="contentContainer"></xp:callback>
</xp:panel>
</xp:this.facets>
</xp:panel>
</xp:view>
The menu is then used the following way:
<xc:cc_layout_main><xp:this.facets>
<xp:panel xp:key="contentContainer">
<xc:cc_content_form></xc:cc_content_form></xp:panel>
</xp:this.facets></xc:cc_layout_main>
The cc_content_form uses this control:
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:messages id="messages1" styleClass="test" layout="table"
errorClass="alert-warning" fatalClass="alert-danger"
infoClass="alert-info" warnClass="alert-warning" showDetail="true"
showSummary="true" disableTheme="false" globalOnly="false">
</xp:messages>
<xp:scriptBlock id="scriptBlock1">
<xp:this.value><![CDATA[
// Validierungs Nachrichten entfernen
var delayMs = 750;
$('body')
.on('click', function(event){
x$('#{id:messages1}').delay(delayMs).fadeOut(500);
})
.on('keyup', function(event){
x$('#{id:messages1}').delay(delayMs).fadeOut(500);
})
]]></xp:this.value>
</xp:scriptBlock>
</xp:view>
In the submit function I am using this in the validation function:
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "error", "some error"));
This call is wrapped in a helper class method with a singletone pattern so it can be used from all pages. For the validation messages this works just fine but further down in the valdiation method before I return the actionResult "xsp-success" it does not work. No message shows up, I do not get any Exception.
Can anybody help on this?
Turns out I messed up the NavigationRules ... Its working just fine

compute partial refresh ID?

I would like to compute the ID of a partial refresh target ID. Is this possible?
I am working an a reusable component (custom control) and would like to specify the target ID via the Property Definition instead of hard-coding it.
You mean something like this?
Code for CustomControl
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:button value="Label" id="button1">
<xp:eventHandler event="onclick" submit="true"
refreshMode="partial" refreshId="#{compositeData.refreshId}">
</xp:eventHandler>
</xp:button>
</xp:view>
Code for XPage
<?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:label
value="#{javascript:java.lang.System.currentTimeMillis()}"
id="label1" />
<xc:CC refreshId="#{label1}" />
</xp:view>
The custom property of the CC is a String named refreshId

duplicate items in Document after saving in a bean

I experience strange but reproduceable behaviour with an XPage which saves its values through a java bean. After copyAllItems to an document there are two richtext items in the document. First is empty, second is filled as expected.
This is my Xpage:
<?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="docDataSource" formName="test"></xp:dominoDocument>
</xp:this.data>
<xp:div id="test">
<xp:fileUpload id="fileUpload1" value="#{docDataSource.test}"></xp:fileUpload>
</xp:div>
<xp:button value="Label" id="button1">
<xp:eventHandler event="onclick" submit="true"
refreshMode="partial" refreshId="test">
<xp:this.action><![CDATA[#{javascript:registration.testCopyAllItems(docDataSource);}]]></xp:this.action>
</xp:eventHandler>
</xp:button>
This is my java bean method:
public void testCopyAllItems(DominoDocument docDataSource) throws NotesException{
Document docUser = database.createDocument(); // <- get any database
docDataSource.getDocument(true).copyAllItems(docUser, true);
docUser.save();
}
This is the result in the document:
Does anyone have a hint on what could cause the trouble?
This seems to be a "normal" behaviour and I have seen it a lot working with RichtText fields. It shouldn't matter. Notes can deal with a RichText field constisting of more than one item.
As a workaround,
delete the RichText field after copyAllItems() with removeItem() and
copy it with copyItem() separately.
This should result in one item only.

xpages - prevent SSJS on page load in CSJS

I have some SSJS within CSJS onclick event of a button. Is there any way to prevent this SSJS from executing during page load?
Thanks
This can be done by checking facesContext.getRenderResponse(). If it is true, the page is reloaded, otherwise it is false. The flag is not set correctly but gives you an easy way to check if the page is loaded or not.
Here is an example XPage:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:button value="Reload CSJS" id="buttonReloadCSJS">
<xp:eventHandler event="onclick" submit="true" refreshMode="complete">
<xp:this.script>
<![CDATA[#{javascript:
facesContext.getRenderResponse()?"alert('NotOnLoad');":"alert('OnLoad')";
}]]>
</xp:this.script>
</xp:eventHandler>
</xp:button>
</xp:view>
If you open the XPage and click the button, the page will be reloaded and you will have another CSJS code.
EDIT:
Here is another way to calculate code only if the button was partial refreshed:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:div id="refreshMe">
<xp:button value="Reload CSJS" id="buttonReloadCSJS">
<xp:eventHandler event="onclick" submit="true" refreshMode="partial" refreshId="refreshMe">
<xp:this.script>
<![CDATA[#{javascript:
var ajax = new com.ibm.xsp.ajax.AjaxUtil();
if( ajax.isAjaxPartialRefresh(facesContext) == true){
return "alert('Refreshed')";
}
}]]>
</xp:this.script>
</xp:eventHandler>
</xp:button>
</xp:div>
</xp:view>

Resources