org.ujorm.wicket.component.form
Class FieldProvider<U extends Ujo>

java.lang.Object
  extended by org.ujorm.wicket.component.form.FieldProvider<U>
All Implemented Interfaces:
Serializable

public class FieldProvider<U extends Ujo>
extends Object
implements Serializable

Field Factory

Author:
Pavel Ponec
See Also:
Serialized Form

Field Summary
static String PASSWORD_KEY_NAME
          Password key name to create a component PasswordField
 
Constructor Summary
FieldProvider(org.apache.wicket.markup.repeater.RepeatingView repeatingView)
          Default constructor with a repeatingView
FieldProvider(org.apache.wicket.markup.repeater.RepeatingView repeatingView, Map<String,Field> fields)
          Final constructor
FieldProvider(String repeatingViewId)
          Default constructor
 
Method Summary
 void add(Class<? super U> domainClass)
          Add all fields of a domain class to the form
 void add(Field field)
          Add any field to a repeating view and set the OutputMarkupPlaceholderTag to value true.
<T> void
add(Key<? super U,T> key)
          Add new field to a repeating view
<T extends Ujo>
void
add(Key<? super U,T> key, Class<? extends Field> fieldClass)
          Create a field of the required instance and set the result into container.
<T extends OrmUjo>
void
add(Key<? super U,T> key, Key<T,?> display, org.ujorm.criterion.Criterion<T> crn)
          Add a Combo-box for a persistent entity
 void add(KeyList<? super U> fields)
          Add all fields
<T> void
addCssStyle(Key<? super U,T> key, String cssStyle)
          Add a CSS style to the field of required key.
protected  void addValidator(Key<? super U,?> key, Field field)
          Set a validator of the Key to the Field from argument
<T> void
addValidator(Key<? super U,T> key, org.apache.wicket.validation.IValidator<T> validator)
          Set a visible attribute for a required filed.
<T> void
addValidator(Key<? super U,T> key, Validator<T> validator)
          Add a validator for a required filed.
<T> void
addValidatorUnchecked(Key<? super U,T> key, Validator validator)
          Add a validator for a required filed, where the validator have no generic type.
protected  U cloneDomain(U domain, OrmSessionProvider session)
          Clone the domain object or reload the ORM object from database.
protected  U copyToFields(U domain)
          Assign values to required component fields in a transaction for a lazy loading case
protected  Field<?> findFirstField()
          Find first enabled field with a non-null Key or return the null.
protected  int getClonedDepth()
          Get a default cloned depth for the method cloneDomain(org.ujorm.Ujo, org.ujorm.wicket.OrmSessionProvider)
 U getDomain()
          Copy new value to the result and return the result
<F extends Field>
F
getField(Key<? super U,?> key)
          Returns the related Field
 Collection<Field> getFields()
          Return all fields
 U getInputDomain()
          Get original domain
protected  Set<String> getKeyNames()
          Return all keys in a String format
<T extends Field>
T
getLast()
          Returns the last field or throw an exception
protected  OrmHandler getOrmHandler()
          Returns OrmHandler
 org.apache.wicket.markup.repeater.RepeatingView getRepeatingView()
          Returns the repeating view
 int getTextAreaLimit()
          Returns a minimal text length to create a TextArea component.
<T> T
getValue(Key<? super U,T> key)
          Get Value, or returns a default value
protected  boolean isMandatory(Key<? super U,?> key)
          Is the key mandatory ?
protected  boolean isPasswordKey(Key<? super U,?> key)
          Is the key type of PasswordField ? The default condition is: the last key name must be 'PASSWORD'.
protected  String newChildId()
          Generates a child component id
 void onChange(Key<? super U,?> source)
          Refresh component
 void onChange(Key<? super U,?> source, String action)
          Refresh component
 void requestFocus(org.apache.wicket.ajax.AjaxRequestTarget target)
          Set a focus to the first component by default
 void setDomain(U domain)
          Copy domain attributes to fields and clone the arguments to internal parameters.
<T> void
setEnabled(Key<? super U,T> key, boolean enabled)
          Set an enabled attribute for a required filed.
<T> void
setValue(Key<? super U,T> key, T value)
          Set Value
<T> void
setValue(Key<? super U,T> key, T value, org.apache.wicket.ajax.AjaxRequestTarget target)
          Set Value and repaint the component
 void setVisible(Key<? super U,?> key, boolean visible)
          Set a visible attribute for a required filed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PASSWORD_KEY_NAME

public static final String PASSWORD_KEY_NAME
Password key name to create a component PasswordField

See Also:
Constant Field Values
Constructor Detail

FieldProvider

public FieldProvider(String repeatingViewId)
Default constructor


FieldProvider

public FieldProvider(org.apache.wicket.markup.repeater.RepeatingView repeatingView)
Default constructor with a repeatingView


FieldProvider

public FieldProvider(org.apache.wicket.markup.repeater.RepeatingView repeatingView,
                     Map<String,Field> fields)
Final constructor

Parameters:
repeatingView - a repeating views
fields - Serializable field map
Method Detail

add

public void add(Field field)
Add any field to a repeating view and set the OutputMarkupPlaceholderTag to value true.


newChildId

protected String newChildId()
Generates a child component id


add

public <T> void add(Key<? super U,T> key)
Add new field to a repeating view


add

public void add(Class<? super U> domainClass)
Add all fields of a domain class to the form


add

public void add(KeyList<? super U> fields)
Add all fields


add

public <T extends Ujo> void add(Key<? super U,T> key,
                                Class<? extends Field> fieldClass)
Create a field of the required instance and set the result into container.

Type Parameters:
T - Ujo type
Parameters:
key - Related Key
fieldClass - Class must have got a one argument constructor type of Key.

add

public <T extends OrmUjo> void add(Key<? super U,T> key,
                                   Key<T,?> display,
                                   org.ujorm.criterion.Criterion<T> crn)
Add a Combo-box for a persistent entity


getValue

public <T> T getValue(Key<? super U,T> key)
Get Value, or returns a default value


setValue

public <T> void setValue(Key<? super U,T> key,
                         T value)
Set Value


setValue

public <T> void setValue(Key<? super U,T> key,
                         T value,
                         org.apache.wicket.ajax.AjaxRequestTarget target)
Set Value and repaint the component


getFields

public Collection<Field> getFields()
Return all fields


getField

public <F extends Field> F getField(Key<? super U,?> key)
Returns the related Field


getLast

public <T extends Field> T getLast()
                        throws ArrayIndexOutOfBoundsException
Returns the last field or throw an exception

Returns:
Not null always
Throws:
ArrayIndexOutOfBoundsException - No last filed was found.

getKeyNames

protected Set<String> getKeyNames()
Return all keys in a String format


getRepeatingView

public org.apache.wicket.markup.repeater.RepeatingView getRepeatingView()
Returns the repeating view


getOrmHandler

protected OrmHandler getOrmHandler()
Returns OrmHandler


isMandatory

protected boolean isMandatory(Key<? super U,?> key)
Is the key mandatory ?


addValidator

protected void addValidator(Key<? super U,?> key,
                            Field field)
Set a validator of the Key to the Field from argument


setDomain

public void setDomain(U domain)
Copy domain attributes to fields and clone the arguments to internal parameters.
Persistent object will be reloaded from database.


cloneDomain

protected U cloneDomain(U domain,
                        OrmSessionProvider session)
                             throws NoSuchElementException,
                                    IllegalStateException
Clone the domain object or reload the ORM object from database.

Throws:
NoSuchElementException
IllegalStateException

getClonedDepth

protected int getClonedDepth()
Get a default cloned depth for the method cloneDomain(org.ujorm.Ujo, org.ujorm.wicket.OrmSessionProvider)

Returns:
Minimal value is 1.

copyToFields

protected U copyToFields(U domain)
Assign values to required component fields in a transaction for a lazy loading case


getDomain

public U getDomain()
Copy new value to the result and return the result


getInputDomain

public U getInputDomain()
Get original domain


getTextAreaLimit

public int getTextAreaLimit()
Returns a minimal text length to create a TextArea component.

Returns:
The default value is 180 characters

isPasswordKey

protected boolean isPasswordKey(Key<? super U,?> key)
Is the key type of PasswordField ? The default condition is: the last key name must be 'PASSWORD'.


onChange

public void onChange(Key<? super U,?> source)
Refresh component


onChange

public void onChange(Key<? super U,?> source,
                     String action)
Refresh component


setEnabled

public <T> void setEnabled(Key<? super U,T> key,
                           boolean enabled)
Set an enabled attribute for a required filed. If the field is not found, the statement is ignored


setVisible

public void setVisible(Key<? super U,?> key,
                       boolean visible)
Set a visible attribute for a required filed. If the field is not found, the statement is ignored


addValidator

public <T> void addValidator(Key<? super U,T> key,
                             Validator<T> validator)
Add a validator for a required filed. If the field is not found, the statement is ignored


addValidatorUnchecked

public <T> void addValidatorUnchecked(Key<? super U,T> key,
                                      Validator validator)
Add a validator for a required filed, where the validator have no generic type. If the field is not found, the statement is ignored

See Also:
#setValidator(org.ujorm.Key, org.ujorm.Validator)

addValidator

public <T> void addValidator(Key<? super U,T> key,
                             org.apache.wicket.validation.IValidator<T> validator)
Set a visible attribute for a required filed. If the field is not found, the statement is ignored


addCssStyle

public <T> void addCssStyle(Key<? super U,T> key,
                            String cssStyle)
Add a CSS style to the field of required key. If the field is not found, the statement is ignored


requestFocus

public void requestFocus(@Nonnull
                         org.apache.wicket.ajax.AjaxRequestTarget target)
Set a focus to the first component by default


findFirstField

@Nullable
protected Field<?> findFirstField()
Find first enabled field with a non-null Key or return the null.



Copyright © 2014. All Rights Reserved.