我有一个问题,我有以下几点:JSF primefaces更新对话框不及格的价值豆
我可以添加角色没有问题,但是当我需要删除或修改其不因工作roleController.selectedRole是null。 起初,我将托管的bean作为requestScope,而且我尽管可能会从那里返回null,因为每次请求都会重新创建bean。 所以我更改为ViewScoped修复添加按钮,以再次工作,但我仍然遇到编辑和删除相同的问题。
发生的情况如下:我选择一行并单击按钮编辑。这将正确显示角色信息的对话框。但是当我点击编辑时,我得到空值。 我见过几个例子,看来我没有做错任何事情。但我可能会错过一些非常基本的东西:/
任何见解将不胜感激!
至于豆我有以下几点:
@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());
}
的页面如下ommitting用户界面:定义和头的东西。
<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>
编辑:我使用Glassfish的3.1与3.5 primefaces
编辑2:所以,似乎我不能使用outputlabel。如果我改变输入,然后我在managedbean中得到所需的值(我想这是因为它调用setter,但我认为它已经在选择行时被照顾)。但我不想编辑第一个字段,因为这是PK键,它在表中也用作FK。但至少知道我知道发生了什么,或多或少。
感谢,但不工作,要么:/如果我改变bean来viewscoped全部停止工作,我想我会需要添加额外的如果我离开的RequestScope和属性它总是指向第一个记录,并且该bean仍为空。 我会尝试一切转换成ViewScope和看到的结果!谢谢 –
2013-02-23 15:24:36
仔细查看代码。 OP正在使用'
'。在编辑对话框中打开数据工作正常。 OP在抱怨说在提交编辑对话框时它不再可用。 – BalusC 2013-02-23 17:10:21