Documentation

(applications:user)

Using Dynamic/User Objects

This is an old revision of the document!


As dynamic object we think of a dynamic created object which is available in the application without changing the application. Sometimes, it's useful to “inject” objects into your application and use such objects in your business logic. This use-case is already supported via Object Injection. The missing part is that it's not automatically possible to access such objects in your application. Sure, if you put an action in your LCO and a simple remote call in your custom application, it'll be easy. But it's not guaranteed that you have a custom application. It's some work to extend the standard ProjX application. So this is not a thing for one minute.

To support this use-case we have dynamic objects, available via standard ProjX API. And here is it:

public Object getDynamicContent(String pName);

The name is the important thing. By default, no dynamic objects exist, so the method will return null.

If want to use a custom dynamic object, write one e.g.:

public class DynamicUserContent extends AbstractDynamicContent
{
    @Override
    public String getContentName() 
    {
        return "userDetails";
    }
 
    @Override
    public Object getDynamicContent()
    {
        String sUser = SessionContext.getCurrentSession().getUserName();
 
        Bean bean = new Bean();
        bean.put("FIRST_NAME", "John");
        bean.put("LAST_NAME", "Doe");
        bean.put("EMAIL", "email@domain.com");
        bean.put("PROFILE_IMAGE", FileUtil.getContent(ResourceUtil.getResourceAsStream("/images/" + sUser.toLowerCase() + ".png")));
 
        return bean;
    }
}

This object must be injected in your Session LCO e.g. via ServiceLoader. If it's injected, the API call

((ProjX)getApplication()).getDynamicContent("userDetails");

will return the Bean instance of your DynamicUserContent.

So, it's super easy to inject objects and make it accessible in your application without changing your application code.

This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information