Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 通过FacesContext进行部分渲染时获取NullPointerException_Jsf_Jsf 2_Primefaces - Fatal编程技术网

Jsf 通过FacesContext进行部分渲染时获取NullPointerException

Jsf 通过FacesContext进行部分渲染时获取NullPointerException,jsf,jsf-2,primefaces,Jsf,Jsf 2,Primefaces,我有一个奇怪的行为,在使用faces上下文进行页面刷新时,我得到了NPE。 我有一个托管bean,它位于请求范围内。所以想在点击命令按钮后刷新页面。我尝试过“更新”,但它在我的页面中的行为很奇怪。 错误:PartialViewContextImpl$PhaseAwareVisitCallback.visit:java.lang.NullPointerException 这是我的JSF页面: <h:form id="form"> <p:messag

我有一个奇怪的行为,在使用faces上下文进行页面刷新时,我得到了NPE。 我有一个托管bean,它位于请求范围内。所以想在点击命令按钮后刷新页面。我尝试过“更新”,但它在我的页面中的行为很奇怪。 错误:PartialViewContextImpl$PhaseAwareVisitCallback.visit:java.lang.NullPointerException

这是我的JSF页面:

<h:form id="form">
                <p:messages autoUpdate="true"/>
                <h:panelGrid columns="4" cellpadding="5" id="panelGrid"  rendered="true">
                    <p:outputLabel for="s00" value="#{tk.expense_keyword}"/>
                    <p:inputText id="s00" value="#{expense.form.keyword}"/>
                    <p:outputLabel for="s02" value="#{tk.expense_creatorId}"/>
                    <p:inputText id="s02" value="#{expense.form.creatorId}" disabled="#{!expense.form.canEditCreatorId}"/>
                    <h:outputText id="s10" value="Amount Between #{expense.form.amountFrom} and #{expense.form.amountTo}" />
                    <h:panelGrid>
                        <p:slider for="s11,s12" display="s10" minValue="0" maxValue="1000" style="width: 200px" range="true" displayTemplate="Amount Between {min} and {max}" />
                        <h:inputHidden id="s11" value="#{expense.form.amountFrom}" />
                        <h:inputHidden id="s12" value="#{expense.form.amountTo}" />
                    </h:panelGrid>
                </h:panelGrid>
                <p:commandButton value="#{tk.expense_search}" id="a01" action="#{expense.search}" ajax="false" immediate="true"/>

                <p:dataTable var="line" varStatus="loop" value="#{expense.form.expenseEntryList}" emptyMessage="#{tk.expense_table_empty}" id="dataTable">
                    <p:column headerText="#{tk.expense_table_creatorId}">
                        <h:inputHidden value="#{line.oid}"/>
                        <h:inputText value="#{line.creatorId}"/>
                    </p:column>
                    <f:facet name="footer">
                        <p:commandButton value="#{tk.expense_saveAsDraft}" id="a06" action="#{expense.saveAsDraft}"/>
                        <p:commandButton value="#{tk.expense_submit}" id="a07" action="#{expense.submitAll}"/>
                        <p:commandButton value="#{tk.expense_validate}" id="a08" action="#{expense.validate}"/>
                    </f:facet>
                </p:dataTable>

            </h:form>

我不知道为什么它适用于数据表刷新,但不适用于panelGrid:(

首先,您的bean位于请求范围内,您正在进行完整页面提交,而这里的部分呈现没有任何意义。您得到的错误是因为您有一个组件,它基本上是表单的另一个输入,在提交表单时将发送到当前视图的托管bean。

发布您的完整页面这里是stacktrace。我忍不住注意到,您实际上并没有打印原始stacktrace,而是重新显示了异常。您还想最小化面板网格中的内容,请删除特殊的
render=“true”
,以缩小焦点范围
public Outcome saveAsDraft() throws Exception{

        try {
            saveAsDraftBody(false,false);
            getFacesContext().getPartialViewContext().getRenderIds().add("form:panelGrid");**//**getting error****
            getFacesContext().getPartialViewContext().getRenderIds().add("form:dataTable");**//**works fine****
            Log.info(this,"getFacesContext().getPartialViewContext().getRenderIds(): "+getFacesContext().getPartialViewContext().getRenderIds());
            return Outcome.SUCCESS;
        }
        catch (Throwable e){
            throw manageError(e);
        }

    }