データテーブルにある編集ボタンを押すと編集ダイアログが開き、そのダイアログ上でデータを編集してsaveボタンを押すと、編集内容が保存されデータテーブルにも反映されるような機能を実装させようとしています。
しかし、データを編集してsaveボタンを押しても値がnullになってしまいエラーが出てしまいます。
入力値を受け取るロジックはできているのではないかと思っているのですが、自分ではどこが違っていてこうなってしまっているのかがわからないため、ご助言いただきたいです。
よろしくお願いいたします。
※編集ボタンは1つ目の<p:commandButton>になります。
※データテーブルとダイアログはprimefacesを利用しています、フレームワークはspringです。
profile.xhtml
<h:form id="profileForm"> <div class="card"> <p:dataTable var="profile" id="profileDataTable" value="#{profileMBean.profileList}" sortMode="single"> <p:column sortBy="#{profile.id}" headerText="No."> <h:outputText value="#{profile.id}" /> </p:column> <p:column sortBy="#{profile.name}" headerText="名前"> <h:outputText value="#{profile.name}" /> </p:column> <p:column sortBy="#{profile.age}" headerText="年齢"> <h:outputText value="#{profile.age}" /> </p:column> <p:column sortBy="#{profile.updateDate}" headerText="最終更新日"> <h:outputText value="#{profile.updateDate}"> <f:convertDateTime pattern="yyyy/MM/dd HH:mm:ss" /> </h:outputText> </p:column> <p:column exportable="false" headerText="操作"> <p:commandButton icon="pi pi-pencil" oncomplete="PF('manageProductDialog').show()" styleClass="edit-button rounded-button ui-button-success" process="@this" actionListener="#{profileMBean.setSelectedProfile(profile)}" update="profileForm:profileEditDialog"> </p:commandButton> <p:commandButton class="ui-button-warning rounded-button" icon="pi pi-trash" process="@this" oncomplete="PF('deleteProductDialog').show()" actionListener="#{profileMBean.setSelectedProfile(profile)}" > </p:commandButton> </p:column> </p:dataTable> <p:dialog header="編集" showEffect="fade" modal="true" widgetVar="manageProductDialog" responsive="true" id="profileEditDialog"> <p:outputPanel id="manage-product-content" class="ui-fluid"> <div class="p-field"> <p:outputLabel for="name">名前</p:outputLabel> <p:inputText id="name" value="#{profileMBean.selectedProfile.name}"/> </div> <div class="p-formgrid p-grid"> <div class="p-field p-col"> <p:outputLabel for="age">年齢</p:outputLabel> <p:inputText id="age" value="#{profileMBean.selectedProfile.age}" /> </div> </div> </p:outputPanel> <f:facet name="footer"> <p:commandButton value="Save" icon="pi pi-check" action="#{profileMBean.profileEdit()}"/> <p:commandButton value="Cancel" icon="pi pi-times" onclick="PF('manageProductDialog').hide()" class="ui-button-secondary"/> </f:facet> </p:dialog>
Profile.MBean
public String profileEdit() { selectedProfile.setName(name); selectedProfile.setAge(age); profileService.updateProfile(selectedProfile); return "/manage/profile/profile.xhtml?faces-redirect=true"; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getAge() { return age; } public void setAge(String age) { this.age = age; } public Profile getSelectedProfile() { return selectedProfile; } public void setSelectedProfile(Profile selectedProfile) { this.selectedProfile = selectedProfile; }