【问题标题】:p:ajax listener doesn't work in primefacesp:ajax 监听器在 primefaces 中不起作用
【发布时间】:2013-12-22 22:52:00
【问题描述】:

我想将项目拖放到仪表板中。我可以使用可拖动的 outputLabel 组件,但不能将其放入仪表板。在仪表板的可放置标记中,p:ajax 侦听器元素不起作用。我该如何解决?或者我的错误在哪里?谁能帮帮我?

这是我的 bean 函数:

public void f_onCompDrop(DragDropEvent ddEvent) {
        FacesContext fc = FacesContext.getCurrentInstance();
        Application application = fc.getApplication();
        dashboard = (Dashboard) application.createComponent(fc, "org.primefaces.component.Dashboard",
                "org.primefaces.component.DashboardRenderer");
        UIComponent comp = ddEvent.getComponent().findComponent(ddEvent.getDragId()); 
        dashboard.setId(ddEvent.getDropId());
        getDashboardComponents();
        DashboardModel model = new DefaultDashboardModel();
        for (int i = 0; i < 3; i++) {
            DashboardColumn column = new DefaultDashboardColumn();
            model.addColumn(column);

        }
        dashboard.setModel(model); 
        if (comp.getId().startsWith("out", 0)) { 
            OutputTextBean out = new OutputTextBean();
            OutputLabel outputLbl = new OutputLabel();
            outputLbl.setId("out_" + out.getID());
            outputLbl.setValue("Dragged");
            model.getColumn(0).addWidget(outputLbl.getId());
        }

        components.add(comp);
    }

这是我的 xhtml 文件:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui">

    <f:view contentType="text/html">
        <h:head>
            <style type="text/css">
                .ui-widget {
                    font-size: 75%;
                }
                .ui-layout-west {
                    z-index:20 !important;
                    overflow:visible;
                }
                .ui-layout-west .ui-layout-unit-content {
                    overflow:visible;
                }
            </style>
        </h:head>

        <h:body>
            <p:layout fullPage="true">

                <p:layoutUnit id="top" position="north" header="menu" size="100">
                </p:layoutUnit>

                <p:layoutUnit id="bottom" position="south" header="properties" size="100">
                </p:layoutUnit>

                <p:layoutUnit id="left" position="west" header="toolbox" size="200" >
                    <p:outputLabel id="out_1" value="outputlabel"/>
                    <p:draggable for="out_1" helper="clone"/>
                </p:layoutUnit>

                <p:layoutUnit id="middle" position="center" >
                    <p:tabView>
                        <p:tab title="Page 1">
                            <p:dashboard id="dashboard" binding="#{myBean.dashboard}" style="width: 600px; height: 600px;">
                            </p:dashboard>

                            <p:droppable for="dashboard" >
                                <p:ajax listener="#{myBean.f_onCompDrop}" update="dashboard"/>
                            </p:droppable>
                        </p:tab>
                    </p:tabView>
                </p:layoutUnit>

            </p:layout>
        </h:body>
    </f:view>
</html>

【问题讨论】:

  • p:ajax 应该在表单中。

标签: ajax jsf jsf-2 primefaces


【解决方案1】:

错误是您忘记了表格。在正文的开始标签后添加&lt;h:form&gt;,在正文的结束标签前添加&lt;/h:form&gt;。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-08
    相关资源
    最近更新 更多