lunes, 2 de octubre de 2017

JEE & JSF13th Part: Creating an abstraction view layer to JSF components and Forms (2/5). Storing configuration

0. Introduction


It is important to have a catalogue of all resources needed to control components and attributes that can be used. It is important for detecting uncatalogued elements used in the application.

As JSON format is relatively easy to be read, it is our candidate format.

The folder to store this catalogues is src/main/resources/config

For now, only a small number of elements are catalogued, but this is an alive catalogue, so as more components are needed, they should be enclosed in the catalogue.

1. Attributes catalogue

The name of this file is component-attributes.json and stores elements of ComponentAttribute class (that was seen in the last post) a sample is


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
[
 {"name":"name"       , "type":"OTHER"                                   , "comment":"name"},
 {"name":"type"       , "type":"OTHER"                                   , "comment":"type of the component with its prefix. (h_HtmlPanelGroup, p_InputText)"},
 
 {"name":"id"         , "type":"PROPERTY" , "pclass":"java.lang.String"  , "comment":"id"},
 {"name":"value"      , "type":"PROPERTY" , "pclass":"java.lang.Object"  , "comment":"Only for primefaces"},
 {"name":"styleClass" , "type":"PROPERTY" , "pclass":"java.lang.String"  , "comment":"To set style"},
 {"name":"class"      , "type":"PROPERTY" , "pclass":"java.lang.String"  , "comment":"To set style"},
 {"name":"disabled"   , "type":"PROPERTY" , "pclass":"boolean"           , "comment":"To disable input. Carefull with primitive types!"},
 {"name":"icon"       , "type":"PROPERTY" , "pclass":"java.lang.String"  , "comment":"To attach an icon"},
 
 {"name":"for"        , "type":"PROPERTY" , "pclass":"java.lang.String"  , "comment":"Used in labels to be attavhed to input fields"},
 
 {"name":"layout"     , "type":"PROPERTY" , "pclass":"java.lang.String"  , "comment":"If block and applied to an HtmlPanelGroups quets a div, else a span"},
 
 {"name":"children"   , "type":"ARRAY"                                   , "comment":"A collection of child component definitions"}
]


2. Components catalogue

The name of this file is component-types.json and stores elements of Component class (that was seen in the last post) a sample is


1
2
3
4
5
6
7
8
[{"name" :"p_InputText"     , "container":"false", "qclass":"org.primefaces.component.inputtext.InputText"       , "comment":"input text" },
 {"name" :"p_OutputLabel"   , "container":"false", "qclass":"org.primefaces.component.outputlabel.OutputLabel"   , "comment":"label "},
 {"name" :"p_AutoComplete"  , "container":"false", "qclass":"org.primefaces.component.autocomplete.AutoComplete" , "comment" : "input text with autocomplete"},
 
 
 {"name" :"h_HtmlPanelGroup", "container":"true" , "qclass":"javax.faces.component.html.HtmlPanelGroup"          , "comment" : "div: if layout=block; span if no layout attribute"}
    
]

Note the prefixes (p_, h_,..) in the name of components so that we can differentiate the libraries they belong to.


3. Components libraries catalogue


The name of this file is component-libraries.json and stores the prefixes used in the name of components in the component catalogue. 

1
2
3
4
5
6
[{"prefix" : "h",  "name" : "Mojarra JSF or Facelets"      },
 {"prefix" : "ui", "name" : "Used in <ui:repeat>"          },
 {"prefix" : "cc", "name" : "Used in composite components>"},
 {"prefix" : "p",  "name" : "PrimeFaces"                   },
 {"prefix" : "pe", "name" : "PrimeFaces Extensions"        }
]

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...