1. In this approach all the selected values will be inserted in separate rows in table.Ex. if you select 3 value out of 10 in LOV then 3 rows will be inserted in table. No need to create the LOV in ViewObject.
Create Entity and View for the table in which you want to store the multiple selected LOV values. Also create the read only view which has the LOV values which user will select.
Ex. 1. PropertiesVO - VO in which value will be stored
2.PropertiesAvailableValuesRVO - VO in which provide LOV value.
2. First of all add af:selectManyChoice component to your page.
3. As shown in the below code create the binding,value and valueChangeListner in your bean and associate with this component.
4. Also create the f:selectItems and create the binding and value in bean same as done above.
<af:selectManyChoice label="#{caseviewcontrollerBundle.PROPERTIES}"
id="cp1"
value="#{pageFlowScope.ManagePerfected.propertiesCode}"
binding="#{pageFlowScope.ManagePerfected.smPropertiesCode}"
contentStyle="width:200.0px;"
disabled="#{pageFlowScope.IsEditable eq 'Y'}" valueChangeListener="#pageFlowScope.ManagePerfected.savePropertiesListener}"
autoSubmit="true" immediate="true">
<f:selectItems value="#pageFlowScope.ManagePerfected.availablePropertiesCode}"
binding="#{pageFlowScope.ManagePerfected.siPropertiesCode}"
id="cp12"/>
</af:selectManyChoice>
private List propertiesCode;
private List availablePropertiesCode;
private RichSelectManyChoice smPropertiesCode;
private UISelectItems siPropertiesCode;
public void setPropertiesCode(List propertiesCode) {
this.propertiesCode= propertiesCode;
}
public List getPropertiesCode() {
if (propertiesCode== null) {
propertiesCode= attributeListForIterator("PropertiesVOIterator","PropertiesCode");
}
return propertiesCode;
}
public void setsmPropertiesCode(RichSelectManyChoice smPropertiesCode) {
this.smPropertiesCode = smPropertiesCode;
}
public RichSelectManyChoice getsmPropertiesCode() {
return smPropertiesCode;
}
public void setSiPropertiesCode(UISelectItems siPropertiesCode) {
this.siPropertiesCode= siPropertiesCode;
}
public UISelectItems getSiPropertiesCode() {
return siPropertiesCode;
}
public void saveCasePropertiesListener(ValueChangeEvent valueChangeEvent)
{
ADFUtils.setCurrentTabDirty(true);
valueChangeEvent.getComponent().processUpdates(FacesContext.getCurrentInstance());
DCBindingContainer bindings =(DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
DCIteratorBinding iterator =bindings.findIteratorBinding("PropertiesVOIterator");
for (Row specialCode : iterator.getViewObject().getAllRowsInRange()) {
specialCode.remove();
}
DCIteratorBinding dcItr = ADFUtils.findIterator("ParentVOIterator");
Row row = dcItr.getViewObject().getCurrentRow();
Object parentId = row.getAttribute("ParentId");
int rcount =this.getPropertiesCode().size();
String[] propertiesCode =new String[this.getPropertiesCode().size()];
if (rcount > 0) {
for (int k = 0; k < rcount; k++) {
propertiesCode[k] =getPropertiesCode().get(k).toString();
Row r = iterator.getViewObject().createRow();
r.setAttribute("ParentId ", parentId );
r.setAttribute("PropertiesCode",propertiesCode[k]);
iterator.getViewObject().insertRow(r);
}
}
}
public void setAvailablePropertiesCode(List availablePropertiesCode ) {
this.availablePropertiesCode = availablePropertiesCode ;
}
public List getAvailablePropertiesCode() {
availablePropertiesCode =selectUniqueItemsForIterator("PropertiesAvailableValuesRVOIterator",
// iterator for displaying all items
"Value", // internal code for list item
"ShortDescription"); // display value for list item
return availablePropertiesCode ;
}
public List<SelectItem> selectUniqueItemsForIterator(String iteratorName,
String valueAttrName,
String displayAttrName) \
{
List<SelectItem> selectItems = new ArrayList<SelectItem>();
HashMap<String, String> itemsMap = new HashMap<String, String>();
DCIteratorBinding tsriter = ADFUtils.findIterator(iteratorName);
ViewObject tsrvo = tsriter.getViewObject();
tsrvo.executeQuery();
// for (Row row : tsrvo.getAllRowsInRange()) {
while (tsrvo.hasNext()) {
Row row = tsrvo.next();
String lovCode = row.getAttribute(valueAttrName).toString();
if (!itemsMap.containsKey(lovCode)) {
itemsMap.put(lovCode, lovCode);
String value = lovCode;
String finalDisplayValue =
(String)row.getAttribute(displayAttrName);
selectItems.add(new SelectItem(value, finalDisplayValue));
}
}
return selectItems;
}
Create Entity and View for the table in which you want to store the multiple selected LOV values. Also create the read only view which has the LOV values which user will select.
Ex. 1. PropertiesVO - VO in which value will be stored
2.PropertiesAvailableValuesRVO - VO in which provide LOV value.
2. First of all add af:selectManyChoice component to your page.
3. As shown in the below code create the binding,value and valueChangeListner in your bean and associate with this component.
4. Also create the f:selectItems and create the binding and value in bean same as done above.
<af:selectManyChoice label="#{caseviewcontrollerBundle.PROPERTIES}"
id="cp1"
value="#{pageFlowScope.ManagePerfected.propertiesCode}"
binding="#{pageFlowScope.ManagePerfected.smPropertiesCode}"
contentStyle="width:200.0px;"
disabled="#{pageFlowScope.IsEditable eq 'Y'}" valueChangeListener="#pageFlowScope.ManagePerfected.savePropertiesListener}"
autoSubmit="true" immediate="true">
<f:selectItems value="#pageFlowScope.ManagePerfected.availablePropertiesCode}"
binding="#{pageFlowScope.ManagePerfected.siPropertiesCode}"
id="cp12"/>
</af:selectManyChoice>
private List propertiesCode;
private List availablePropertiesCode;
private RichSelectManyChoice smPropertiesCode;
private UISelectItems siPropertiesCode;
public void setPropertiesCode(List propertiesCode) {
this.propertiesCode= propertiesCode;
}
public List getPropertiesCode() {
if (propertiesCode== null) {
propertiesCode= attributeListForIterator("PropertiesVOIterator","PropertiesCode");
}
return propertiesCode;
}
public void setsmPropertiesCode(RichSelectManyChoice smPropertiesCode) {
this.smPropertiesCode = smPropertiesCode;
}
public RichSelectManyChoice getsmPropertiesCode() {
return smPropertiesCode;
}
public void setSiPropertiesCode(UISelectItems siPropertiesCode) {
this.siPropertiesCode= siPropertiesCode;
}
public UISelectItems getSiPropertiesCode() {
return siPropertiesCode;
}
public void saveCasePropertiesListener(ValueChangeEvent valueChangeEvent)
{
ADFUtils.setCurrentTabDirty(true);
valueChangeEvent.getComponent().processUpdates(FacesContext.getCurrentInstance());
DCBindingContainer bindings =(DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
DCIteratorBinding iterator =bindings.findIteratorBinding("PropertiesVOIterator");
for (Row specialCode : iterator.getViewObject().getAllRowsInRange()) {
specialCode.remove();
}
DCIteratorBinding dcItr = ADFUtils.findIterator("ParentVOIterator");
Row row = dcItr.getViewObject().getCurrentRow();
Object parentId = row.getAttribute("ParentId");
int rcount =this.getPropertiesCode().size();
String[] propertiesCode =new String[this.getPropertiesCode().size()];
if (rcount > 0) {
for (int k = 0; k < rcount; k++) {
propertiesCode[k] =getPropertiesCode().get(k).toString();
Row r = iterator.getViewObject().createRow();
r.setAttribute("ParentId ", parentId );
r.setAttribute("PropertiesCode",propertiesCode[k]);
iterator.getViewObject().insertRow(r);
}
}
}
public void setAvailablePropertiesCode(List availablePropertiesCode ) {
this.availablePropertiesCode = availablePropertiesCode ;
}
public List getAvailablePropertiesCode() {
availablePropertiesCode =selectUniqueItemsForIterator("PropertiesAvailableValuesRVOIterator",
// iterator for displaying all items
"Value", // internal code for list item
"ShortDescription"); // display value for list item
return availablePropertiesCode ;
}
public List<SelectItem> selectUniqueItemsForIterator(String iteratorName,
String valueAttrName,
String displayAttrName) \
{
List<SelectItem> selectItems = new ArrayList<SelectItem>();
HashMap<String, String> itemsMap = new HashMap<String, String>();
DCIteratorBinding tsriter = ADFUtils.findIterator(iteratorName);
ViewObject tsrvo = tsriter.getViewObject();
tsrvo.executeQuery();
// for (Row row : tsrvo.getAllRowsInRange()) {
while (tsrvo.hasNext()) {
Row row = tsrvo.next();
String lovCode = row.getAttribute(valueAttrName).toString();
if (!itemsMap.containsKey(lovCode)) {
itemsMap.put(lovCode, lovCode);
String value = lovCode;
String finalDisplayValue =
(String)row.getAttribute(displayAttrName);
selectItems.add(new SelectItem(value, finalDisplayValue));
}
}
return selectItems;
}
I wanted to thank you for this great read!! I definitely enjoying every little bit of it and I have you bookmarked to check out new stuff you post.
ReplyDeleteOracle Apps Technical Training in Bangalore