1

I'm pretty new to the general procedure of bean injection. I've googled a lot but haven't found a solution to my problem.

Additional Information

Running Wildfly 9.0.1 final EJB Vers. : 3.1 CDI Vers. : 2.2.16 (SP1) JSF Vers. : 2.2

import javax.annotation.PostConstruct;
import javax.ejb.Stateless;
import javax.inject.Named;

@Named
@ViewScoped
public class UserEmailSettingsBean extends UserModuleSettingsBean {

private List<String> store;
private List<String> selectedStore;
//getters and setters, some fancy stuff...

@Override
public boolean saveProperties() {
    LOG.info("Save called");
    LOG.info(selectedStore.toString());
    LOG.info(store.toString());
    for(String prop : store) {
        getProperties().setProperty(prop, String.valueOf(false));
    }

    for(String selectedProp : selectedStore){
        LOG.info("selected: " + selectedProp + ":" + getProperties().getProperty(selectedProp) + " -> true");
        getProperties().setProperty(selectedProp, String.valueOf(true));
    }
    
    super.saveProperties();
    return true;
    }
}

2nd Class:

public abstract class UserModuleSettingsBean implements ModuleSettings {
    private static final long serialVersionUID = 459417872482285085L;

    protected abstract List<String> getPropertiesName();

    @Inject
    private SettingsRepository settingsRepository;

    @Inject
    private SettingsService settingsService;

    private Properties properties = new Properties();
    @Override
    public boolean saveProperties() {
        String username = SecurityContextHolder.getContext().getAuthentication().getName();
        settingsService.store(getProperties(), username);
        return (true);
    }
}

The problem is, that the settingsService is constructed, however its field "settingsRepository" is null in my child class.

On the call of my save method from UserEmailSettings, getProperties().setProperty() is called with the right values, however its never stored, as the settingsRepository is null. I believe that is due to a wrong Injection for some reason.

Let me know if I need to provide more information ☺

Here is the needed part of SettingsRepository:

@Stateless
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public class SettingsService implements Serializable {

    private static final long serialVersionUID = 1695882717866085259L;

    @Inject
    SettingsRepository settingsRepository;
    //...
}

And here the information SettingsRepository

@Stateless
public class SettingsRepository extends AbstractBaseRepository<Settings, Long> {

/**
 * Instantiates a new settings repository.
 */
public SettingsRepository() {
    super(Settings.class);
}
}
Community
  • 1
  • 1

1 Answers1

0

wanted to say my problem was that I didn't called an init() function on the settingsService to create the propertys, so getProperties was empty