在ajax更新中动态添加Primefaces Schedule和Schedule事件

时间:2017-07-01 03:45:07

标签: java ajax jsf primefaces bootsfaces

我有一个命令按钮,它接收表单中的所需数据,然后创建DefaultScheduleModel以及任何DefaultScheduleEvents。然后,命令按钮应通过动态创建新选项卡和新计划以及需要创建的任何事件来更新包含TabView的另一个表单。

问题在于,由于某些奇怪的原因,在ajax更新时不会创建新选项卡以及相应的计划/事件。我唯一得到的是一个带有空计划的标签,其中任何后续提交都不会创建任何其他标签/计划/事件。

以下是我的观点:

<h:form>

        <b:panel id="createSchedule" title="Create Schedule-o-matic" >

                <f:facet name="append">
                    <b:commandButton look="danger" value="Delete" ajax="true" actionListener="#{onCallJSFBean.deleteTeamMember(teamMember)}" iconAwesome="times" icon-align="right"
                             update="rosterTable"/>
                </f:facet>
                </b:inputText>
            </h:column>
            </h:dataTable>
            <b:commandButton value="Add Team Member" ajax="true" update="createSchedule" actionListener="#{onCallJSFBean.addTeamMember}"/>
            <f:facet name="footer">
            <b:buttonToolbar>
                <b:buttonGroup>
                <b:commandButton id='scheduleCancel' look="danger" ajax="true" value="Close" icon-awesome="window-close" update="createSchedule" 
                         onclick="ajax:onCallJSFBean.cancelSchedule();"
                         oncomplete="$('#j_id_12\\:createSchedule').hide();"/>
                <b:commandButton id='scheduleCreate' look="success" ajax="true" value="Submit" icon-awesome="fa-check"
                         actionListener="#{onCallJSFBean.createSchedule()}" update="@(.scheduleClass)"
                         />
                </b:buttonGroup>
            </b:buttonToolbar>
            </f:facet>

        </b:panel>

            </h:form>
<h:form class="scheduleClass">
            <b:row>
            <p:tabView dynamic="true" value="#{onCallJSFBean.scheduleDOs}" var="scheduleList" scrollable="true">
                <p:tab title="#{scheduleList.scheduleTitle}">
                <h:outputText value="#{scheduleList.startTime} #{scheduleList.endTime} #{scheduleList.scheduleModel.eventCount}"/>

                </p:tab>
            </p:tabView>
            </b:row>
        </h:form>

这是相应的控制器:

//When canceling/closing the schedule creation panel     
public void cancelSchedule(){
        this.createScheduleTitle="";
        this.createScheduleCycleTime = null;
        this.slotStartTimePeriod = null;
        this.slotEndTimePeriod = null;
        this.createScheduleRoster = new ArrayList<>();
        System.err.println(scheduleDOs.size());
}

        public void createSchedule(){


        if(submitFail == true){
            this.scheduleDOs.add(createScheduleData());
            System.err.println(this.scheduleDOs.size()+" Size of tab");
        }

        System.err.println("Finished");
        }

        private ScheduleDO createScheduleData(){
        ScheduleModel scheduleModel = new DefaultScheduleModel();

        if(createScheduleCycleTime == 1){
            populateDailySchedule(scheduleModel);
        }

        ScheduleDO onCall = new ScheduleDO(createScheduleTitle, createScheduleCycleTime, 
            slotStartTimePeriod, slotEndTimePeriod, createScheduleRoster, scheduleModel);

        return onCall;
        }

        private int rosterCounter = 0;
        private String nextTeamMember(List<SimpleStringWrapper> roster){
        String tmp;
        if(rosterCounter >= roster.size()){
            rosterCounter=0;
            tmp = roster.get(rosterCounter).getValue();
        }else{
            tmp = roster.get(rosterCounter).getValue();
        }
        rosterCounter+=1;
        return tmp;
        }

        private void populateDailySchedule(ScheduleModel scheduleModel){
        DateTime startDate = DateTime.now();
        Period period = Period.months(6);
        DateTime endDate = startDate.plus(period);
        Days day = Days.daysBetween(startDate, endDate);

        int numDays = day.getDays();

        for(int i = 0;i<numDays;i++){
            MutableDateTime startTime = new MutableDateTime(startDate.plusDays(i));
            startTime.setHourOfDay(this.slotStartTimePeriod);
            MutableDateTime endTime = new MutableDateTime(startDate.plusDays(i));
            endTime.setHourOfDay(this.slotEndTimePeriod);

            String teamMember = nextTeamMember(createScheduleRoster);
    //      System.err.println(teamMember+" "+startTime.toDate()+" "+endTime.toDate());
            DefaultScheduleEvent event = new DefaultScheduleEvent(teamMember, startTime.toDate(), endTime.toDate());
            scheduleModel.addEvent(event);
        }
        System.err.println(scheduleModel.getEventCount());
        }

我正在使用Primefaces 6.0和Bootsfaces 1.1.1

1 个答案:

答案 0 :(得分:1)

我意识到我的错误一直是我更新tabview / schedule的方式,而不是有两个表单和提交命令按钮,目标是第二个表单ID,而是我让提交按钮更新了tabview本身。