Directory

← Back

AppFoundation

Application foundation provides commonly used features to your Vaadin applications, such as persistence, authentication, permission management, i18n and view helpers.

Author

Rating

Popularity

<100

The add-on's goal is to provide a simple and lightweight foundation for Vaadin application. The add-on consists of individual modules which are designed to be used separately or in combination with other modules. Minimization of dependencies to other modules and third party libraries have been one of the primary goals with the module designs. With the application foundation library you get commonly used features such as JPA based persistence, view handling, i18n, authentication and permission management.

Dependencies: EclipseLink (persistence module) and XOM XML parser (i18n module)

Sample code

User user = new User();
user.setUsername(username);
FacadeFactory.getFacade().store(user);
...
String query = "SELECT u FROM User u WHERE u.username = :username";
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("username", username);

User user = FacadeFactory.getFacade().find(query, parameters);
// Authenticate a user
AuthenticationMessage msg = AuthenticationUtil.authenticate(
                    username, password);

// Get the User object of the currently inlogged used
User user = SessionHandler.get();

// Register a new user
RegistrationMsg msg = UserUtil.registerUser((String) username
                    .getValue(), (String) password.getValue(),
                    (String) verifyPassword.getValue());

// Change the password of a user
ProfileMsg msg = UserUtil.changePassword(user, "currentpassword", 
        "newpassword","newpassword");

public class YourClass {
    ...
    @FieldTranslation(tuid = "USER")
    private String user;

    ...
}


class YourFormFieldFactory implements FormFieldFactory {
  private static final long serialVersionUID = 7983734476850858693L;

  public Field createField(Item item, Object propertyId,
    Component uiContext) {
    TextField field = new TextField();

    // Get the caption of the field from the YourClass class's
    // field's @FieldTranslation-annotation.
    field.setCaption(TranslationUtil.getFieldTranslation(
    YourClass.class, (String) propertyId));   
    field.setRequired(true);
    // Add a translated error message
    field
      .setRequiredError(InternationalizationServlet
      .getMessage(Locale.getDefault().getLanguage(), 
	  "ERROR_FIELD_MAY_NOT_BE_EMPTY"));
    field.setNullRepresentation("");
    return field;
  }
}
// Example of a view class
public class YourView extends AbstractView<Panel> implements
        ClickListener {
  ...
  public AdModificationView() {
    super(new Panel());
    ...
  }

  ...
}

// Example of a view container class
public class MainView extends CustomComponent implements ViewContainer {

  private VerticalLayout mainLayout = new VerticalLayout();
  private AbstractView<?> currentView = null;
  ...
   public MainView() {
    setCompositionRoot(mainLayout);
    ...
    ViewHandler.addView(YourView.class, this);
    ...
  }

  @Override
  public void activate(AbstractView<?> view) {
    if(currentView != null) {
      mainLayout.replaceComponent(currentView, view);
    } else {
      mainLayout.addComponent(view);
    }

    currentView = view;
  }

  ...
}


// Example of a method invoking the activation of a view
public class SomeClass {
  ...
  public void someMethod() {
    // This will trigger the MainView's activate()-method
    // with an instance of the YourView class
    ViewHandler.activateView(YourView.class);
  }
  ...
}


Permissions.initialize(application, new MemoryPermissionManager());

Role visitors = getVisitorRole();
Role regUsers = getRegisteredUsersRole();
Resource newsFeedView = getNewsFeedView();

Permissions.allow(visitors, "read", newsFeedView);
Permissions.allow(regUsers, "comment", newsFeedView);

// Before opening the resource, we can check the user's permissions
if(Permissions.hasAccess("read", newsFeedView)) {
	layout.addComponent(newsFeedView);
}

Compatibility

(Loading compatibility data...)

Was this helpful? Need more help?
Leave a comment or a question below. You can also join the chat on Discord or ask questions on StackOverflow.

Version

Version 2.0.0 supports (only) Vaadin 7. It's maturity level is experimental, because it has not been tested sufficiently to be able to have it's maturity level as something else. If you find bugs, please file tickets to the issue tracker.

Released
2013-02-03
Maturity
EXPERIMENTAL
License
Apache License 2.0

Compatibility

Framework
Vaadin 7.0+
Vaadin 6.0+ in 1.1.0
Vaadin 6.2+ in 1.3.5
Browser
N/A

AppFoundation - Vaadin Add-on Directory

Application foundation provides commonly used features to your Vaadin applications, such as persistence, authentication, permission management, i18n and view helpers. AppFoundation - Vaadin Add-on Directory
The add-on's goal is to provide a simple and lightweight foundation for Vaadin application. The add-on consists of individual modules which are designed to be used separately or in combination with other modules. Minimization of dependencies to other modules and third party libraries have been one of the primary goals with the module designs. With the application foundation library you get commonly used features such as JPA based persistence, view handling, i18n, authentication and permission management. Dependencies: EclipseLink (persistence module) and XOM XML parser (i18n module)
Online