我正在尝试使用数据网格(代表任务状态)中的面板(带有任务信息)创建任务板,其中一个面板可以从数据网格拖动并放入另一个面板。当我运行应用程序时,这仅在我第一次拖动面板并放入其他数据网格时才起作用,第二次尝试此操作时,面板不会绑定到目标数据网格。如果我刷新页面并再次尝试,面板将绑定到目标数据网格,但服务器显示javax.faces.model.NoRowAvailableException。为什么我得到这个例外?这是代码:
home.xhtml:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head></h:head>
<h:body>
<h:form id="form">
<h:inputText id="newTaskName" />
<h:inputText id="newTaskDescription" />
<p:selectOneListbox id="newTaskState"
value="#{taskView.newTaskState}">
<f:selectItem itemLabel="TODO" itemValue="1" />
<f:selectItem itemLabel="DOING" itemValue="2" />
<f:selectItem itemLabel="DONE" itemValue="3" />
</p:selectOneListbox>
<h:commandButton action="#{taskView.addNewTask}" value="+"
update="dash" />
<div id="dash">
<p:fieldset id="fieldTasksTodo" legend="TODO">
<p:dataGrid id="dataGridTasksTodo" var="task"
value="#{taskView.allTodoTasks}" columns="1">
<p:panel id="task" header="#{task.name}">
<h:outputText value="#{task.description}" />
</p:panel>
<p:draggable for="task" revert="true" />
</p:dataGrid>
</p:fieldset>
<p:droppable for="fieldTasksTodo" datasource="dataGridTasksTodo">
<p:ajax listener="#{taskView.onTaskDropTodo}"
update="fieldTasksTodo fieldTasksDoing fieldTasksDone" />
</p:droppable>
<p:fieldset id="fieldTasksDoing" legend="DOING">
<p:dataGrid id="dataGridTasksDoing" var="task"
value="#{taskView.allDoingTasks}" columns="1">
<p:panel id="task" header="#{task.name}">
<h:outputText value="#{task.description}" />
</p:panel>
<p:draggable for="task" revert="true" />
</p:dataGrid>
</p:fieldset>
<p:droppable for="fieldTasksDoing" datasource="dataGridTasksTodo">
<p:ajax listener="#{taskView.onTaskDropDoing}"
update="fieldTasksTodo fieldTasksDoing fieldTasksDone" />
</p:droppable>
<p:fieldset id="fieldTasksDone" legend="DONE">
<p:dataGrid id="dataGridTasksDone" var="task"
value="#{taskView.allDoneTasks}" columns="1">
<p:panel id="task" header="#{task.name}">
<h:outputText value="#{task.description}" />
</p:panel>
<p:draggable for="task" revert="true" />
</p:dataGrid>
</p:fieldset>
<p:droppable for="fieldTasksDone" datasource="dataGridTasksTodo">
<p:ajax listener="#{taskView.onTaskDropDone}"
update="fieldTasksTodo fieldTasksDoing fieldTasksDone" />
</p:droppable>
</div>
</h:form>
</h:body>
</html>
TaskView.java(Managed Bean):
package br.com.nutrello.dashboard;
import java.io.Serializable;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import org.primefaces.event.DragDropEvent;
@ManagedBean(name = "taskView")
@ViewScoped
public class TaskView implements Serializable{
/**
*
*/
private static final long serialVersionUID = 8115685123089539229L;
private int newTaskState;
public void init() {
newTaskState = 1;
}
public void addNewTask() {
HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext()
.getRequest();
String newTaskName = request.getParameter("form:newTaskName");
String newTaskDescription = request.getParameter("form:newTaskDescription");
Task newTask = new Task(newTaskName, newTaskDescription);
if (newTaskState == 2) {
TaskRepository.addTaskDoing(newTask);
} else if (newTaskState == 3) {
TaskRepository.addTaskDone(newTask);
} else {
TaskRepository.addTaskTodo(newTask);
}
}
public List<Task> getAllTodoTasks() {
return TaskRepository.getTodoTaskList();
}
public List<Task> getAllDoingTasks() {
return TaskRepository.getDoingTaskList();
}
public List<Task> getAllDoneTasks() {
return TaskRepository.getDoneTaskList();
}
public int getNewTaskState() {
return newTaskState;
}
public void setNewTaskState(int newTaskState) {
this.newTaskState = newTaskState;
}
public void onTaskDropTodo(DragDropEvent ddEvent) {
Task task = ((Task) ddEvent.getData());
TaskRepository.removeTask(task);
TaskRepository.addTaskTodo(task);
}
public void onTaskDropDoing(DragDropEvent ddEvent) {
Task task = ((Task) ddEvent.getData());
TaskRepository.removeTask(task);
TaskRepository.addTaskDoing(task);
}
public void onTaskDropDone(DragDropEvent ddEvent) {
Task task = ((Task) ddEvent.getData());
TaskRepository.removeTask(task);
TaskRepository.addTaskDone(task);
}
}