This post is about a specific requirement that is to hide some values from adf based select one choice from UI
Previously I have posted about disabling some items from select one choice and this post uses same steps to hide values from lov
Blog about Oracle ADF, JDeveloper, PL/SQL, Java, JavaScript, jQuery and Other Web Technologies
import java.util.ArrayList; import java.util.List; public class Seasons { public Seasons(String name) { this.name = name; // To Store Header Values (Storing Seasons Name :)) } // Season and Charater Name private String name; // To Store Detail Values (Storing Season's Charatcers) private List<Seasons> characters = new <Seasons>ArrayList(); public void setCharacters(List<Seasons> empDet) { this.characters = empDet; } public List<Seasons> getCharacters() { return characters; } public void setName(String name) { this.name = name; } public String getName() { return name; } // This methods directly add characters value in list public void addCharaters(Seasons employee) { characters.add(employee); } }
// Master List to populate data in selectOnce choice List<Seasons> seasonList = new ArrayList<Seasons>(); public void setSeasonList(List<Seasons> seasonList) { this.seasonList = seasonList; } public List<Seasons> getSeasonList() { return seasonList; } //Constructor of Managed Bean to populate data on page load (you can move this code ) public TreeStyleLovBean() { super(); // Creating tree for Seasons and Characters details // Adding Master Values (seasons) Seasons season1 = new Seasons("Game of Thrones"); // Adding Detail Values (Child Node-Characters) Seasons character = new Seasons("Tywin Lannister"); season1.addCharaters(character); character = new Seasons("Tyrion Lannister"); season1.addCharaters(character); character = new Seasons("Jaime Lannister"); season1.addCharaters(character); character = new Seasons("Cersie Lannister"); season1.addCharaters(character); character = new Seasons("Ned Stark"); season1.addCharaters(character); // Adding Master Values (seasons) Seasons season2 = new Seasons("Arrow"); // Adding Detail Values (Child Node-Characters) character = new Seasons("Oliver Queen"); season2.addCharaters(character); character = new Seasons("Moira Queen"); season2.addCharaters(character); character = new Seasons("Laurel Lance"); season2.addCharaters(character); character = new Seasons("Sara Lance"); season2.addCharaters(character); // Adding Master Values (seasons) Seasons season3 = new Seasons("Vikings"); // Adding Detail Values (Child Node-Characters) character = new Seasons("Ragnar Lothrak"); season3.addCharaters(character); // Adding Master Values (seasons) Seasons season4 = new Seasons("The Flash"); // Adding Detail Values (Child Node-Characters) character = new Seasons("Barry Allen"); season4.addCharaters(character); character = new Seasons("Harisson Wells"); season4.addCharaters(character); character = new Seasons("Iris West"); season4.addCharaters(character); character = new Seasons("Joe"); season4.addCharaters(character); // Adding all list to topList seasonList.add(season1); seasonList.add(season2); seasonList.add(season3); seasonList.add(season4); }
<af:selectOneChoice id="selectBox" label="Choose Character" valuePassThru="true" styleClass="employeeSelectBox" contentStyle="width:150px;" binding="#{viewScope.TreeStyleLovBean.selectOneValueBind}"> <af:forEach items="#{viewScope.TreeStyleLovBean.seasonList}" var="seasonNm"> <af:selectItem label="#{seasonNm.name}" disabled="true" id="si1"/> <af:forEach items="#{seasonNm.characters}" var="characterNm"> <af:selectItem label="#{characterNm.name}" value="#{characterNm.name}" id="si2"/> </af:forEach> </af:forEach> </af:selectOneChoice>
<f:facet name="metaContainer"> <af:group> <![CDATA[ <style> .employeeSelectBox option{text-indent:15px;color:darkgreen;} .employeeSelectBox option[disabled]{color:red; background-color:#dddddd; font-weight: bold; text-indent:0px} </style> ]]> </af:group> </f:facet>
/**Value Change Listener of DeptIdTrans (to get selected and display value) * @param vce */ public void deptIdVCE(ValueChangeEvent vce) { System.out.println("New Value is-" + vce.getNewValue()); if (vce.getNewValue() != null) { this.setvalueToExpression("#{row.bindings.DeptIdTrans.inputValue}", vce.getNewValue()); //Updating Model Values Integer selectedCode = Integer.parseInt(this.getValueFrmExpression("#{row.bindings.DeptIdTrans.attributeValue}").toString()); System.out.println("******** Selected Value in List***** " + selectedCode); System.out.println("*******Display Value in List ****" + getValueFrmExpression("#{row.bindings.DeptIdTrans.selectedValue.attributeValues[1]}")); } }
/**Method to set value in Expression (EL) * @param el * @param val */ public void setvalueToExpression(String el, Object val) { FacesContext facesContext = FacesContext.getCurrentInstance(); ELContext elContext = facesContext.getELContext(); ExpressionFactory expressionFactory = facesContext.getApplication().getExpressionFactory(); ValueExpression exp = expressionFactory.createValueExpression(elContext, el, Object.class); exp.setValue(elContext, val); } /**Method to get value from Expression (EL) * @param data * @return */ public String getValueFrmExpression(String data) { FacesContext fc = FacesContext.getCurrentInstance(); Application app = fc.getApplication(); ExpressionFactory elFactory = app.getExpressionFactory(); ELContext elContext = fc.getELContext(); ValueExpression valueExp = elFactory.createValueExpression(elContext, data, Object.class); String Message = null; Object obj = valueExp.getValue(elContext); if (obj != null) { Message = obj.toString(); } return Message; }
<af:selectOneChoice value="#{bindings.LocationId.inputValue}" label="#{bindings.LocationId.label}" required="#{bindings.LocationId.hints.mandatory}" shortDesc="#{bindings.LocationId.hints.tooltip}" id="soc1" contentStyle="width:150px;color:red;"> <af:forEach items="#{bindings.Locations1.rangeSet}" var="list"> <af:selectItem label="#{list.City}" id="si1" value="#{list.LocationId}" disabled="#{ (bindings.DepartmentId.inputValue==100 and (list.LocationId==1000 || list.LocationId==1300)) || (bindings.DepartmentId.inputValue==110 and (list.LocationId==1500 || list.LocationId==1600 || list.LocationId==1700 || list.LocationId==1800 || list.LocationId==1900))}"/> </af:forEach> </af:selectOneChoice>
List<SelectItem> customList; public void setCustomList(List<SelectItem> customList) { this.customList = customList; } public List<SelectItem> getCustomList() { return customList; }
public List<SelectItem> getCustomList() { if (customList == null) { customList = new ArrayList<SelectItem>(); customList.add(new SelectItem("i1","Item 1")); customList.add(new SelectItem("i2","Item 2")); customList.add(new SelectItem("i3","Item 3")); customList.add(new SelectItem("i3","Item 4")); customList.add(new SelectItem("i5","Item 5")); } return customList; }
<?xml version='1.0' encoding='UTF-8'?> <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" xmlns:f="http://java.sun.com/jsf/core" xmlns:af="http://xmlns.oracle.com/adf/faces/rich"> <jsp:directive.page contentType="text/html;charset=UTF-8"/> <f:view> <af:document title="listPage.jspx" id="d1"> <af:form id="f1"> <af:panelGroupLayout id="pgl1" layout="vertical" halign="center"> <af:spacer width="10" height="10" id="s1"/> <af:selectOneChoice label="Custom List" id="soc1" contentStyle="font-weight:bold;color:darkgreen;"> <f:selectItems value="#{ListPolulatebean.customList}" id="si1"/> </af:selectOneChoice> </af:panelGroupLayout> </af:form> </af:document> </f:view> </jsp:root>