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:selectOneListbox id="cmbField" value="#{investigationItemController.current}" >
<f:selectItems value="#{investigationItemController.currentInvestigation.reportItems}" var="ri" itemLabel="#{ri.name}" itemValue="#{ri}" itemRendered="#{ri.retired ne true and ri.ixItemType eq 'Value'}" />
</p:selectOneListbox>
As itemRendered is not an attribute, I tried this, but failed.
<p:selectOneListbox id="cmbField" value="#{investigationItemController.current}" >
<ui:repeat value="#{investigationItemController.currentInvestigation.reportItems}" var="ri" >
<h:panelGroup rendered="#{ri.retired ne true and ri.ixItemType eq 'Value'}" >
<f:selectItem itemLabel="#{ri.name}" itemValue="#{ri}" />
</h:panelGroup>
</ui:repeat>
</p:selectOneListbox>
Owner Entity is as below.
@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<InvestigationItemValue> investigationItemValues;
public List<InvestigationItemValue> getInvestigationItemValues() {
return investigationItemValues;
}
public void setInvestigationItemValues(List<InvestigationItemValue> investigationItemValues) {
this.investigationItemValues = investigationItemValues;
}
}
The other entity is as follow
@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
}
The important code set of the controller class is as follows
@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
}
How can I filter items when using f:selectItem or f:selectItems in JSF/Primefaces ?
(I will explain my real world situation why I desperately need this functionality.
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.)