可编辑的DataTable + NoRowAvailableException

时间:2014-05-05 04:56:50

标签: java jsf javabeans getmethod

我得到了这个javax.faces.model.NoRowAvailableException,我想它与bean范围或元数据id属性有关。当我提交行的修改时会抛出异常(p:rowEditor' s check button)。

jsf页面:

<?xml version='1.0' encoding='UTF-8' ?>
<!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:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:p="http://primefaces.org/ui">
    <f:metadata>
        <f:viewParam name="id" value="#{definitionsFacelet.id}"/>
        <f:event type="preRenderView" listener="#{definitionsFacelet.init}" />
    </f:metadata>
    <h:head>
    <title>#{definitionsFacelet.plan.name}</title>
    </h:head>
    <h:body>
        <h1><h:outputText value="#{definitionsFacelet.plan.name}"/></h1>
        <f:view>
            <h:form>
                <h:messages class="errorMessage" id="defsMessages" />
                <p:dataTable value="#{definitionsFacelet.plan.definitions}" var="item" editable="true">
                    <p:ajax event="rowEdit" listener="#{definitionsFacelet.onEditDefinition}" update="@form:defsMessages" />
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="Resource"/>
                        </f:facet>
                        <h:outputText value="#{item.resource.name}"/>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="Value"/>
                        </f:facet>
                        <p:cellEditor>
                            <f:facet name="output">  
                                <h:outputText value="#{item.value}"/>
                            </f:facet>
                            <f:facet name="input">  
                                <h:inputText value="#{item.value}"/>
                            </f:facet>
                        </p:cellEditor>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="Price"/>
                        </f:facet>
                        <p:cellEditor>
                            <f:facet name="output">  
                                <h:outputText value="#{item.price}"/>
                            </f:facet>
                            <f:facet name="input">  
                                <h:inputText value="#{item.price}"/>
                            </f:facet>
                        </p:cellEditor>
                    </p:column>
                    <p:column width="6%">
                        <f:facet name="header">
                            <h:outputText value="Edit"/>
                        </f:facet>
                        <p:rowEditor/>
                    </p:column>
                </p:dataTable>
            </h:form>
        </f:view>
    </h:body>
</html>

和托管bean:

/**
 *
 * @author oliver
 */
package XXX;

import java.io.Serializable;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
import XXX.DefinitionsControlInterface;
import XXX.PlansControlInterface;
import net.elegit.store.model.Plan;
import org.primefaces.event.RowEditEvent;

@ManagedBean
@RequestScoped
public class DefinitionsFacelet implements Serializable {

@EJB
DefinitionsControlInterface definitionsBean;

@EJB
PlansControlInterface planBean;

@ManagedProperty("#{param.id}")
private int id;

private Plan plan;

public void init(){
    System.out.println("ID: "+id);
    plan = planBean.get(id);
}

public String onEditDefinition(RowEditEvent event) {
    return null;
}

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

public Plan getPlan() {
    return plan;
}

public void setPlan(Plan plan) {
    this.plan = plan;
}

}

这个问题似乎是Jsf DataModel vs Java List problem ( no row available exception )上的问题,但只有那里的回答没有帮助我。

祝你好运, 奥利弗

0 个答案:

没有答案