Plugging LightAdmin Into an Application

Please note that currently LightAdmin can only be used with JPA based applications.

To plug LightAdmin into your application, follow 3 easy steps below:

  • Declare repository in your POM
    <repositories>
      <repository>
        <id>lightadmin-nexus-releases</id>
        <url>http://lightadmin.org/nexus/content/repositories/releases</url>
        <releases>
          <enabled>true</enabled>
          <updatePolicy>always</updatePolicy>
        </releases>
      </repository>
     </repositories>
    
  • Define maven dependency
    <dependency>
     <groupId>org.lightadmin</groupId>
     <artifactId>lightadmin</artifactId>
     <version>1.0.0.M2</version>
    </dependency>
  • Enable LightAdmin web-module in your web.xml:
    <context-param>
     <param-name>light:administration:base-url</param-name>
     <param-value>/admin</param-value>
    </context-param>
    
    <context-param>
     <param-name>light:administration:security</param-name>
     <param-value>true</param-value>
    </context-param>
    
    <context-param>
     <param-name>light:administration:base-package</param-name>
     <param-value>[package with Administration Configurations, ex.: org.lightadmin.demo.config]</param-value>
    </context-param>
  • Optionally, configure link to your application from the LightAdmin interface
    <context-param>
     <param-name>light:administration:back-to-site-url</param-name>
     <param-value>http://yourApplication.com</param-value>
    </context-param>
    

Creating an application from scratch with LightAdmin interface:

  • In addition to the steps above, add your JPA persistence provider of choice (Hibernate, EclipseLink, OpenJpa) and setup basic Spring JPA configuration.
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:jdbc="http://www.springframework.org/schema/jdbc"
           xmlns:jpa="http://www.springframework.org/schema/data/jpa"
           xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
                               http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                               http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">
    
      <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="jpaVendorAdapter">
          <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
        </property>
      </bean>
    
      <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
      </bean>
    
    </beans>
  • Create an entity
    @Entity
    public class User {
    
    @Id
     @GeneratedValue(strategy = GenerationType.AUTO)
     private Integer id;
     private String firstname;
     private String lastname;
    
    // Getters and setters
    }
  • Create an Administration Configuration in the package defined in web.xml previously:
    public class UserAdministration extends AdministrationConfiguration<User> {
    
    public EntityMetadataConfigurationUnit configuration( EntityMetadataConfigurationUnitBuilder configurationBuilder ) {
     return configurationBuilder.nameField( "firstname" ).build();
     }
    
    public ScreenContextConfigurationUnit screenContext( ScreenContextConfigurationUnitBuilder screenContextBuilder ) {
     return screenContextBuilder
     .screenName( "Users Administration" ).build();
     }
    
    public static FieldSetConfigurationUnit listView( final FieldSetConfigurationUnitBuilder fragmentBuilder ) {
     return fragmentBuilder
     .field( "firstname" ).caption( "First Name" )
     .field( "lastname" ).caption( "Last Name" )
     .build();
     }