Note that there are some explanatory texts on larger screens.

plurals
  1. POFilter values in f:selectItems in JSF/Primefaces
    primarykey
    data
    text
    <p>I have bilateral One to Many Relationship in a JSF + JPA application. I want to list out only filtered items from the list in the view. Doing it in the controller is difficult and is it possible to filted like below?</p> <pre><code>&lt;p:selectOneListbox id="cmbField" value="#{investigationItemController.current}" &gt; &lt;f:selectItems value="#{investigationItemController.currentInvestigation.reportItems}" var="ri" itemLabel="#{ri.name}" itemValue="#{ri}" itemRendered="#{ri.retired ne true and ri.ixItemType eq 'Value'}" /&gt; &lt;/p:selectOneListbox&gt; </code></pre> <p>As itemRendered is not an attribute, I tried this, but failed.</p> <pre><code>&lt;p:selectOneListbox id="cmbField" value="#{investigationItemController.current}" &gt; &lt;ui:repeat value="#{investigationItemController.currentInvestigation.reportItems}" var="ri" &gt; &lt;h:panelGroup rendered="#{ri.retired ne true and ri.ixItemType eq 'Value'}" &gt; &lt;f:selectItem itemLabel="#{ri.name}" itemValue="#{ri}" /&gt; &lt;/h:panelGroup&gt; &lt;/ui:repeat&gt; &lt;/p:selectOneListbox&gt; </code></pre> <p>Owner Entity is as below.</p> <pre><code>@Entity @Inheritance(strategy = InheritanceType.SINGLE_TABLE) public class InvestigationItem extends ReportItem implements Serializable { private static final long serialVersionUID = 1L; @OneToMany(mappedBy = "investigationItem", cascade= CascadeType.ALL) List&lt;InvestigationItemValue&gt; investigationItemValues; public List&lt;InvestigationItemValue&gt; getInvestigationItemValues() { return investigationItemValues; } public void setInvestigationItemValues(List&lt;InvestigationItemValue&gt; investigationItemValues) { this.investigationItemValues = investigationItemValues; } } </code></pre> <p>The other entity is as follow</p> <pre><code>@Entity public class InvestigationItemValue implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @ManyToOne private InvestigationItem investigationItem; private String name; //Getters and setters and some other fields } </code></pre> <p>The important code set of the controller class is as follows</p> <pre><code>@ManagedBean @SessionScoped public final class InvestigationItemController implements Serializable { private static final long serialVersionUID = 1L; @EJB private InvestigationItemFacade ejbFacade; private InvestigationItem current; private Investigation currentInvestigation; // Other code goes here } </code></pre> <p>How can I filter items when using f:selectItem or f:selectItems in JSF/Primefaces ?</p> <p>(I will explain my real world situation why I desperately need this functionality.</p> <p>I am developing a medical applications and terms are confusing. A test or an Investigation (like Full Blood Count or Urine Full Report) can have several properties. Test is represented as an Investigation Entity. A test comprised of one or more fields (like Haemoglobin, White Cell Count for FBC and Colour, Apperance for UFR). It is represented as InvestigationItem. A single InvestigationItem may have a list of possible values of which one is selected for in different occasions. They are identified as InvestigationItemValue. So one InvestigationItem has a list of InvestigationItemValue(s). But some of the InvestigationItemValues may be of string type while others are of numeric, for example. The user needs to select one InvestigationItemValue when designing a new investigation of one particular type. So filtering is needed in the view.)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload