使用ui:include时,DragDrop对象为null

时间:2012-10-04 19:43:24

标签: java jsf-2 drag-and-drop richfaces

我在Richfaces4和JSF2中使用拖放组件。

当我将Action(第一个面板)拖放到目标面板中时,一切正常。但是当我尝试将对象(第二个面板)拖放到目标面板时。我得到以下异常:

异常

debug[16:27:48.572]: Server returned responseText: <?xml version='1.0' encoding='UTF-8'?> <partial-response><error><error-name>class java.lang.NullPointerException</error-name><error-message><![CDATA[]]></error-message></error></partial-response>
info [16:27:48.574]: Element error
<error><error-name>class java.lang.NullPointerException</error-name><error-message><![CDATA[]]></error-message></error>
debug[16:27:48.574]: richfaces.queue: ajax submit error
debug[16:27:48.575]: richfaces.queue: Nothing to submit
error[16:27:48.576]: Received 'error@serverError' event from <div id=dropForm:list:0:j_idt42 class=rf-ind-drag ui-draggable ...>
error[16:27:48.577]: [200] class java.lang.NullPointerException:

消息面板                                                                                                                    

<rich:panel id="Object">

    <h:dataTable value="#{dropBean.objects}" var="object">
        <h:column>
        <a4j:outputPanel layout="block">
             <rich:dragSource type="#{dropBean.objectType}" dragValue="#{object}" />
             <h:outputText value="#{object}"></h:outputText>
        </a4j:outputPanel>
        </h:column>
        </h:dataTable>
</rich:panel>

TARGET PANEL 1

<h:panelGrid columns="4">
    <rich:panel styleClass="idPanel" >
    <rich:panel>
    <rich:dropTarget acceptedTypes="ACTION" dropListener="#{dropBean.processDrop}" render="editPanel" />
    <rich:tooltip value="Drop here an Action..." />
    <a4j:outputPanel>
    <h:outputText value="#{dropBean.currentLine.action}"></h:outputText>
        </a4j:outputPanel>
    </rich:panel>
    <ui:include src="#{dropBean.pageByAction}" />
    <a4j:commandButton styleClass="opButtons" value="Add Step" action="#{dropBean.saveLine}" render="editPanel" />
</h:panelGrid>

<ui:include src="#{dropBean.pageByAction}" />根据我在第一个目标面板中删除的操作获取正确的页面。

以下是包含页面(目标面板2)的示例:

TARGET PANEL 2

<h:panelGrid columns="3">
     <rich:panel styleClass="itemPanel" bodyClass="itemPanelBody">
     <rich:dropTarget acceptedTypes="OBJECT" dropListener="#{dropBean.processDrop}" render="@form" />
     <rich:tooltip value="Drop here an Object..." />
     <a4j:outputPanel>
     <h:outputText value="#{dropBean.currentLine.object}" />
     </a4j:outputPanel>
     </rich:panel>
</h:panelGrid>

如果我删除<ui:include src="#{dropBean.pageByAction}" />并直接插入代码,则drop操作正常。但通过这种方式,面板不是动态的。我需要根据我选择的动作生成面板。

我尝试过的其他事情并没有起作用:

  1. 插入render =“@ form”“formName”“@ all”尝试渲染所有页面。
  2. 更改其他组件的数据表,例如rich:list和rich:dataGrid
  3. 在drop target组件中使用immediate。
  4. 提前告诉,

1 个答案:

答案 0 :(得分:0)

我已经解决了强制页面刷新的问题。

将对象拖放到目标面板时调用的Backing bean中的方法。

public void processDrop(DropEvent event) {

    //process event (not relevant code)

    FacesContext context = FacesContext.getCurrentInstance();
    String viewId = context.getViewRoot().getViewId();
    ViewHandler handler = context.getApplication().getViewHandler();
    UIViewRoot root = handler.createView(context, viewId);
    root.setViewId(viewId);
    context.setViewRoot(root);
}

我确信这不是最佳解决方案,我仍然要求更好的解决方案。与此同时,我会坚持下去。

如果有人有更好的解决方案,请告诉我。

相关问题