lunes, 18 de septiembre de 2017

JEE & JSF12th Part: Creating an abstraction view layer to JSF components and Forms (1/5). Description classes

0. Introduction

So far, we have learned to create JSF components programmatically with the desired properties and actions.

Imagine you want to migrate your application to another framework.

A way to achieve this is using classes that :

  1. Hold or retrieve the necessary information to describe the desired forms or components.
  2. Create the components programmatically (Builders)
Let's create a new java package called org.ximodante.jsf.component

In this entry, we will focus on the structure and classes that define components, attributes, actions and so on. 

1. AttributeType structure

This structure defines the type of an element of a component (I have decided it to be one of the following:

  1. property
  2. action
  3. array (of child components)
  4. other

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
package org.ximodante.jsf.component;

/**
 * 
 * @author Ximo Dante
 * A compompent attribute can be :
 *   1. property that can be accessed by a getter/setter
 *   2. action from a button, etc
 *   3. array like children, ...
 *   4. other
 *
 */
public enum AttributeType {
 PROPERTY,
 ACTION,
 ARRAY,
 OTHER
}


2. ComponentAttribute class

It is intended to have a catalogue of all attributes so that we can detect if a not catalogued attribute is proposed to be employed.

The attribute has a name and belongs to a defined class. Here is the source:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package org.ximodante.jsf.component;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * 
 * @author ximo Dante
 * 16/9/2017
 * name: name of attribute
 * setter : if the setter is buid by set + Name
 * pclass : class of the parameter or argument of setter
 * comment: comments
 */

@NoArgsConstructor @AllArgsConstructor
public class ComponentAttribute {
 @Getter @Setter private String name;
 @Getter @Setter private AttributeType type=AttributeType.PROPERTY;
 @Getter @Setter private String pclass;
 @Getter @Setter private String comment="This is a comment";
}

3. ComponentType class

It is intended to have a catalogue of all component types so that we can detect if a not catalogued component is intended to be used.

As we know there are some jsf components from different libraries that share the same name. So let's append a letter prefix and an underscore to the name to distinguish them.

For instance, the name "h_HtmlPanelGroup" is used to represent a panel of the class "javax.faces.component.html.HtmlPanelGroup"

The component type class is:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package org.ximodante.jsf.component;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * 
 * @author ximo Dante
 * 15/9/2017
 * name: prefix + "_" + name of component
 * container : if can have children
 * qclass : qualified class
 * comment: comments
 */
@NoArgsConstructor @AllArgsConstructor
public class ComponentType {
 @Getter @Setter private String name;
 @Getter @Setter private boolean container;
 @Getter @Setter private String qclass;
 @Getter @Setter private String comment;
 
} 

4. Exceptions

Let's create an Exception class for this package:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
package org.ximodante.jsf.component;

/**
 * Exception for component building
 * @author Ximo Dante
 *
 */
public class ComponentJsfException extends Exception{
 private static final long serialVersionUID = 1L;

 public ComponentJsfException(String message) { 
  super(message); 
 }
 

}

No hay comentarios:

Publicar un comentario

JEE & JSF16th Part: Creating an abstraction view layer to JSF components and Forms (5/5). Frequent problems

1. ERROR #1: Using a bean that does not exists In the previos entry we used this facelet file: 1 2 3 4 5 6 7 8 9 10 11 1...