0

I have an enum:

public enum Risk {
    LOW(10),
    MEDIUM(20),
    HIGH(30);
}

and a managed bean

@ManagedBean
@ApplicationScoped
public class Data {

    public Risk[] getRisks() {
        return Risk.values();
    }
}

Now I can display the values in a <p:selectOneMenu>

<p:selectOneMenu>
     <f:selectItems value="#{data.risks}"
                    var="t"
                    itemValue="#{t}"
                    itemLabel="#{texts[t.name]}"/>
 </p:selectOneMenu>

However what If I wanted to show not all values but only a set of them, e.g. LOW and MEDIUM, how can I do this?

Tiny
  • 27,221
  • 105
  • 339
  • 599
matthias
  • 1,938
  • 23
  • 51
  • Is it permanent or conditional? If conditional, which conditions exactly? All in all I think you ultimately need this answer: http://stackoverflow.com/questions/6932034/how-to-conditionally-render-an-fselectitem-tag/ – BalusC Dec 17 '15 at 09:20
  • it is permanent. The problem is that I don't know how I can select only one item of my Risk enum. How can I say: itemValue="#{data.risk.LOW} ? – matthias Dec 17 '15 at 09:32
  • Just create a new array with the value removed? Not really JSF. – BalusC Dec 17 '15 at 09:32
  • Yeah, I wanted to avoid that – matthias Dec 17 '15 at 09:33
  • A fixed subset of an enum is part of the model. So why do it in the view? See http://stackoverflow.com/questions/3786125/how-to-fetch-a-subset-of-an-enumeration. Or just 'disable' the ones that are not to be used like BalusC stated... – Kukeltje Dec 17 '15 at 13:24

0 Answers0