af:panelAccordion 部分触发 af:selectOneChoice valueChangeListener
我是 ADF 面孔的新手,在 af:selectOneChoice 的值更改上部分触发 af:panelAccordion 时遇到麻烦。 af:panelAccordion 在其 af:showDetailItem 中包含多个 af:showDetailHeader。所有 af:showDetailItem 及其 af:showDetailHeader 都是动态生成的。 bean College 位于视图范围内,其代码如下:
public class College {
private List<Department> departments;
private List<SelectItem> departmentDropDownMenu;
private String selectedDepartment;
public College() {
this.departments = new ArrayList<Department>(0);
Employee employee1 = new Employee("Employee 1", "Information");
Employee employee2 = new Employee("Employee 2", "Information");
Employee employee3 = new Employee("Employee 3", "Information");
Employee employee4 = new Employee("Employee 4", "Information");
Employee employee5 = new Employee("Employee 5", "Information");
List<Employee> employees1 = new ArrayList<Employee>(0);
employees1.add(employee1);
List<Employee> employees2 = new ArrayList<Employee>(0);
employees2.add(employee2);
List<Employee> employees3 = new ArrayList<Employee>(0);
employees3.add(employee3);
List<Employee> employees4 = new ArrayList<Employee>(0);
employees4.add(employee4);
employees4.add(employee5);
Department department1 = new Department("Department 1", employees1);
Department department2 = new Department("Department 2", employees2);
Department department3 = new Department("Department 3", employees3);
Department department4 = new Department("Department 4", employees4);
this.departments.add(department1);
this.departments.add(department2);
this.departments.add(department3);
this.departments.add(department4);
List<SelectItem> departmentDropDownMenu = new ArrayList<SelectItem>(0);
departmentDropDownMenu.add(new SelectItem("Department 1"));
departmentDropDownMenu.add(new SelectItem("Department 2"));
departmentDropDownMenu.add(new SelectItem("Department 3"));
departmentDropDownMenu.add(new SelectItem("Department 4"));
this.setDepartmentDropDownMenu(departmentDropDownMenu);
this.setSelectedDepartment("Department 1");
}
public void departmentDropDrownValueChangeListener(ValueChangeEvent event) {
String oldValue = event.getOldValue().toString();
String newValue = event.getNewValue().toString();
if(oldValue.equalsIgnoreCase(newValue)) {
return;
}
List<Department> departmentUpdated = new ArrayList<Department>(0);
for (Department department : departments) {
if(department.getDepartmentName().equals(newValue)) {
departmentUpdated.add(department);
break;
}
}
for (Department department : departments) {
if(!department.getDepartmentName().equals(newValue)) {
departmentUpdated.add(department);
}
}
this.setDepartments(departmentUpdated);
}
public void setDepartments(List<Department> departments) {
this.departments = departments;
}
public List<Department> getDepartments() {
return departments;
}
public void setDepartmentDropDownMenu(List<SelectItem> departmentDropDownMenu) {
this.departmentDropDownMenu = departmentDropDownMenu;
}
public List<SelectItem> getDepartmentDropDownMenu() {
return departmentDropDownMenu;
}
public void setSelectedDepartment(String selectedDepartment) {
this.selectedDepartment = selectedDepartment;
}
public String getSelectedDepartment() {
return selectedDepartment;
}
}
Department 和 Employee 类是简单的 POJO。 Department 类仅包含两个字段: 1. 字符串部门名称和 2. 列出员工名单 Employee 类及其访问器也包含两个字段: 1. 字符串名称和 2. 字符串信息。
该页面的 jspx 代码如下:
<?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="Page.jspx" id="d1">
<af:form id="f1">
<af:panelStretchLayout id="psl1">
<f:facet name="center">
<af:panelGroupLayout id="pgl2">
<af:selectOneChoice label="Department" value="#{college.selectedDepartment}" id="soc1"
unselectedLabel="" autoSubmit="true" immediate="true"
valueChangeListener="#{college.departmentDropDrownValueChangeListener}">
<f:selectItems value="#{college.departmentDropDownMenu}" id="si1"/>
</af:selectOneChoice>
<af:panelAccordion id="pa1" discloseNone="true" partialTriggers="soc1" discloseMany="true">
<af:forEach items="#{college.departments}" var="department">
<af:showDetailItem text="#{department.departmentName}" id="sdi1">
<af:forEach items="#{department.employees}" var="employee">
<af:showDetailHeader text="#{employee.name}" disclosed="false" id="sdh1">
<af:outputText value="#{employee.info}" id="ot1"/>
</af:showDetailHeader>
</af:forEach>
</af:showDetailItem>
</af:forEach>
</af:panelAccordion>
</af:panelGroupLayout>
</f:facet>
</af:panelStretchLayout>
</af:form>
</af:document>
</f:view>
</jsp:root>
我想要做的是根据 af:selectOneChoice 的选定值重新排列 af:showDetailItem。
我在图像中展示了问题:
如您所见,第一张图片是页面加载后的正常情况。部门 1 只有一名员工,即员工 1 和部门 4 有两名员工员工 1、员工 2。从下拉列表中选择部门 4 后,部门 3 进入最后一个位置,但在部门 3 面板中显然有两个 af:showDetailItem图片但最初只有一名员工。另外,额外的 af:showDetailItem 不可点击。
如果有人请提出任何建议,这将对我非常有帮助。
谢谢。
I am new in ADF faces and I am facing trouble to partialTrigger a af:panelAccordion on the value change of a af:selectOneChoice. The af:panelAccordion contains multiple af:showDetailHeader within its af:showDetailItem. All the af:showDetailItem and their af:showDetailHeader are generated dynamically.
The bean college is in view scope and its code is given below:
public class College {
private List<Department> departments;
private List<SelectItem> departmentDropDownMenu;
private String selectedDepartment;
public College() {
this.departments = new ArrayList<Department>(0);
Employee employee1 = new Employee("Employee 1", "Information");
Employee employee2 = new Employee("Employee 2", "Information");
Employee employee3 = new Employee("Employee 3", "Information");
Employee employee4 = new Employee("Employee 4", "Information");
Employee employee5 = new Employee("Employee 5", "Information");
List<Employee> employees1 = new ArrayList<Employee>(0);
employees1.add(employee1);
List<Employee> employees2 = new ArrayList<Employee>(0);
employees2.add(employee2);
List<Employee> employees3 = new ArrayList<Employee>(0);
employees3.add(employee3);
List<Employee> employees4 = new ArrayList<Employee>(0);
employees4.add(employee4);
employees4.add(employee5);
Department department1 = new Department("Department 1", employees1);
Department department2 = new Department("Department 2", employees2);
Department department3 = new Department("Department 3", employees3);
Department department4 = new Department("Department 4", employees4);
this.departments.add(department1);
this.departments.add(department2);
this.departments.add(department3);
this.departments.add(department4);
List<SelectItem> departmentDropDownMenu = new ArrayList<SelectItem>(0);
departmentDropDownMenu.add(new SelectItem("Department 1"));
departmentDropDownMenu.add(new SelectItem("Department 2"));
departmentDropDownMenu.add(new SelectItem("Department 3"));
departmentDropDownMenu.add(new SelectItem("Department 4"));
this.setDepartmentDropDownMenu(departmentDropDownMenu);
this.setSelectedDepartment("Department 1");
}
public void departmentDropDrownValueChangeListener(ValueChangeEvent event) {
String oldValue = event.getOldValue().toString();
String newValue = event.getNewValue().toString();
if(oldValue.equalsIgnoreCase(newValue)) {
return;
}
List<Department> departmentUpdated = new ArrayList<Department>(0);
for (Department department : departments) {
if(department.getDepartmentName().equals(newValue)) {
departmentUpdated.add(department);
break;
}
}
for (Department department : departments) {
if(!department.getDepartmentName().equals(newValue)) {
departmentUpdated.add(department);
}
}
this.setDepartments(departmentUpdated);
}
public void setDepartments(List<Department> departments) {
this.departments = departments;
}
public List<Department> getDepartments() {
return departments;
}
public void setDepartmentDropDownMenu(List<SelectItem> departmentDropDownMenu) {
this.departmentDropDownMenu = departmentDropDownMenu;
}
public List<SelectItem> getDepartmentDropDownMenu() {
return departmentDropDownMenu;
}
public void setSelectedDepartment(String selectedDepartment) {
this.selectedDepartment = selectedDepartment;
}
public String getSelectedDepartment() {
return selectedDepartment;
}
}
The Department and Employee classes are simple POJO. The Department class contains only two fields:
1. String departmentName and
2. List employees
with their accessors also the Employee class contains two fields:
1. String name and
2. String info.
The jspx code of the page is given below:
<?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="Page.jspx" id="d1">
<af:form id="f1">
<af:panelStretchLayout id="psl1">
<f:facet name="center">
<af:panelGroupLayout id="pgl2">
<af:selectOneChoice label="Department" value="#{college.selectedDepartment}" id="soc1"
unselectedLabel="" autoSubmit="true" immediate="true"
valueChangeListener="#{college.departmentDropDrownValueChangeListener}">
<f:selectItems value="#{college.departmentDropDownMenu}" id="si1"/>
</af:selectOneChoice>
<af:panelAccordion id="pa1" discloseNone="true" partialTriggers="soc1" discloseMany="true">
<af:forEach items="#{college.departments}" var="department">
<af:showDetailItem text="#{department.departmentName}" id="sdi1">
<af:forEach items="#{department.employees}" var="employee">
<af:showDetailHeader text="#{employee.name}" disclosed="false" id="sdh1">
<af:outputText value="#{employee.info}" id="ot1"/>
</af:showDetailHeader>
</af:forEach>
</af:showDetailItem>
</af:forEach>
</af:panelAccordion>
</af:panelGroupLayout>
</f:facet>
</af:panelStretchLayout>
</af:form>
</af:document>
</f:view>
</jsp:root>
What I want to do is to rearrange the af:showDetailItem depending on selected value of the af:selectOneChoice.
I am showing the problem in the images:
As you can see the first image is the normal condition after page load. Department 1 has only one employee viz, Employee 1 and Department 4 has two employees Employee 1, Employee 2. After selecting Department 4 from the dropdown, Department 3 goes into last position but there in Department 3 panel has apparently two af:showDetailItem in the picture but originally it has only one employee. Also that extra af:showDetailItem is not clickable.
If any one please give any suggestion it will be very helpful to me.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题在于使用
。根据 标签文档:您可以使用
标记来代替 JDev 会抱怨它不是
的有效子级,但它确实有效。这个页面布局似乎有效。请注意,我将
移至顶部面并转储
以强制手风琴拉伸并制作所有的孩子都可见。希望这有帮助。欢迎 ADF 的混乱。 :)
The problem is in using
<af:forEach/>
. According to the tag documentation:You can use an
<af:iterator/>
tag instead. JDev will complain that it isn't a valid child of<af:panelAccordion/>
, but it does work.This page layout seems to work. Note, I moved the
<af:selectOneChoice/>
to the top facet and dumped the<af:panelGroupLayout/>
to force the accordion to stretch and make all the children visible.Hope this helps. Welcome the confusion that is ADF. :)