How to avoid page refresh while using selectOneChoice - oracle-adf

I am working on JDeveloper 11g Release 2. I am having af:input text elements and af:selectonechoice elements in my form. The problem is with af:selectonechoice element. After selecting a value from this choice list, it refreshes the values of other elements. I mean the values of af:inputtext are lost or the fields becomes empty.
The code for af:selectonechoice is as follows:
<af:selectOneChoice label="User Permission" id="soc"
value="#{row.bindings.UserPermission.inputValue}"
autoSubmit="true" valueChangeListener="#{SomeBean.setSomeValue}">
<af:selectItem label="Administrator" value="ADMIN" id="si1"/>
<af:selectItem label="Manager" value="MANAGER" id="si2"/>
<af:selectItem label="Employee" value="EMPLOYEE" id="si3"/>
</af:selectOneChoice>
Below is the code for input text:
<af:inputText value="XXX" label="XXX" id="id3" readOnly="true" partialTriggers="soc" >
</af:inputText>
Only the above inputText has partialtriggers. This works fine. Also I am sure that other input elements not having any partial triggers. Why the other input elements also being updated. Any ideas regarding this.
EDIT:
<af:column sortProperty="#{bindings.TasksView1.hints.TaskNo.name}"
sortable="true" headerText="Task No" id="c2">
<af:inputText value="#{row.bindings.TaskNo.inputValue}"
label="#{bindings.TasksView1.hints.TaskNo.label}" id="id3"
partialTriggers="soc">
</af:inputText>
</af:column>
And Code for ValueChangeLister is:
public void generateTaskNo(ValueChangeEvent valueChangeEvent){
DCBindingContainer dcBindings = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
DCIteratorBinding iterBind = (DCIteratorBinding)dcBindings.get("TasksView1Iterator");
valueChangeEvent.getComponent().processUpdates(FacesContext.getCurrentInstance());
String task_code = (String)iterBind.getCurrentRow().getAttribute("USERPERMISSION");
task_code = task_code +'-';
String task_no = (String)iterBind.getCurrentRow().getAttribute("TaskNo");
task_code = task_code + task_no;
iterBind.getCurrentRow().setAttribute("TaskNo", task_code );
}
Here i am getting the SelectOneChoice value and Input text value[with id 'id3' ]. Based on the selected choice's value[Admin,manager,employee] i will set the value[TaskNo] in that input text. This should not affect other input fields in the form. But the problem is all other input fields are also updating and losing their previous values. I am sure those input fields don't have any partial triggers.

Your select one choice (SOC) set as auto submit = true. Then any element had partial triggers for SOC, Then that elements get refreshed. element SOC submit his value to server and other elements listen that value. listening elements needs to refreshed for update his value for SOC

The solution for this is if you use select one choice component with list of values you want store the id in database. For suppose your storage "ID" datatype consist integer but in database storage column datatype consist Varchar then soc components automatically refreshed when click save.so let you check the db column and list of values(lov) store value.

Related

Fetch Id from SelectOneChoice in ADF 12c

I am using Oracle ADF12C, I have a table which has an strong textselect One Choice>(Customized Query) as a column, on change of the value I need to open a popup, I have tried using value Change Listener to fetch the ID but not able to find. Any Suggestions….
I have tried using the JavaScript to fetch the ID, still it did not work
<af:selectOneChoice value="#{row.bindings.ProfileId.inputValue}"
label="#{row.bindings.ProfileId.label}"
required="#{bindings.Assets1.hints.ProfileId.mandatory}"
shortDesc="#{bindings.Assets1.hints.ProfileId.tooltip}"
id="soc7"
binding="#{GenericListenerBean.assetprofileBV}">
<f:selectItems value="#{row.bindings.ProfileId.items}"
id="si8"/>
<f:validator binding="#{row.bindings.ProfileId.validator}"/>
<af:clientListener method="profileLovValue"
type="valueChange"/>
</af:selectOneChoice>
function profileLovValue() {
alert("function called");
var lov_value = document.getElementById('soc8');
alert("Executedd ======"+lov_value);
var strUser = lov_value.options[lov_value.selectedIndex].value;
alert("value ======"+strUser);
}
There is a couple issues in your code. you are doing a :
var lov_value = document.getElementById('soc8');
when your af:selectOneChoice Html DOM ID will be something like "p1::pc2::soc7".
If you want to get the real Html DOM ID of an element from your browser, you need to right-click it in your browser and click Inspect to check the real ID in your console.
Since you are using the oracle ADF framework, you should also avoid JavaScript and use Java with built-in java ADF fonction.
—If you want to get the value of this #{row.bindings.ProfileId.inputValue} use resolveExpression as describe here https://cedricleruth.com/how-to-retreive-the-value-of-an-iterator-binding-variable-programmatically-in-adf/
//Here is how to simply retreive the value of and ADF Binding from the view El Expression :
//Below is a view example with values taken from an ADF View Object
<af:inputText id="it1" autoSubmit="true" value="#{bindings.YOUR_VO.YOUR_VO_ATTRIBUTE.inputValue}" />
<af:table value="#{bindings.YOUR_VO.collectionModel}" var="row">
<af:column sortProperty="#{bindings.YOUR_VO.hints.YOUR_VO_ATTRIBUTE.name}"
id="c1">
<af:outputText value="#{row.YOUR_VO_ATTRIBUTE}" id="ot1"/>
</af:column>
</af:table>
//Using below function you can easily get any of those value in your ADF Bean as follow :
//Note: replace String by the correct type
String inputTextValue= (String)resolveExpression("#{bindings.YOUR_VO.YOUR_VO_ATTRIBUTE.inputValue}");
String currentRowValue= (String)resolveExpression("#{row.YOUR_VO_ATTRIBUTE}");
/**
* Method for taking a reference to a JSF binding expression and returning
* the matching object (or creating it).
* #param expression EL expression
* #return Managed object
* #author : Duncan Mills, Steve Muench and Ric Smith's JSFUtils class
*/
public static Object resolveExpression(String expression) {
FacesContext facesContext = getFacesContext();
Application app = facesContext.getApplication();
ExpressionFactory elFactory = app.getExpressionFactory();
ELContext elContext = facesContext.getELContext();
ValueExpression valueExp = elFactory.createValueExpression(elContext, expression, Object.class);
return valueExp.getValue(elContext);
}
—If you want to get the ID of the element that trigger an event :
public void yourValueChangeEvent(ValueChangeEvent valueChangeEvent) {
String IdOfTheObjectTriggeringTheEvent = valueChangeEvent.getComponent().getId();
}
I think you need change your design to avoid using JavaScript. Oracle ADF run java code on server side.
In the code, you bound the selectOneChoice to assetprofileBV
binding="#{GenericListenerBean.assetprofileBV}">
You can get value of this selectOneChoice by assetprofileBV.getValue() .You can use valueChangeListener attribute to listen when value change and get value

I need to access the old value of ADF viewObject

I have ADF page fragement (.jsff), which conatins ADF form based on ViewObject, I need to get the old value of af:RichInputField using EL expression, when I use:
#{bindings.fieldName.inputValue}, it gets the new submitted value, but what I need is the value before submission...
You can use the valueChangeListener attribute (https://docs.oracle.com/cd/E21043_01/apirefs.1111/e12046/oracle/adf/view/js/event/AdfValueChangeEvent.html) of your af:RichInputField to trigger a java function in a bean that will get the new value and the old value for you to do whatever you want.
Here is a quick example with an inputText (It would work in a similar way with any ADF Faces input) :
//In your jsff
<af:inputText value="#{bindings.YOUR_VO_BINDING_VALUE.inputValue}"
valueChangeListener="#{YOUR_BEAN_SCOPE.YOUR_BEAN.itChange}"
id="it">
<f:validator binding="#{bindings.YOUR_VO_BINDING_VALUE.validator}"/>
</af:inputText>
//In your YOUR_BEAN_SCOPE.YOUR_BEAN
public void itChange(ValueChangeEvent valueChangeEvent) {
String oldValue = valueChangeEvent.getOldValue();
String newValue = valueChangeEvent.getNewValue();
//do whatever you want with those values
}
If you need to set a binding value in the [//do whatever you want with those values] please read https://cedricleruth.com/how-to-set-jsf-binding-attribute-programmatically-in-oracle-adf/ :
JSFUtils.setExpressionValue("#{bindings.YOUR_VO_ATTRIBUTE.inputValue}",oldValue);

How to show List of Checkbox item value in JSP Page

I am not able to show checkbox value in JSP page and it shows some random data.
after saving, some random value is also stored in database and it is not able to store all 3 values in one column (stud_language column) in DB and i took datatype as varchar(100) for stud_language column
My Jsp Code.
Student.jsp
<td><form:label path = "stud_language">Language Known</form:label></td>
<td><form:checkboxes items = "${stud_language}" path = "stud_language" /></td>
Controller.java
#ModelAttribute("stud_language")
public Map<String, String> getStudLanguage() {
Map<String, String> stud_language = new HashMap<String, String>();
stud_language.put("Hindi", "Hindi");
stud_language.put("Marathi", "Marathi");
stud_language.put("English", "English");
return stud_language;
Student_List.jsp (where i want to shown the output where some random values are coming instead of checkbox items value)
<c:forEach items="${students}" var="stud">
<td>${stud.stud_language}</td>
i tried with this above code using for each but it show the same random value instead of Checkbox value as English,Hindi,Marathi both in view page and Database one column. How should i display all 3 checkbox values in one field and also how can i store all 3 checkbox values in one column in DB?

Need to get dynamic count of the selected check-boxes

I'm having the two types of check-boxes one is for selectAll check-box in the data table header, and another type selecting the check-box for each row.
I'm doing a operation, So I need to show the confirmation message, How do I get the count of the selected check-boxes from the Managed Bean.
My code was written in JSF 1.2.
I can able to do select all records, select records, ManagedBean is working fine, But I need to get how many of them got selected for deletion.
Here is the JSF code,
<i:commandLink id="delete"
onclick="if (!confirm('#{managedBean.deleteSelectedCount}')) return false;"
action="#{managedBean.deleteRecords}"
title="Delete records"
immediate="true">
<i:graphicImage url="images/icons/delete.gif" alt="Delete records" />
</i:commandLink>
;
;//Some coding
;
//Data table code starts
<i:dataTable id="caseDataTable"
<h:column>
<f:facet name="header">
<i:selectBooleanCheckbox id="selectAllRecords" title="select All records"
value="#{managedBean.selectAll}">
<a4j:support event="onclick" reRender="caseDataTable,globalMessages" action="#{managedBean.actionSelectAllRecordss}" onsubmit="showBusyIndicator();" oncomplete="hideBusyIndicator();" />
</i:selectBooleanCheckbox>
</f:facet>
<h:outputLabel for="selectCheckbox" value="selectCheckbox"/>
<i:selectBooleanCheckbox id="selectCheckbox"
title="select a record" value="#{managedBean.selected}" >
<a4j:support event="onclick" reRender="selectAllRecords, globalMessages" action="#{managedBean.actionSelectionChange}"
onsubmit="showBusyIndicator();" oncomplete="hideBusyIndicator();"/>
</i:selectBooleanCheckbox>
</h:column>
Possible solution is to use h:inputHidden component (I think it exists in JSF 1.2. If not, you can find some alternative).
For example
Add h:inputHidden to the page
<h:inputHidden id="selectedCountHidden" value="#{managedBean.deleteSelectedCount}"/>
Each time you click on header check box or any of row check boxes, calculate deleteSelectedCount value and re-render h:inputHidden. Something like
<i:selectBooleanCheckbox id="selectCheckbox" title="select a record" value="#{managedBean.selected}" >
<a4j:support event="onclick" reRender="...,selectedCountHidden,..."
And now, since h:inputHidden will always hold deleteSeletedCount value, you can read its value via java script so there is no need for re-loading the page when you click on commandLink
<i:commandLink id="delete"
onclick="if(!confirm(document.getElementById('form:selectedCountHidden').value))return false;"..../>
Note that if you have form with id defined, you will need to call
document.getElementById('form:selectedCountHidden').value
Otherwise just call
document.getElementById('selectedCountHidden').value
In any case, inspect page source and you will find the exact id of p:inputHidden.

XPages comboBox values issue on partial refresh

I have 2 combo boxes and 1 input text field. On change of the 1st combo I set some value in the input field and partial refresh the panel where the input field is.
OnComplete of this refresh, i partial refresh (using XSP partialRefreshPost) the panel of the 2nd combo box. This combo box value as you can see is just the 1st combo's value.
The problem is:
The combo value is set but the input value is not! Although input's panel refresh comes first and on complete comes the combo's panel refresh. If i remove the code from inside the 2nd combo's value tab then the input field works. (or if i just remove the reference of the 1st combobox from the 2nd combobox then it works again).
The weird thing is:
if i use a listbox instead of the second combo box then it works!!
The xpage design is:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:table>
<xp:tr>
<xp:td>
<xp:comboBox id="comboBox1">
<xp:selectItem itemLabel="a" itemValue="a"></xp:selectItem>
<xp:selectItem itemLabel="b" itemValue="b"></xp:selectItem>
<xp:selectItem itemLabel="c" itemValue="c"></xp:selectItem>
<xp:eventHandler event="onchange" submit="true"
refreshMode="partial" refreshId="panel1">
<xp:this.action><![CDATA[#{javascript:var inputText1:com.ibm.xsp.component.xp.XspInputText = getComponent("inputText1");
inputText1.setValue("aaaaaa");}]]></xp:this.action>
<xp:this.onComplete><![CDATA[alert("refreshed panel1");
XSP.partialRefreshPost("#{id:panel0}",{onComplete: function(){alert("refreshed panel0");}});]]></xp:this.onComplete>
</xp:eventHandler></xp:comboBox></xp:td>
<xp:td></xp:td>
</xp:tr>
<xp:tr>
<xp:td></xp:td>
<xp:td></xp:td>
</xp:tr>
</xp:table>
<xp:br></xp:br>
<xp:br></xp:br>
<xp:panel id="panel0">
<xp:comboBox id="comboBox2">
<xp:selectItems>
<xp:this.value><![CDATA[#{javascript:var comboBox1:com.ibm.xsp.component.xp.XspSelectOneMenu = getComponent("comboBox1");
if(comboBox1.getValue()!=null){
return comboBox1.getValue().toString();
}else{
return "its empty";
}}]]></xp:this.value>
</xp:selectItems>
</xp:comboBox></xp:panel>
<xp:br></xp:br>
<xp:panel id="panel1">
<xp:inputText id="inputText1"></xp:inputText>
</xp:panel>
<xp:br></xp:br>
<xp:br></xp:br></xp:view>
Just replace 2nd combo with this and see....
<xp:listBox id="listBox1">
<xp:selectItems>
<xp:this.value><![CDATA[#{javascript:var comboBox1:com.ibm.xsp.component.xp.XspSelectOneMenu = getComponent("comboBox1");
if(comboBox1.getValue()!=null){
return comboBox1.getValue().toString();
}else{
return "its empty";
}}]]></xp:this.value>
</xp:selectItems>
</xp:listBox>
Any ideas?
When using a combobox, the first value in the list is the selected value. When you are using a list box, you have to choose a value from the list first. If you select a value, your example will fail too.
Because you are changing the allowed values of the combobox/listbox programmatically, and then try to set a value which is not longer in the list (the value is posted back to the server when doing a partial refresh), a validation error occurs, and the value of the inputText ('aaaaa') is not set in the backend.
You can add a xp:messages component inside of the panels, then you can see the error message.
Try doing this bind the controls to a viewScope then it should work.
I always bind my components to something scope variable, field or bean because if you don't you can get lot's of strange value problems. That's my experience.
I've tested you code and my suggestion works as far as I can see.

Resources