I tried to cache my dropdowndata in infinispan.
My Infinispan imports are (yes there are other imports too):
import org.infinispan.Cache;
import org.infinispan.configuration.cache.ConfigurationBuilder;
import org.infinispan.manager.DefaultCacheManager;
This is my Bean:
@Startup
@Named("cache")
@ApplicationScoped
public class CacheManagerBean implements Serializable {
private static final long serialVersionUID = 1L;
private DefaultCacheManager cacheManager;
// Dropdown-Values
private Cache<Integer, String> nations;
@Inject
MyEJB myEJB;
@PostConstruct
public void init(){
createCache();
updateCache();
}
private void createCache() {
// Construct a simple local cache manager with default configuration
cacheManager = new DefaultCacheManager();
// Define cache configuration
cacheManager.defineConfiguration("nations", new ConfigurationBuilder().build());
}
public void updateCache() {
nations = cacheManager.getCache("nations");
nations.putAll(myEJB.fetchNations());
}
public Cache<Integer, String> getNations() {
return nations;
}
public void setNations(Cache<Integer, String> nations) {
this.nations = nations;
}
The nations cache is filled with the data i need.
Now my problem is, that i want to create a SelectOneMenu with the data of this Cache and fill the selectItems with it:
<p:selectOneMenu id="nation"
value="#{bean.nation}"
styleClass="DetailsDropdown" var="activeNation">
<f:selectItem itemLabel="" itemValue="" noSelectionOption="true" />
<f:selectItems value="#{cache.nations.entrySet()}" var="entry"
itemValue="#{entry.key}" itemLabel="#{entry.value}" />
</p:selectOneMenu>
Unfortunatley the dropdown is always empty. Is there a workaround or maybe i missed something? Maybe i need to add something to a config for maven or wildfly?
Im using Wildfly 12, Primefaces 6.2, Infinispan 9.2.1.Final and Maven.
Thanks!
EDIT: The SelectOneMenu is inside a form an a panel. It works if i make a Map inside my view bean, not with the cache. All bean properties have getter and setter! The Cache has the data, the question is only about accessing it with JSF!
You can see the data inside the cache: http://prntscr.com/ktuead
How it should be (it is like that with exactly the same code and HashMap): http://prntscr.com/ktufji
This is the Dropdown with Cache (no errors!): http://prntscr.com/ktufqw