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 :
- Hold or retrieve the necessary information to describe the desired forms or components.
- 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.
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:- property
- action
- array (of child components)
- 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