Monday, November 21, 2016

Setting XPages ACL Dynamically

The ACL on the XPage can be set from the XPage's - All Poperties - ACL property manually, by defining each ACLEntry directly on the XPage, but there's no way ( as far a s I know ) to bind this to a java bean or to have this computed on the fly.

A workaround is to add this to the XPage's view root.
This is done by calling a function in java from the beforePageLoad event of the XPage you want to restrict...

 public void setACLOnXPage() {
  ACLEntry aclEntry = null;
  ArrayList arList = null;
  ACL aclObject = new ACL();
  try {
   
   arList = new ArrayList();
   
   // USER
   aclEntry = new ACLEntry();
   aclEntry.setFullName("My UserName"); // FirstName SurName
   aclEntry.setName("My User Cannonical Name"); // CN=FirstName SurName/O=Organization
   aclEntry.setType("USER");
   aclEntry.setRight("EDITOR");
   arList.add(aclEntry);
   
   // DEFAULT
   aclEntry = new ACLEntry();
   aclEntry.setName("DEFAULT");
   aclEntry.setFullName("DEFAULT");
   aclEntry.setType("DEFAULT");
   aclEntry.setRight("NOACCESS");
   arList.add(aclEntry);

   // ANONYMOUS
   aclEntry = new ACLEntry();
   aclEntry.setName("ANONYMOUS");
   aclEntry.setFullName("ANONYMOUS");
   aclEntry.setType("ANONYMOUS");
   aclEntry.setRight("NOACCESS");
   arList.add(aclEntry);

   // ROLES
   aclEntry = new ACLEntry();
   aclEntry.setName("[ADMINISTRATION]");
   aclEntry.setFullName("ADMINISTRATION");
   aclEntry.setType("ROLE");
   aclEntry.setRight("EDITOR");
   arList.add(aclEntry);
   
   // GROUP
   aclEntry = new ACLEntry();
   aclEntry.setName("MY GROUP");
   aclEntry.setFullName("MY GROUP");
   aclEntry.setType("GROUP");
   aclEntry.setRight("EDITOR");
   arList.add(aclEntry);
   
   for (ACLEntry entry : arList) {
    aclObject.addEntry(entry);
   }
  
   aclObject.setTransient(false);
   aclObject.saveState(FacesContext.getCurrentInstance());
   
   UIViewRootEx2 view = (com.ibm.xsp.component.UIViewRootEx2) FacesContext.getCurrentInstance().getViewRoot();
   view.setAcl(aclObject);
   
   
  }catch(Exception ex) {
   System.out.print(ex);
  }
 }
Hope this helps! ;-)

Monday, March 30, 2015

Xpages : TabContainer : Dynamically Add Tabs in Java

When I was looking on the web for a way to add a page dynamically to a Tab Container in Xpages,
many sources were talking about CSJS (the dojo way addChild) or via SSJS createTab function of the extension library control.
I decided to use the Extension Library control, now I did want to control this via Java instead of CSJS/SSJS.
On the Ext. Lib control UIDojoTabContainer there’s a function called createTab().
When I tried to use this function it kept complaining, CreateTab is not a function.
Why? I really can't say… After some frustration and a good night sleep I came up with a different way using JSF.

On my Xpage I have defined a Tab Container with 1 page, this page holds our dynamic view panel.


    
        
    


In the custom control which holds our dynamic view panel, I have defined an onColumnClick event.


                           <![CDATA[#{javascript:var docId = viewEntry.getUniversalID();
//var noteId = viewEntry.getNoteID();
 
var number = viewEntry.getDocument().getItemValueString("jeNumber");
var formName = viewEntry.getDocument().getItemValueString("Form");
var baseURL = com.jacobs.JPI.Utils.GetXpageURL(formName + ".xsp");
var url = baseURL+ '?documentId='+docId+'&action=openDocument';
 
var tabContainer:com.ibm.xsp.extlib.component.dojo.layout.UIDojoTabContainer = getComponent("TabContainer");
 
if(Main.Navigation.currentPage.Controls.createTab(tabContainer, number, docId, url)){
       print("New Tab Created : " + number);
}else{
       print("Error creating new Tab");
}}]]>
                     
First we get the universal ID of the document, this will be used as the tab’s unique key,
second we get some text to display as a title on this tab
and then we compute the new URL of the document you want to open in a new tab.
We grab a handle on our TabContainer control and call a function in one of my managed java beans (Main).

com.mycompany.PageObject.Controls.createTab

com.mycompany.PageObject.Controls.createTab

import com.ibm.xsp.complex.Attr;
import com.ibm.xsp.component.UIPanelEx;
import com.ibm.xsp.extlib.component.dojo.layout.UIDojoTabContainer;
import com.ibm.xsp.extlib.component.dojo.layout.UIDojoTabPane;
              
public boolean createTab(UIDojoTabContainer tabContainer, String title, String unid, String url) {

                     try {
                           // create a new Tab
                           UIDojoTabPane newTab = new UIDojoTabPane();
                           newTab.setTitle(title);
                           newTab.setTabUniqueKey(unid);
                           newTab.setClosable(true);
                           // newTab.setHref(url); => does not work properly, un clickable content
                           
                           // create new Panel
                           UIPanelEx newPanel = new UIPanelEx();
                           newPanel.setId("IFrame" + unid);
                           newPanel.setStyle("height:700px;width:100%; overflow-y: auto");
                           // make an iFrame of this panel with our URL as src
                           newPanel.setTagName("iframe");
                           Attr property = new Attr();
                           property.setName("src");
                           property.setValue(url);
                           newPanel.addAttr(property);
                           
                           // add Panel to our new Tab
                           newTab.getChildren().add(newPanel);
                           
                           // add the new tab to our tab container
                           tabContainer.getChildren().add(newTab);
                     
                           return true;
                     } catch (Exception ex) {
                           Utils.WriteToConsole("Unable to add a new Tab Page to the Tab Container", ex);
                           return false;
                     }

}
First we create a new tab pane, we set some properties (title, unique key, closable tab).
You would think that using the href property, you can easily set the url you want the page to display.
Although this actually displays our xpage, the content becomes unusable (un-clickable).
Another way to display the xpage is by using an iframe…
To create a new iframe, we need to create a new panel UIPanelEx.
This panel needs some styling to set (mainly the height & width).
To transform this to an iframe you’ll need to specify the tagName ‘iframe’.
Of course we’ll need to provide our iframe with an URL, this is done by adding a special attribute ‘src’.
The attribute consists of a name ‘src’ and a value, the URL.

We then add the panel to our new tab page and the new tab page to our container,
by using the function component.getChildren().add(newcomponent).

Looking back this is in fact a very simple solution and easy to debug in Domino Designer.
For this point you can start building a library that controls the way you work with tabs in Java.
For instance, block the tab container of adding already added tabs…

  // check if the tab isn't already created if so just select it
   for (Object obj : tabContainer.getChildren()) {
    if (obj.getClass().getName().equalsIgnoreCase("com.ibm.xsp.extlib.component.dojo.layout.UIDojoTabPane")) {
     newTab = (UIDojoTabPane) obj;
     if (newTab != null) {
      if (newTab.getTabUniqueKey().equalsIgnoreCase(unid)) {
          // tab already created, just select it and exit
          tabContainer.setSelectedTab(unid);
          return true;
      }
     }
    }
   }

Tuesday, March 17, 2015

Xpages : Connect RestService to a different database/server




Recently I found that it was not so well known that you actually can specify a server in the databaseName property of the Rest Service in Xpages.

So let's share this with the world ;-)

In the databaseName property of your RestService:

var databasePathName = "MyDatabase.nsf";
var serverName = "MyServer/MyOrg/MyDomain";
return serverName + "!!" + databasePathName;



 
  
   
   
  
 

Wednesday, July 30, 2014

Xpages : Dynamically Create Navigator TreeNodes

In the AfterPageLoad event of my custom navigator control add this:


try{

var newContainer:com.ibm.xsp.extlib.tree.impl.BasicContainerTreeNode = new com.ibm.xsp.extlib.tree.impl.BasicContainerTreeNode();
newContainer.setLabel("Dynamic Container Node");
var newNode:com.ibm.xsp.extlib.tree.impl.BasicLeafTreeNode = new com.ibm.xsp.extlib.tree.impl.BasicLeafTreeNode();
newNode.setLabel("Dynamic Basic Node");
newContainer.addChild(newNode);
var Nav = getComponent("nav1");
Nav.addNode(newContainer);

}catch(e){
print(e.toString);
}

'nav1' Navigator control















Improved version, use a Managed Bean (does not need to be managed can be just a class)







Java class:


package com.my.javaclass;

import java.io.Serializable;
import com.ibm.xsp.extlib.tree.ITreeNode;
import com.ibm.xsp.extlib.tree.impl.BasicLeafTreeNode;
import com.ibm.xsp.extlib.tree.impl.BasicContainerTreeNode;
import com.ibm.xsp.extlib.tree.impl.BasicNodeList;

public class javaclass extends BasicNodeList implements Serializable {


private static final long serialVersionUID = -7600042596799645230L;

        public javaclass() {
                 
                   BasicContainerTreeNode newContainer = new BasicContainerTreeNode();
                   newContainer.setLabel("Dynamic Container Node");
                   BasicLeafTreeNode newNode = new BasicLeafTreeNode();
                   newNode.setLabel("Dynamic Basic Node");
                   newNode.setSubmitValue(/*some value you want to submit*/);
                   newNode.setSelected(/*some boolean function*/);
                   newContainer.addChild(newNode);
                   addChild(newContainer);

      }
}


Wednesday, November 28, 2012

What people think I do...

I received a mail from my colleague, so true...
Just had to post it :-)


Friday, September 28, 2012

Fun : Carry On & Some Nights & We Are young

Carry On :



Some Nights



We Are Young

Guild Wars II

Guild Wars II really lived up to my expectations, for me this is the best game ever created...

No fees, no typical healer/tank/DPS, new game play, dynamic events, World vs World, impressive evolving story line.
PVE & PVP & WvW just give it a try you'll love it..

Well if you like these kind of MMORPGs that is :-)

Website: https://www.guildwars2.com/en/

Check out the introduction movie below... See you in the game...


Tuesday, September 25, 2012

Jayden

Ever seen such a cutey :-)

My son Jayden (2years old)


Monday, September 17, 2012

Evolution from GSM to GPRS to 3G to LTE

Three-Minute Tech: LTE | TechHive


The evolution of ‘Long Term Evolution’

LTE is a mobile broadband standard developed by the 3GPP (3rd Generation Partnership Project), a group that has developed all GSM standards since 1999. (Though GSM and CDMA—the network Verizon and Sprint use in the United States—were at one time close competitors, GSM has emerged as the dominant worldwide mobile standard.)

Cell networks began as analog, circuit-switched systems nearly identical in function to the public switched telephone network (PSTN), which placed a finite limit on calls regardless of how many people were speaking on a line at one time.

The second-generation, GPRS, added data (at dial-up modem speed). GPRS led to EDGE, and then 3G, which treated both voice and data as bits passing simultaneously over the same network (allowing you to surf the web and talk on the phone at the same time).

GSM-evolved 3G (which brought faster speeds) started with UMTS, and then accelerated into faster and faster variants of 3G, 3G+, and “4G” networks (HSPA, HSDPA, HSUPA, HSPA+, and DC-HSPA).

Until now, the term “evolution” meant that no new standard broke or failed to work with the older ones. GSM, GPRS, UMTS, and so on all work simultaneously over the same frequency bands: They’re intercompatible, which made it easier for carriers to roll them out without losing customers on older equipment. But these networks were being held back by compatibility.

That’s where LTE comes in. The “long term” part means: “Hey, it’s time to make a big, big change that will break things for the better.”

Thursday, September 13, 2012

Chocolatey Linux' Appget for Windows

Chocolatey Brings Lightning Quick, Linux-Style Package Management to Windows

I found this nice article about an appget variant for windows.


Chocolatey puts all of your favorite Windows programs right at your fingertips. With just a few keystrokes, you can have a program up and running on your system without ever needing to open a browser, double-click on an installer, or go through any menus. To install Chocolatey, just run the following command in a Command Prompt:

@powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('http://bit.ly/psChocInstall'))" && SET PATH=%PATH%;%systemdrive%\chocolatey\bin 


Then, you can search the chocolatey database for any program using the clist command. For example, clist windirstat will let you know whether WinDirStat is in Chocolatey's database (it is), after which you can install it by typing in cinst windirstat. You may need to say "Yes" to a UAC prompt, but that's all it takes—you'll have WinDirStat up and running on your system in no time. You can even install multiple programs at once, or use Chocolatey in your favorite alternate shell like Cygwin.

-------------------------
Usage
-------------------------
chocolatey [install [packageName [-source source] [-version version] | pathToPackagesConfig]  | installmissing packageName [-source source] | update packageName [-source source] [-version version] | l
ist [packageName] [-source source] | help | version [packageName] | webpi packageName | gem packageName [-version version] |uninstall packageName]

example: chocolatey install nunit
example: chocolatey install nunit -version 2.5.7.10213
example: chocolatey install packages.config
example: chocolatey installmissing nunit
example: chocolatey update nunit -source http://somelocalfeed.com/nuget/
example: chocolatey help
example: chocolatey list (might take awhile)
example: chocolatey list nunit
example: chocolatey version
example: chocolatey version nunit
example: chocolatey uninstall

A shortcut to 'chocolatey install' is 'cinst'
cinst [packageName  [-source source] [-version version] | pathToPackagesConfig]
example: cinst 7zip
example: cinst ruby -version 1.8.7
example: cinst packages.config