Thursday 13 December 2012

SharePoint Master Pages, a slog....

It has been a while since my last post, basically because I have been struck down by that most unwanted of Christmas Presents "The Office Cold"!


When not ensuring that any uninfected colleagues are being deluged with fresh virus I have been playing around with Microsoft's latest SharePoint offering, 2013.

Now a few cynical people might say that any other company appending 2013 to a product name would provoke the wrath of the gods what with 21.12.2012 around the corner but this being Microsoft the gods will make an exception in return for a reduction in license fees....

On The Face Of Things: paying attention led me, by accident, to a cool tool in SharePoint Designer. Or, reason to write a tutorial as my next post?


After you have recovered from installing SharePoint 2013 one of the next things you are going to be doing is playing with all the easily accessible features like MySites, Apps and generally having fun.
Yes, I just admitted to enjoying mucking about with a Microsoft product that doesn't play on an XBox, Ssshhh! 

However most seminars and training courses tend to push you towards being productive which leads you to one of the most vexing problems for an application middleware developer like me: the Master Page!!
I have been through this before with earlier generations of SharePoint and only today did I actually get around to this noisome job, creating a master page template.
These are the steps I took

  1. Search Google for sharepoint 2013 master page
  2. Take the first decent looking tutorial link
  3. Spend hours translating the English instructions into German!!! (I am forced to use SP with German and the translations sometimes suck badly)
  4. create a rudimentary html5 page with css and an image
  5. create a master page using this page + css + image
  6. check out how it looks
  7. be incredibly disappointed because the first thing you have to do is add SP tags to your HTML in order to get any kind of SP functionality involved
At this point I have to say that MS have not learned from previous mistakes: the code to add SP functionality in pages is incredibly bloated and utterly obscure. They could really learn from JSF here.

In order to add SPBLOAT to your page you need to access the page that SP converted into a master page (vast oversimplification for what really happens, find a tutorial to see why).
So, I download the page; what I actually did was follow the instructions on the tin which led me to installing Desktop Experience on my 2008 R2 dev machine so I could open the design library in Windows Explorer by way of WebDav! So now I can simply drop the file into VS 2012 and stare aghast at what happened to the lean mean html I offered to the SharePoint Gods in sacrifice. In the interests of humanity I am not going to  post any code here, I want to keep the reader I have!

VS 2012 did do me one favour though, by automatically highlighting links in blue and me being red/green colour blind I tend to focus on the blue first. The link embedded in the XML comment at the top of my poor html5 file lead me to the.... Ausschnitt-Galerie. Literal translations of this can lead to people getting arrested (neckline/cleavage gallery) but this is the Snippets Generator. Following the link reveals the part of SharePoint that to my mind has to be a leading contender for SharePoint MVP (Most Valuable Page).

With the Snippets Generator you simply select the SP function you want to add to your template and it provides you with the SPBLOAT you need to copy to your page. You can also add your own class strings to the top level component tag which means not having to wade through the SPBLOAT to find out what to change. This discovery has just saved me a mountain of time, stress and the ears of my as-yet-to-be-reinfected-with-the-cold-they-gave-me colleages because I don't need to hand code it!

I thought my poor page was sacrificed to help out with 21.12.2012 but it looks like I have to find another victim... HOWARD!!!

This would have been more interesting with pictures however all the screenies I could have taken would have been in Deutsch.

Thursday 29 November 2012

Worlds apart but not that different

One the face of things: a philosophical monologue.

I have been brushing up on my ASP.Net skills prior to the start of a rather large Sharepoint based project and during the last week have been comparing the JEE6 (Java Enterprise 6) stack to the ASP.Net stack.

Luckily I don't have to wallow in the mud with VB, the language of choice here is C# so the jump between the 2 languages, Java and C#, is not so great. Mind you the syntax of a programming language, especially when they have such close roots, should never be anything other than a trivial exercise for you.

Not a clash of ideologies here

There have been so many flame wars, rants and idealists fighting about .Net vs Java that I am not attempting to fan the flames again.
If you consider the 2 platforms, as you should be doing, then .Net and Java are really worlds apart but still not that different... really!

Adam Bien posted some while ago: JAVA EE OR .NET - AN ALMOST UNBIASED OPINION
I agree with a lot of what was said there and a lot of the comments, trolls notwithstanding, have kind of kept the material up to date. What I don't agree with is LINQ for SQL.
I have been playing with LINQ for SQL and it under pressure it cracks. With even moderate amounts of data things like paged data access becomes slower and slower and memory leaks all over the place.
LINQ is still excellent for queries on generic collections and especially XML though.

The thing is that the Java vs .Net arguments live because people are way too married to the favorite language or platform and are missing the point in the abstract. Can I use either platform to provide solutions in software which fulfill the customer's requirements without having to reinvent the wheel doing it?
The answer is a resounding yes because so much of the progress made on design ideologies, eg. Patterns and development practices, eg. Agile, are applicable to any application platform in general use. Not only that but the tools available use the results of such progress regardless of which platform.

What am I waffling on about? The Backend!

As I do most of my work in the Java World I was looking for a decent all purpose ORM tool seeing as the MS one is, well, only good for the MS World and still not very good at that either.

A colleague of mine pointed me in the direction of NHibernate, a project I was already aware of.
Yes, this is similar to Hibernate from the Java World. It does suffer a lot from "A Sea of XML  Configuration" though, similar to old style EJB.
It does have a lot of advantages though

  • Database agnostic with the caveat that a driver and possibly dialect exists for it
  • It is very well supported and is used in a lot of Projects.
  • There are a lot of similarities with Hibernate and JPA and for me the jump from JPA to NHibernate was not that wide.
If it weren't for all the XML though...
Enter ActiveRecord.
  • Uses NHibernate
  • Domain objects are classes which determine the structure in the backend.
    I find it easier to do the domain at the Object level and have the engine build the car as it were, ie have the ability to create or modify the Database Schema via changes to my domain classes and their relations.
  • The only XML you really ever need is for configuring the connection, this is a snap
  • Is really, really, easy to Unit Test, I have not seen the need to mock anything yet, I can test against a real DB. You can still mock things up really easily though.
The makers of ActiveRecord, Castle, also have other goodies. I have been using their Proxy tool for quite a while now.

I am almost fanatical about the Java Platform and I do really believe that it is the best general server platform in terms of cost, reliability, performance and freedom of choice. Having said that I am able to do my thing, developing middle tier components, in either environment, and only have to deal with the differences at the surface. With .Net you just have to work a little bit harder on the backend, with Java on the UI.

Now, when are PrimeFaces going to give me all their wonderful UI Components working under ASP.Net?

Wednesday 14 November 2012

PrimeFaces PUSH

On Monday this week I was going through my blogs round when I spotted this from Geertjan Wielenga,
some of you may know Geertjan as a Principal Product Manager for Oracle and NetBeans guru whose regular blog posts are well worth reading if you are a Java Dev and/or NetBeans user.

In essence what Geertjan is looking for is a way of publishing information to browsers where this information may come from hardware devices perhaps based on TinkerForge.

If you read his post you can see more about what exactly he wants to do.

I decided I would see if I could slap something together which could be used for something like this.

Requirements

  • Data to be supplied asynchronously to the web app and browsers
  • Wide browser support
  • As a Proof of Concept simulation is allowed.
My Technology Choices

I use PrimeFaces for most if not all of my JSF based WebApps and this has some very handy support for PUSH (WebSockets) which uses Atmosphere. I have never used this before so this is the perfect opportunity to try it out.

Because I wanted to do a little more than simply push the current vehicle direction and update a few p tags I also added a page which uses Raphael to provide SVG support. Basically my vehicle is a simple triangle that gets transformed into a direction supplied by data pushed to the client.

I had already suggested using a Singleton Session Bean using Timers as a way of supplying data and decided this would be the easiest way to simulate hardware being spun around and reporting its current direction to any interested clients.

I have created a Project for this on GitHub should you wish to try the code out for yourself.
Edit:

  • I have since found that Glassfish and WebSockets don't mix very well (at least with PrimeFaces).
    I created a version of the same project which runs well under Tomcat 7 where WebSocket support seems to work off the bat!
  • The AsynchDirectionChangeSimulator bean is no longer active but the same function is provided by a Servlet.

Here is the code for the Session Timer Bean that simulates the "hardware".

package org.andy.pf.tfsim.simulator;

import javax.ejb.Schedule;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import org.primefaces.push.PushContext;
import org.primefaces.push.PushContextFactory;

/**
 *
 * @author a.bailey
 */
@Singleton
@Startup
public class AsynchDirectionChangeSimulator {

    final static String[] DIRS = {
        "North",
        "Northeast",
        "East",
        "Southeast",
        "South",
        "Southwest",
        "West",
        "Northwest"
    };
    
    
    @Schedule(minute = "*", second = "*/1", hour = "*")
    public void pushDirection() {
        String nextDirection = DIRS[(int)(Math.random()*DIRS.length)];
        PushContext ctx = PushContextFactory.getDefault().getPushContext();
        if( ctx != null ) {
            ctx.push("/tfSim", nextDirection);
        }
    }
}


Please note that this looks breathlessly simple and it is because all the magic is wrapped up in the libraries being used.

Here is the page used to display my little triangle animated on push.
The code is meant to be readable by the way not perfect.


<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">
    <f:view contentType="text/html" encoding="utf-8">
        <h:head>
            <title>TinkerForge RT Sim with SVG</title>
            <h:outputScript library="js" name="raphael-min.js"/>
            <f:facet name="last">
                <script type="text/javascript">
                    var dirTransforms = {
                       'North':"R0",
                       'Northeast':"R45",
                       'East':"R90",
                       'Southeast':"R135",
                       'South':"R180",
                       'Southwest':"R225",
                       'West':"R270",
                       'Northwest':"R315"
                    };
                    var canvas = null;
                    var tf = null;
                    $(document).ready(function() {
                       canvas = Raphael(document.getElementById("raphaelPanel"), 300, 300);
                       // tf = canvas.rect(50, 20, 40, 100);
                       tf = canvas.path("M120 180H180L150 40L120 180");
                       tf.attr("stroke", "#000");
                    });
                    function setDirection(data) {
                        tf.transform(dirTransforms[data]);
                    }
                </script>
            </f:facet>
        </h:head>
        <h:body>
            <p:panel id="raphaelPanel">
            </p:panel>
            <p:socket onMessage="setDirection" channel="/tfSim"/>
        </h:body>
    </f:view>
</html>

Monday 12 November 2012

Dinner Guests

On the face of things: well worth the effort!

Every year my Wife and I invite a group of friends for dinner. It was that time of year last Saturday.

Most of our guests arrived punctually even though we aren't really sticklers for this on such occasions.
It was nice of them to make the effort though!

What awaited them was a 5 course meal with a selection of wines from my cellar.


  1. A slice Game Pie with green salad as a starter.
    Because we live in the country and some of my friends go hunting regularly we have a ready supply of boar, venison, pheasants, pigeons and in this case hare. One of the guests supplied the hare for this one.
  2. Lobster or Paprika soup.
    We always try to offer more than one soup because you can never guarantee everyone will like the one you do make.
  3. Smoked Salmon in vol-au-vent topped with either a Garlic or Yoghurt and Dill sauce, garnished with bean sprouts.
  4. Roast Veal with Roast Potatoes (secret recipe makes mine golden yellow packets of oral joy!), vegetables and Gravy.
  5. Tiramisou for dessert.

To wash this lot down I had Mumms Sekt, Monbijou 2009 (a delicious french red medium dry wine), Rivaner 2004, Chappelle 2007.

Altogether we had 12 people to dinner.
Considering that all the food was cooked by me with my Wife providing invaluable assistance I was very pleased to hear that everyone was not only stuffed but enjoyed every mouthful!

We have been doing this for several years now and it looks like the traditional pre-Christmas feed with our friends will continue.

Tuesday 6 November 2012

Always time for a first time

It has taken me quite a while to force myself to start a blog, mainly because I never really gave them much thought before.
Times change though and I am a firm believer in changing with them hence the blog.

About the blog

A lot of the focus of this blog will be about some of the things I do as a developer, things I learn and things I see others doing. There will be blogs about other things in my life too.

Currently I am involved in the publishing of a new book entitled PrimeFaces Cookbook something that should be available at the end of 2012. I will be posting more about this when the book becomes available.

About me

My profile will contain more of this information but until I get that sorted here it is

I currently work as a lead developer for web based applications for a leading agricultural machinery manufacturer in Germany.
Although English I and my Wife decided that we wanted to live in Germany and since then we have 2 kids, a house, a cat and a varying population of African Giant Snails

Apart from my time as a software developer I also enjoy singing, cooking and I also run a youth shooting group for a local sports shooting club.