-3

嗨,想创建一个包含序列号的列的数据表,并且我正在通过在按钮单击时添加行来使数据列动态化,我需要生成一个序列号,我为这种情况做些什么聊天,

我的jsf页面

<rich:dataTable value="#{section2Bean.employeeList}"
                            var="emp" style="width:100%;">
                            <h:column>
                                <f:facet name="header">
                               #{msg.lbl_serialNo}
                            </f:facet>
                                <h:outputText value="#{TnwrdBean.hrmsBean.hrmsSection9.serialNo}" />
                            </h:column>
                            <h:column>
                            <f:facet name="header">
                                 #{msg.lbl_addRow}
                             </f:facet>
                                <div class="buttons">
                                <p align="center">
                                <h:commandButton id="addEduQualRow" type="submit" actionListener="#{section2Bean.addNewEmployee}"
                                value="+" />
                                </p>
                                </div>
                            </h:column>
                        </rich:dataTable>

Section2Bean.java

public class Section2Bean  extends BaseAction implements Serializable {
    private static final long serialVersionUID = 32423545435345L;
List<Employee> employeeList;
List<Employee> employeetrainingList;
private boolean checkSelected;

public List<Employee> getEmployeeList() {
    return employeeList;
}

public void setEmployeeList(List<Employee> employeeList) {
    this.employeeList = employeeList;
}

public void addNewEmployee(ActionEvent event) {
    employeeList.add(new Employee(employeeList.size(), null));
    System.out.println(employeeList);
    for(int i = 1;i<=employeeList.size();i++){
    }
}

public void deleteNewEmployee(ActionEvent event){
    employeeList.remove(employeeList.hashCode());
}
@PostConstruct
public void init() {
    employeeList = new ArrayList<Employee>();
    employeetrainingList =new ArrayList<Employee>();
    employeeList.add(new Employee(1, ""));
}

public Section2Bean() {
}

public boolean isCheckSelected() {
    return checkSelected;
}

public void setCheckSelected(boolean checkSelected) {
    this.checkSelected = checkSelected;
}
}
4

2 回答 2

0

你的数据表

<h:column rendered="#{section2Bean.showSerials}">
    #{section2Bean.getSerial(emp)}
</h:column>

你的豆子

import java.util.UUID;

private Map<Employee, String> serials;
private boolean showSerials;
// getter

@PostConstruct 
public void init() {
    serials = new HashMap<>();
    for(Employee employee : ...) {
        serials.put(employee, newSerial());
    }
}

public String getSerial(Employee employee) {
    return serials.get(employee);
}

public void buttonClick(ActionEvent event) {
    // other logic?
    showSerials = true;
}

private String newSerial() {
    return UUID.randomUUID().toString();
}
于 2013-05-31T06:07:55.260 回答
0

在 bean 中声明一个新字段来保存序列号。当您使用 bean 的实例填充 List 时,每次都给它一个递增的值。所以在你的jsf中,你可以直接访问序列号属性。

于 2013-05-31T06:19:33.043 回答