AppFoundation
Application foundation provides commonly used features to your Vaadin applications, such as persistence, authentication, permission management, i18n and view helpers.
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); }
Links
Compatibility
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
- Released
- 2010-02-27
- Maturity
- BETA
- License
- Apache License 2.0
Compatibility
- Framework
- Vaadin 6.0+
- Vaadin 6.2+ in 1.0
- Vaadin 7.0+ in 2.0.0
- Browser
- Browser Independent
Vaadin Add-on Directory
Find open-source widgets, add-ons, themes, and integrations for your Vaadin application.