如何创建一个表格作为矩阵与曲面(3D表以某种方式)?

时间:2014-04-03 13:54:40

标签: java jsf-2 primefaces

我找到了同样的问题Here,我尝试为我的项目做同样的事情,但我无法得到结果,任何人都可以检查下面的代码并告诉我在哪里制作一个失误。 我想要做的是获得一个表格,其中列是飞机,行是每架飞机的工作包,单元格是每架飞机每个工作包中的工作。 XHTML是:

<h:form id="globalreport">
  <p:layout>
   <p:layoutUnit position="north">
 <p:selectOneMenu id="model" value="#{userInterfaceMB.model}">
   <f:selectItem itemLabel="All models" itemValue="" />
   <f:selectItems value="#{userInterfaceMB.getAllAvailableModels()}" />
   <p:ajax update="aircraftTable"listener="#{userInterfaceMB.handleModelChange()}" />
 </p:selectOneMenu>
   </p:layoutUnit>

<p:layoutUnit position="center">
<p:dataTable id="aircraftTable" var="workPackageId" 
             value="# {userInterfaceMB.workPackagesIds}" rowIndexVar="rowIdx">
           <p:column headerText="" styleClass="ui-widget-header">
                <h:outputText value="#{workPackageId}" />
                 </p:column>
                <p:columns var="aircraftId" value="#  
                                               {userInterfaceMB.aircraftsIds}"
                         headerText="#{aircraftId}"   
                                                 columnIndexVar="colIdx">
        <ui:repeat value="#{userInterfaceMB.myJobs[rowIdx][colIdx]}"  
                               var="myJob">
                         <p:panel>
                <h:outputText value="#{myJob}" />
             </p:panel>
        </ui:repeat>
    </p:columns
</p:dataTable>
</p:layoutUnit> 
</p:layout>
</h:form>
</h:body>

这是我的ManagedBean:

@ManagedBean(name="userInterfaceMB")
@SessionScoped
@ComponentScan("com.")
public class UserInterfaceBean implements Serializable{

    private static final long serialVersionUID = 1L;

    //TODO Autowired is not working, get it to work
    @Autowired
    private DBDataManipulatorService dbDataManipulatorService;

    private int aircraftId;
    private String type;
    private String model;
    private List<String> workPackagesIds;
    private List<Integer> aircraftsIds;
    private ArrayList<ArrayList<ArrayList<MyJob>>> myJobs;
    private List<Aircraft> aircrafts; 


    public ArrayList<ArrayList<ArrayList<MyJob>>> getMyJobs() {
        return myJobs;
    }

    public void setMyJobs(ArrayList<ArrayList<ArrayList<MyJob>>> myJobs) {
        this.myJobs = myJobs;
    }

    public List<Integer> getAircraftsIds() {
        return aircraftsIds;
    }

    public void setAircraftsIds(List<Integer> aircraftsIDs) {
        this.aircraftsIds = aircraftsIDs;
    }

    public UserInterfaceBean(){
        //Because the Autowire is not working
        WebApplicationContext ctx =  
                FacesContextUtils.getWebApplicationContext(FacesContext.getCurrentInstance());
        dbDataManipulatorService = ctx.getBean(DBDataManipulatorService.class);

    }

    @PostConstruct
    public void Init() {

        aircrafts = new ArrayList<Aircraft>();
        aircrafts = dbDataManipulatorService.findAllAircrafts();

    }

    public List<Aircraft> getAircrafts() {
        if(aircrafts==null){
            aircrafts = dbDataManipulatorService.findAllAircrafts();
        }

        return aircrafts;
    }

    public void setAircrafts(List<Aircraft> aircrafts) {
        this.aircrafts = aircrafts;
    }

    public DBDataManipulatorService getDBDataManipulatorService() {

        return dbDataManipulatorService;
    }

    public void setDBDataManipulatorService(DBDataManipulatorService   
                                                dbDataManipulatorService) {

    }

    public int getAircraftId() {
        return aircraftId;
    }

    public String getType() {
        return type;
    }

    public String getModel() {
        return model;
    }


    public List<String> getWorkPackagesIds() {
        return workPackagesIds;
    }



    public void setAircraftId(int aircraftId) {
        this.aircraftId = aircraftId;
    }


    public void setType(String type) {
        this.type = type;
    }


    public void setModel(String model) {
        this.model = model;
    }


    public void setWorkPackagesIds(List<String> workPackageIds) {
        this.workPackagesIds = workPackageIds;
    }

    public List<String> getAllAvailableModels(){

        return  dbDataManipulatorService.findAllAvailableAircraftsModels();
    }

    public void handleModelChange(){

        List<Aircraft> aircrafts =   
                               dbDataManipulatorService.findAllAircraftsByModel(model);

        setAircrafts(aircrafts); 
        List<Integer> aircraftsIds = new ArrayList<Integer>(); 

        for(Aircraft aircraft:aircrafts){

            int aircraftId = aircraft.getAircraftId();
            aircraftsIds.add(aircraftId);               
        }
        setAircraftsIds(aircraftsIds);
        getDistinctWorkPackageId(model);
        updateMyJobs();
    }

    public List<WorkPackage> getAllAvailableWorkPackesByAircraftModel(String model){

        List<WorkPackage> workpackages = new ArrayList<WorkPackage>();

        workpackages = dbDataManipulatorService.getWorkPackagesByAircraftModel(model);

        return workpackages;
    }

    public void getDistinctWorkPackageId(String model){

        List<String> workPackagesIds = new ArrayList<String>();
        List<WorkPackage> workPackages = 
                                  getAllAvailableWorkPackesByAircraftModel(model);

        for(WorkPackage workPackage: workPackages){

            String workPackageId = workPackage.getWorkPackageId();

            if (!workPackagesIds.contains(workPackageId)){

                workPackagesIds.add(workPackageId);
            }       
        }
        setWorkPackagesIds(workPackagesIds);
    }

    public void updateMyJobs(){
        ArrayList<ArrayList<ArrayList<MyJob>>> myJobs = 
                                                 new ArrayList<ArrayList<ArrayList<MyJob>>>();

                Map<Integer, Aircraft> aircraftsMap = getAircraftsMap();

        int aircraftId = 0;
        String workPackageId = null;

        for (int i = 0; i < aircraftsIds.size(); i++) {

            aircraftId = aircraftsIds.get(i);

            if (aircraftsMap.containsKey(aircraftId)){

                Aircraft aircraft = aircraftsMap.get(aircraftId);

                Map<String, WorkPackage> workPackagesMap = 
                                                         aircraft.getWorkPackagesMap();

                for(int j=0; j<workPackagesIds.size();j++){

                    workPackageId = workPackagesIds.get(j);

                    if(workPackagesMap.containsKey(workPackageId)){

                        WorkPackage workPackage = 
                                                          workPackagesMap.get(workPackageId);

                        List<MyJob> jobsMap = 
                                               (List<MyJob>)workPackage.getJobsMap().values();                      

                        for(MyJob myJob:jobsMap){

                            myJobs.get(i).get(j).add(myJob);
                        }
                    }
                }

            }
        }

        setMyJobs(myJobs);
    }


    private  Map<Integer, Aircraft> getAircraftsMap(){

        Map<Integer, Aircraft> aircraftsMap = new HashMap<Integer, Aircraft>();

        for(Aircraft aircraft: aircrafts){

            aircraftsMap.put(aircraft.getAircraftId(), aircraft);
        }

        return aircraftsMap;

    }

}

请非常感谢您的快速帮助。我想要的是:

+--------------+--------------------------+--------------------------+-------------+------
|              |  Aircraft1               |  Aircraft2               |  ...... ....
+--------------+--------------------------+--------------------------+-------------+------
|              | +-------+----------+     | +-------+----------+     |
|              | |jobId1 |jobstatus |     | |jobId1 |jobstatus |     |  
|              | +-------+----------+     | +-------+----------+     |
| Workpackage1 | |jobId2 |jobstatus |     | |jobId2 |jobstatus |     |
|              | +-------+----------+     | +-------+----------+     |
|              | |jobId3 |jobstatus |     |                          |
|              | +-------+----------+     |                          |
+--------------+--------------------------+--------------------------+-------------------
|              | +-------+----------+     | +-------+----------+     |
|              | |jobId1 |jobstatus |     | |jobId1 |jobstatus |     |  
|              | +-------+----------+     | +-------+----------+     |
| Workpackage2 |                          | |jobId2 |jobstatus |     |
|              | +-------+----------+     | +-------+----------+     |
|              | |jobId3 |jobstatus |     |                          |
|              | +-------+----------+     |                          |
+--------------+--------------------------+--------------------------+-------------------
  ....

0 个答案:

没有答案