0

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

Hami
  • 11
  • 5
  • Hi, by tagging it oracle and wildfly, you sort of implicitly state it e.g. does work on mysql or on glassfish. Tags are not for what you use but for where the indication of a problem is. And your title is not to good either. It just states two tags. – Kukeltje Sep 11 '18 at 11:03
  • thx, i removed the tags and changed the title – Hami Sep 11 '18 at 13:00
  • What if you just do `` or use plain jsf `` instead of a primefaces one? And what is your PF version btw? – Kukeltje Sep 13 '18 at 07:52
  • @Kukeltje thx a lot, your question for plain JSF helped me. Now i know my mistake! – Hami Sep 13 '18 at 08:02
  • And in your screenshot about the not-working version, I cannot even see the 'no selection option'. Sure the dropdown part is not just masked but the panel boundaries (which might not have been in the original one) – Kukeltje Sep 13 '18 at 08:03

1 Answers1

0

The problem was the var attribute. It looks like the p:selectOneMenu fails to work correctly if this attribute is present but not used. It was a leftover from a test I did before.

    <p:selectOneMenu id="nation"
        value="#{bean.nation}"
        styleClass="DetailsDropdown">
        <f:selectItem itemLabel="" itemValue="" noSelectionOption="true" />
        <f:selectItems value="#{cache.nations.entrySet()}" var="entry"
            itemValue="#{entry.key}" itemLabel="#{entry.value}" />
    </p:selectOneMenu>

After removing the var tag everything worked well!

Thanks to Kukeltje for the time and endurance!

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Hami
  • 11
  • 5
  • Please post your PF version to the question. Might be relevant. And so effectively this **WOULD NOT** have worked with a static map either... effectively not being infinispan related at all. So even though 'it worked with a static map' before, **ALWAYS, ALWAYS, ALWAYS, create a [mcve]. Yould have noticed the latest xhtml code you were running did not work with a static map either. Maybe good to 'reduce' the question to this code basic problem. Remember this Q/A when encountering future problems... – Kukeltje Sep 13 '18 at 08:12
  • Yes next time i will test the example before i post it. It would have saved lot of your time. Was my first post, sorry again! Will remember it! – Hami Sep 13 '18 at 08:18
  • Cheers, then I'm happy! – Kukeltje Sep 13 '18 at 08:23