【问题标题】:Primefaces timeline onchanged executes but does not call method on beanPrimefaces时间线onchanged执行但不调用bean上的方法
【发布时间】:2017-10-29 05:57:08
【问题描述】:

我正在尝试将 primefaces 添加到现有的 Spring/JSF (myfaces) 项目中。我有实际的时间线组件工作(或至少加载正确的数据),但事件侦听器似乎无法正常工作。我尝试了多种配置,但似乎无法解决此问题。

<p:timeline id="timeline1" 
        value="#{timelineView.getModel(searchFacade.dataModel)}" 
        editable="true" eventMargin="10" eventMarginAxis="0" 
        start="#{timelineView.start}" 
        end="#{timelineView.end}" 
        showNavigation="true" showButtonNew="true" 
        axisOnTop="true" stackEvents="false"
        oncomplete="styleEvents();">  

    <p:ajax event="changed" listener="#{timelineView.onEdit()}" oncomplete="restyleTimeline()" />  
</p:timeline>

在上面的代码中,changed 事件被触发,并进行了 AJAX 调用。在浏览器的网络窗格中,我可以看到 AJAX 调用始终指向当前页面的 URL(例如 /mypage.jsf?conversationCode=a - 我显然也在使用 Apache Orchestra)

为更改的事件发送的实际表单数据如下所示:

javax.faces.partial.ajax:true
javax.faces.source:timeline1
javax.faces.partial.execute:timeline1
javax.faces.behavior.event:changed
javax.faces.partial.event:changed
timeline1_eventIdx:0
timeline1_startDate:1498881600000
timeline1_endDate:1510894800000
timeline1_group:<div class='timeline-group'><div class='timeline-row timeline-row-group'>Group One/div><div class='timeline-row timeline-row-sub'>Group One subtitle</div><div class='timeline-row timeline-row-details'>Group One details</div></div>
mainForm:j_id_mt_SUBMIT:1
javax.faces.ViewState: Big hash as usual

奇怪的长组名是因为我将输出组名格式化为更详细的行标题。

后面的bean(导入和包省略):

public class TimelineView<T> implements Serializable {
    private static final long serialVersionUID = 1L;

    TimelineView<T> timelineView;

    public TimelineModel getModel() {
        return timelineView.getModel();
    }
    public TimelineModel getModel(ListDataModel<? extends Row<T>> results) {  
        return timelineView.getModel(results);
    }
    public void setTimelineView(TimelineView<T> timelineView) {
        this.timelineView = timelineView;
    }
    public Date getStart() {  
        return timelineView.getStart();  
    }
    public Date getEnd() {  
        return timelineView.getEnd();  
    }
    public void onEdit(TimelineModificationEvent e) {
        timelineView.onEdit(e);
    }
    public void onSelect(TimelineSelectEvent e) {
        timelineView.onSelect(e);
    }
}

这些方法中的功能和代码无关紧要,因为当我设置断点时,我可以看到永远不会调用 onEdit 方法,当我在时间轴中有选择事件时也不会调用 onSelect 方法。

由于我让 Spring 处理所有 bean,我的配置就是这样,位于 ApplicationContext.xml 文件中:

<bean id="timelineView" class="com.mycompany.projectone.view.timeline.TimelineView" />

我尝试在时间轴周围添加一个表单,没有任何区别,并且还尝试添加 process=":form_id",这导致错误“找不到表达式组件“:form_id””。

作为也适合我需要的替代方案,有谁知道如何将 primefaces 事件发送到要处理的 javascript 函数?例如,如果用户在时间轴中移动项目的开始点和结束点,我想更新显示的开始和结束日期。

我也想改变或拦截删除行为,修改点击删除链接时发生的情况。

任何帮助将不胜感激。谢谢。

编辑


建议的潜在重复既不解决症状也不解决实际解决方案 - 请参阅下面的答案。

【问题讨论】:

标签: spring jsf primefaces primefaces-extensions


【解决方案1】:

好的,所以答案是 Primfaces timeline 组件必须设置一个 widgetVar 才能使 p:ajaxpe:javascript 调用正常工作。非常简单的解决方案,但非常难以找到。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-09-17
    • 2015-01-15
    • 2016-06-14
    • 2015-12-10
    • 2013-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多