onsdag 19. mars 2014

XPages and SelectItem pecularities

I am always striving towards best practices when coding. This is not to say that I always know what is the best practice (often far from it) but when it comes to XPages I prefer Java over SSJS.

This struggle makes me often use a lot of extra (evening) time trying to find out how to do something the Java way. And this occasion was no exception.

Lately I have been working on an XPage which had a combobox for selecting between last year, current year or next year. All of course Integer values. Since hard coding values is not allowed (really, it isn't!) I had to generate values by code.

And here's the code:

package no.inforte.test;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import javax.faces.model.SelectItem;

public class YearBean implements Serializable {

    private static final long serialVersionUID = 1L;

    public List<SelectItem> getYears() {
        int thisYear = Calendar.getInstance().get(Calendar.YEAR);

        List<SelectItem> selectItems = new ArrayList<SelectItem>();

        selectItems.add(new SelectItem(new Integer(thisYear - 1), new Integer(thisYear - 1).toString()));
        selectItems.add(new SelectItem(new Integer(thisYear), new Integer(thisYear).toString()));
        selectItems.add(new SelectItem(new Integer(thisYear + 1), new Integer(thisYear + 1).toString()));
        return selectItems;
    }
}

And an excerpt from my xpage showing how to access the values using Expression Language (EL):


    <xp:comboBox
        id="comboYear"
        value="#{yearBean.currentYear}"
        style="width:100%">
        <xp:selectItems>
            <xp:this.value><![CDATA[${javascript:yearBean.years}]]></xp:this.value>
        </xp:selectItems>
        <xp:this.converter>
            <xp:convertNumber
                type="number"
                integerOnly="true">
            </xp:convertNumber>
        </xp:this.converter>
    </xp:comboBox>

The page shows up perfectly and 2013, 2014 and 2015 are available for selection.

Pick one and submit: Boom! Error! (what the...)


How come I get "Validation Error: Value is not valid"?

I started digging for documentation on what kind of values the <xp:selectitems> expect.

The help file itself was of no use. It simply explains how to "pipe-separated" strings for values...

But:
OpenNTF has released a XPages Control Documentation as part of the XPages Extension Library.
There is also a Domino Designer javadoc describing all the classes backing XPages.

Trying to squeeze out what was the problem with my page from this information however did only partly succeed. Neither did a Google search...

Suddenly (and I don't know how) it came to me that perhaps the number converter <xp:NumberConverter> really expects something floating-point-ish...


I changed my code accordingly:

package no.inforte.test;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import javax.faces.model.SelectItem;

public class YearBean implements Serializable {

    private static final long serialVersionUID = 1L;

    public List<SelectItem> getYears() {
        int thisYear = Calendar.getInstance().get(Calendar.YEAR);

        List<SelectItem> selectItems = new ArrayList<SelectItem>();

        selectItems.add(new SelectItem(new Double(thisYear - 1), new Integer(thisYear - 1).toString()));
        selectItems.add(new SelectItem(new Double(thisYear), new Integer(thisYear).toString()));
        selectItems.add(new SelectItem(new Double(thisYear + 1), new Integer(thisYear + 1).toString()));
        return selectItems;
    }
}
Note! The only change is that the SelectItem is now equipped with Double values.


And voila! Now it works without the validation error! :-)


mandag 3. februar 2014

My thoughts on IBM Connect 2014

IBM Connect 2014 is history. I am writing this on the flight back to Norway and everyday life.
This post is not about all the new stuff IBM presented for us. All of that is probably fully covered in numerous articles and blogs already. Rather I will try to describe my impressions and thoughts. 

The IBM message

During the conference it became very clear to me what IBM has tried to tell us all the past 4-5 years; "Jump on the Connections bandwagon or we will have to leave you behind!"
This would have sounded like craziness some years ago but now it makes perfect sense! Connections has become a fabulous piece of software and the Social Business Toolkit makes it easier to contribute to it than ever before, almost whatever platform you're contributing from.


My goals 

 

Inspiration

 IBM Connect is actually all about inspiration. Meeting other people sharing the same interests and passion as yourself creates loads of positive energy. Seeing all the cool stuff speakers are presenting makes you wanna go home and do the same.

 

Making community friends

To keep this inspiration I found I had to get to know some of you better. Not only as bloggers (or whatever you all are doing for the community) but as persons with a name and a face. I'm not saying I got to know you personally (Connect was to short for that) but going to the same sessions, smalltalk during breaks etc. felt rewarding and will help me keep that inspiration in the year to come.
For this I thank you all!

Certification

Since IBM just started using Pearson Vue as their certification partner all assessment and certification test were available free of charge during the conference. This is a great idea and something I hope IBM will continue to do going forward.
My last AD certification was 8, and thus I tried to pass the AD 9A and 9B tests. I failed at 9B, but at least it got me started...

Sessions  

 

Opening General Session

If I return next year I will probably stay in bed or do some shopping instead of attending the OGS. Russel Maher states in his blog about the subject "Now the entire OGS is just one long promotional video interrupted by an actual commercial?". And he is darn right!
Sad...

XPages sessions

As a Notes/Domino old-timer another objective for Connect was learning more about Xpages. Spending half of my time at work doing Domino administration hasn't actually made me an expert.
Thus I wanted to attend so many sessions about Xpages as possible, which I did.
And mostly they all were very good! The speakers were well prepared, provided extensive slide material making it easy to follow up on back home, good examples etc.
No wonder IBM calls you Champs! Well deserved! Kudos!

I mostly attended sessions in the AD track. What annoyed me was that several the intresting sessions was scheduled at the same time, thus making me choose. Other times I found that there in fact were no sessions I really felt like attend... I hope this was not intentional and that IBM will pay more attention to this next year.

OpenNTF BOF

OpenNTF held a birds-of-a-feather (BOF) where we got to discuss plans for 2014 with members of the board. Can't tell you much plans now as need some decicions first. But it looks promising and will be very interesting!
Another topic discussed was how we could persuade IBM to make a XWork (Domino) community server, free to use for non-commercial purposes. This would possibly attract more developers to the platform and give students a viable alternative to Glassfish, JBoss and all the other application servers out there. We all signed a piece of paper that was handed over to IBM during the "Meet the product managers" session.

 

Domino development BOF

Another favorite session of mine was the Domino Development (BOF205 hosted by Pete Janzen and Martin Donnelly) where the core developers for Domino, Designer and Xpages met hard core developers from the community. Demands from the community like "give us a Designer based on a newer version of Eclipse", "open source more parts of the Domino server", "modernize the java API" and "get rid of the java.policy" was debated. Really interesting!

Solutions Showcase

I didn't get to spend much time in the Solutions Showcase this year. I did go to the OpenNTF booth, however, where Nathan Freeman gave me a demonstration of the new wrapper for the Domino Java API project. I must say the work done in this project is simply awesome!

Except for this I actually were most impressed by the Whitsell Consulting booth. They told me they were a small company (10 employees) selling nothing but their consulting services. No products, just heads! Really cool!

Next year...

I hope IBM takes our evaluations (and conserns) into account when planning for Connect 2015. To much of this commerial and non-technical babble will eventually scare off us hard core developers and administrators. As my colleague Arnstein stated; "Next year I may consider Google IO instead..."

lørdag 18. januar 2014

Worth mentioning about Domino Designer and SourceTree...

I have (as so many of you experts out there) jumped on the SourceTree bandwagon.

In the past I used Bitbucket and Mercurial directly from Domino Designer (DDE). This actually worked pretty good for me, so why change?

Well: I was of course fascinated by SourceTree's ability to help you with merging...


But my message today is not about merging, but to praise the extra control I felt when dealing with SourceTree!


When working with SourceTree there a big part of the application workspace is dedicated to showing you which files you have modified (see below).

When working with some changes to our (Inforte) system for time accounting, billing etc. I knew I had edited at least 5 files, but only 2 of them was shown as modified...

I tried to manually sync the ntf with the on disk project (ODP) several times. Nothing happened...


I checked the date stamp on the files that should have been modified in the ODP, but they all had old dates...

I almost panicked! (I guess the only reason for not doing so was because my kids had just gone to bed...)

When I came to my senses I restarted DDE and (of course) after having synced again all my modified files were available for commit. :-)


So; When in doubt, restart Domino Designer!

torsdag 16. januar 2014

NotesItem.IsProtected: How has this wonderful feature passed me by for so many years?

Last week I needed to do some batch processing on the person documents in Domino Directory. So, as any other decent person would do, I created an agent.

When testing the compared fields modified by my agent with similar fields in a document not modified, and noticed that an item property "PROTECTED" was not set...




After a little investigation I found this wonderful security feature. The "Must have at least Editor access to use" field property prohibits a user with Author access to the document to edit the field. The property is available to all kind of fields.




I instantly thought of several applications I have made in the past that could have needed exactly this functionality. Because of me being not aware of this I chose different, and more time demanding techniques, to achieve this.

The item property is available using Lotusscript, Java or Javascript as well, so there you have 3 more reasons why I should have seen it but didn't...

I have not (yet) tried to explore how XPages cope with this, but since Java and Javascript supports querying and setting this property it's supported for sure. If any of you reading this knows more about this feel free to comment.



Last: To my defense I asked two of my dry capable colleagues if they knew about this feature. Lucky for me they didn't so I feel I'm not a complete jerk. And that fact makes it even more important to bring this information to the masses... :-)


lørdag 4. januar 2014

IBM IHS error: mod_domino: apr_socket_connect, could not connect to Domino Server

I just had a problem getting IHS to communicate with Domino 9.0.1. The IHS error.log stated the following:
mod_domino: apr_socket_connect, could not connect to Domino Server
I browsed the documentation and found:
The Domino HTTP server only accepts connections that originate from the same computer. By default, mod_domino uses the local loop back address of 127.0.0.1 to connect to the Domino HTTP server. Both server processes must run on the same computer.
When IHS is installed as a part of Domino the Domino HTTP task listens to port 9288. I figured I needed to find out which IP addresses the HTTP task was listening on port 9288 on. Netstat is good at this and revealed the following:
TCP    10.201.17.12:9288      0.0.0.0:0             LISTENING
Domino was listening on port 9288, but not on the loopback address.
Suddenly it struck me that I had to add localhost to field in the server document where you specify the host name(s) Domino HTTP task listens to.
Screen Shot 2013-12-23 at 14.05.23
I added localhost, restarted the Domino server and voila! :-)