我是 ADF 的新手并面临一些问题:我的af:selectOneChoice
页面中有一个组件,其中包含数据列表。
当用户从组件列表中选择一个选项时,我想获得选定的值selectOnceChoice
。
我使用了带参数的请求 bean,并将其绑定在组件属性检查器的 value 选项中,但它未能给出所选值。如何从selectOneChoice
组件中获取选定的值?
我是 ADF 的新手并面临一些问题:我的af:selectOneChoice
页面中有一个组件,其中包含数据列表。
当用户从组件列表中选择一个选项时,我想获得选定的值selectOnceChoice
。
我使用了带参数的请求 bean,并将其绑定在组件属性检查器的 value 选项中,但它未能给出所选值。如何从selectOneChoice
组件中获取选定的值?
您可以使用ValueChangeListener
组件selectOnceChoice
。您可以将其绑定到valueChangeListener
bean 类方法并调用 API 以获取selectOnceChoice
组件的新值或旧值:
public void selectOnceChoiceValue(ValueChangeEvent valueChangeEvent){
if(valueChangeEvent != null) {
Object newVal = valueChangeEvent.getNewValue();
Object oldVal = valueChangeEvent.getOldValue();
}
}
<af:selectOneChoice id="soc1" simple="true" autoSubmit="true"
valueChangeListener="#{ExtnEmailNotificationPFBean.recipientTypeValue}"
label="#{''}"
binding="#{ExtnEmailNotificationPFBean.recipientTypeValue}"
partialTriggers="cl2"
value="#{pageFlowScope.ZcxEaNotificationRecipientType}">
<f:selectItems id="si4"
value="#{pageFlowScope.ZcxEaRecipientsTypeValueList}"/>
</af:selectOneChoice>
根据您需要对值执行的操作,一个选项是支持 bean 中的以下方法
public void valueChanged(ValueChangeEvent valueChangeEvent) {
this.setValueToEL("#{bindings.Deptno.inputValue}", valueChangeEvent.getNewValue()); //Updates the model
System.out.println("\n******** Selected Value: "+resolveExpression("#{bindings.Deptno.attributeValue}"));
System.out.println("\n******** Display Value: "+resolveExpression("#{bindings.Deptno.selectedValue ne ' ' ? bindings.Deptno.selectedValue.attributeValues[1] : ''}"));
}
public Object resolveExpression(String el) {
FacesContext facesContext = FacesContext.getCurrentInstance();
ELContext elContext = facesContext.getELContext();
ExpressionFactory expressionFactory = facesContext.getApplication().getExpressionFactory();
ValueExpression valueExp = expressionFactory.createValueExpression(elContext,el,Object.class);
return valueExp.getValue(elContext);
}
public void setValueToEL(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);
}
你的 JSP 组件应该看起来像
<af:selectOneChoice value="#{bindings.Deptno.inputValue}" label="Select Department"
required="true" shortDesc="#{bindings.Deptno.hints.tooltip}"
id="soc1" autoSubmit="true">
<f:selectItems value="#{bindings.Deptno.items}" id="si1"/>
</af:selectOneChoice>
来自http://blogs.oracle.com/adf/entry/getting_selected_value_from_selectonechoice
如果您正在寻找更多与支持您想要查看的组件的视图对象的连接,这将为您提供实时显示的文本。
public void buttonPressed(ActionEvent actionEvent) {
// Get the binding
BindingContainer bindings =
BindingContext.getCurrent().getCurrentBindingsEntry();
// Get the sepecific list binding
JUCtrlListBinding listBinding =
(JUCtrlListBinding)bindings.get("DepartmentId");
// Get the value which is currently selected
Object selectedValue = listBinding.getSelectedValue();
System.out.println(selectedValue);
}
来自http://blogs.oracle.com/shay/entry/getting_the_value_from_a_selec
If I got it right, your problem is that value, you have selected with af:selectOneChoice
will be available at bean, only after submit. If thats the case, then you should either let user submit the form, or set autoSubmit
property of component to true
.
这应该这样做:
<af:selectOneChoice id="sampleId"
value="#{bindings.sampleAttribute.inputValue}"
label="#{bindings.sampleAttribute.label}"
valueChangeListener=#"{Bean.valueChangeListener}"
immediate="true" autoSubmit="true">
<f:selectItems id="sampleAttributeValues"
value="#{bindings.sampleAttribute.items}"/>
</af:selectOneChoice>
豆子会有:
public void valueChangeListener(ValueChangeEvent valueChangeEvent)
{
FacesContext.getCurrentInstance().renderResponse();
}
如果您将 autoSubmit 属性设置为“true”,请确保也将立即数设置为“true”。否则,将在页面级别触发验证。