0

我已经看到了这个问题。请参阅我的 jsf 页面。

<h:form id="companyList">
            <p:contextMenu for="companiesDB" style="height:53px;">
                <p:menuitem value=" edit" update="panelGrid" icon="ui-icon-pencil" oncomplete="editCompany.show()" />

                <p:menuitem value=" delete" update="panelGrid" icon="ui-icon-closethick" onclick="editCompany.show()" />
            </p:contextMenu>

            <p:dataTable id="companiesDB" var="companies"
                value="#{companyController.companyList}" rowKey="#{companies.pkId}"
                selection="#{companyController.selectedCompany}"
                selectionMode="single" paginator="true"
                paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                rows="20" >
                <p:column headerText="name">
                    #{companies.companyName}
                </p:column>
                <p:column headerText="desc">
                    #{companies.description}
                </p:column>
            </p:dataTable>

            <p:dialog header="edit mode" widgetVar="editCompany"
                modal="true" height="160" width="390"
                id="dialog" resizable="false">

                <p:panelGrid cellpadding="10" id="panelGrid" >
                    <p:row>
                        <p:column width="300">
                            <h:outputText value="name:" style="float:left;" />
                        </p:column>
                        <p:column>
                            <p:inputText   value="#{companyController.selectedCompany.companyName}"/>
                        </p:column>
                    </p:row>
                    <p:row>
                        <p:column>
                            <h:outputText value="desc:" style="float:right;" />
                        </p:column>
                        <p:column>
                            <p:inputText  
                                value="#{companyController.selectedCompany.description}" />
                        </p:column>
                    </p:row>

                </p:panelGrid>

                <br />
                <br />
                <p:commandButton value="save" icon="ui-icon-check"
                    style="float:right; margin-right:25px;" update="companiesDB"
                    oncomplete="addCompany.hide();"
                    action="#{companyController.insertCompany()}">
                </p:commandButton>
            </p:dialog>
 </h:form>

控制台错误是:/company.xhtml @46,91 value="#{companyController.selectedCompany.companyName}": Target Unreachable, 'selectedCompany' 返回 null

4

1 回答 1

1

尝试将您的对话ID重命名为mydialog(只是为了安全起见)

并按如下方式更新您的菜单项条目(注意update="mydialog"):

<p:menuitem value="edit" update="mydialog" icon="ui-icon-pencil" oncomplete="editCompany.show()" />

另外,请确保仅在表中进行选择后才启用编辑按钮...否则您将获得空指针...

你可以用类似的东西来实现它

<p:menuitem value="edit" disabled=#{companyController.selectedCompany eq null}.....

p:ajax并在您的表中添加两个

<p:dataTable.......>
    <p:ajax event="rowSelect" update="contextMenuID" />
    <p:ajax event="rowUnselect" update="contextMenuID" />

最后一件事:添加id=contextMenuID到您的上下文菜单

于 2012-07-05T05:45:16.393 回答