次のような問題があります。
問題なくロールを追加できますが、削除または編集する必要がある場合、roleController.selectedRoleがnullであるため機能しません。最初はマネージド Bean を requestScope として持っていましたが、すべてのリクエストで Bean が再作成されるため、null がそこから来ている可能性があります。そのため、ViewScoped に変更して追加ボタンが再び機能するように修正しましたが、それでも編集と削除で同じ問題が発生します。
何が起こっているかは次のとおりです。行を選択し、編集ボタンをクリックします。これにより、ロール情報を含むダイアログが正しく表示されます。しかし、編集をクリックすると、null 値が表示されます。私はいくつかの例を見てきましたが、私は何も悪いことをしていないようです。しかし、私は本当に基本的な何かが欠けているかもしれません:/
どんな洞察も大歓迎です!
Beanに関しては、次のものがあります。
@ManagedBean
@RequestScoped
....
private Roles selectedRole = new Roles();
(I have the normal setter and getter)
public void edit() {
Logger.getGlobal().log(Level.INFO, "====> EDIT ROLE" + selectedRole.getRole());
}
ページは ui:define とヘッダーのことを省略して次のようになります。
<h:form id="contentView">
<p:dataTable id="lstRoles" var="r" value="#{roleController.rolesList}" selectionMode="single"
selection="#{roleController.selectedRole}" rowKey="#{r.role}" paginator="true"
paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {CurrentPageReport} {RowsPerPageDropdown}"
rowsPerPageTemplate="10,15,50" rows="10">
<p:column headerText="Role" sortBy="#{r.role}">
<p:outputLabel value="#{r.role}"></p:outputLabel>
</p:column>
<p:column headerText="Description">
<h:outputLabel value="#{r.description}"></h:outputLabel>
</p:column>
<f:facet name="footer">
<p:commandButton value="New" icon="ui-icon-star" oncomplete="newRoleDialog.show()"></p:commandButton>
<p:commandButton value="Edit" icon="ui-icon-check" oncomplete="editRoleDialog.show()" update=":editRoleForm:editRolePanel"></p:commandButton>
<p:commandButton value="Delete" icon="ui-icon-trash"></p:commandButton>
</f:facet>
</p:dataTable>
<p:blockUI block="lstRoles" trigger="lstRoles">
LOADING
</p:blockUI>
</h:form>
<!-- Edit User -->
<p:dialog header="Edit User" widgetVar="editRoleDialog" resizable="false">
<h:form id="editRoleForm">
<p:panelGrid id="editRolePanel" columns="2">
<h:outputText value="Role: "></h:outputText>
<h:outputText value="#{roleController.selectedRole.role}"></h:outputText>
<h:outputText value="Description: "></h:outputText>
<p:inputText value="#{roleController.selectedRole.description}" required="true"></p:inputText>
<f:facet name="footer">
<p:commandButton value="Confirm" update=":contentView:lstRoles :growl" oncomplete="handleSubmitRequest(xhr, status, args, 'editRoleDialog','editRoleForm');" actionListener="#{roleController.edit()}"></p:commandButton>
<p:commandButton type="reset" value="reset"></p:commandButton>
</f:facet>
</p:panelGrid>
</h:form>
</p:dialog>
編集:私はプライムフェイス3.5でGlassfish 3.1を使用しています
編集 2:だから、私は出力ラベルを使用できないようです。入力に変更すると、マネージド Bean で必要な値を取得します (行を選択するときに既に処理されていると思いますが、セッターを呼び出すためだと思います)。しかし、これは PK キーであり、テーブルでは FK としても使用されるため、最初のフィールドは編集したくありません。しかし、少なくとも何が起こっているか、多かれ少なかれ知っていることを知っています。