Wednesday, 5 August 2015

Wednesday, 3 June 2015

Road Testing

The Blog Platform is now in a state of a minimum viable product. I am guinea pigging it on my own website This guinea pigging is helping me find UI defects and bugs. Most importantly the guinea pigging is helping me improve the spec before the next iteration starts.

In the next iteration I intend to crate a web-service API so that each front-end can be a client of the platform. This will mean each front-end client is language and template engine independent from the Blog Platform.

I will be sure to add updates about the Blog Platform's progress here soon.

Monday, 25 May 2015

Comments are Implemented

The video below proudly demonstrates the commenting functionality I have been implementing this weekend for the blog platform.

Comments have a one to many relationship with posts.

I have used cascade on delete so that a post can be deleted without the need to delete each of its comments first. The JPA withing the Java looks like this:
    private Post post;

I cannot wait to start using the new blog platform now it is almost finished.

Saturday, 23 May 2015


The tags are hooked up. Please find a video of the end result below:

Each blog post can have n many tags. Tags are embedded into the 'Post' class.
    @CollectionTable(name="POST_TAGS", joinColumns = @JoinColumn(name="POST_ID"))
    private List<tag> tags = new ArrayList<>();

I experimented with tags as entities in order to query them in a more JPA way. However, after several hours of making it complicated I decided to go with embedding them. After all: Why complicate the entities for the sake of a JPQL query?

Tuesday, 19 May 2015

JSF Buttons Nested in a Repaintable Elements

There was a little bug in posts where any unsaved fields would be lost when removing a tag from the tag list. This happened because each tag element had <f:ajax render="@form" /> set.

Setting the JSF <f:ajax render="tags-output" /> had not facilitated the repainting of  the tag list. This was a problem and I thought <f:ajax render="@form" /> was the solution.

Armed with new knowledge about JSF  I have prefix the panelGroup's id with the form's id.

Now the bug has gone and the problem is solved.
    <ui:repeat var="t" value="#{}">
                render="posts:tags-output posts:tags"

Friday, 15 May 2015

A Cleaner Entity Count

Using TypedQuery<T> I got a cleaner entity count with JPA's JPQL.

Here is the cleaner way:

    public int countAllMessages(){
        return em.createQuery("SELECT count(m) FROM Message m", Number.class).getSingleResult().intValue();

Instead of:

    public int countAllMessages(){
        Query q = em.createQuery("SELECT count(m) FROM Message m");
        Number result = (Number) q.getSingleResult();
        return result.intValue();

Where q.getSingleResult() is cast to Number.

Thursday, 14 May 2015

General Settings

The general settings items are odd to model compared with the other entities that have been modeled within the blog platform.  The other entities created for the blog platform, such as 'Post' entities, can have n many instances persisted. If modeled this same way all settings would become one entity. Would it be better in this instance to persist each setting item individually?

I decided to try out modeling each setting individually for now. Here is what I have implemented.

     <label for="blog-desc">Blog Name</label>
        <f:ajax event="blur" />

    <label for="blog-desc">Blog Description</label>
        <f:ajax event="blur" />
public class ConfigurationWriter implements Serializable {
    private ConfigurationDAOBean ps;
    private String blogName;
    private String blogDescription;
    private void setup(){
        blogName = ps.fetch("blog-name").getValue();
        blogDescription = ps.fetch("blog-description").getValue();
    public void save(){
        saveHelper("blog-name", blogName);
        saveHelper("blog-description", blogDescription);
    private void saveHelper(String field, String value){
        Configuration c = ps.fetch(field);

    public String getBlogName() {
        return blogName;

    public void setBlogName(String blogName) {
        this.blogName = blogName;

    public String getBlogDescription() {
        return blogDescription;

    public void setBlogDescription(String blogDescription) {
        this.blogDescription = blogDescription;
public class ConfigurationDAOBean {

    private EntityManager em;

    public Configuration fetch(String item) {
        List<Configuration> results = em.createQuery("SELECT c FROM Configuration c WHERE = :name", Configuration.class)
                .setParameter("name", item)
        if (results.isEmpty()) {
            Configuration c = new Configuration();
            return c;
        return results.get(0);

    public void store(Configuration c) {

I am open to ideas!