我正在尝试使用 Primefaces 在 JSF 中实现对实体的修改。
我列出用户的主要视图如下:
<p:growl id="growlEditUnit" showDetail="true" life="12000" />
<p:dialog id="dialogEditUnit" header="Edit Unit" widgetVar="editUnitDialog" showEffect="fade" hideEffect="fade" resizable="false" >
<ui:include src="editUnit.xhtml" />
</p:dialog>
<h:form id="form2">
<p:dataTable id="units" var="unit" value="#{unitController.unitsOfLoggedInUser}" >
<f:facet name="header">
Click Edit or Delete after selecting a unit to modify or remove it
</f:facet>
<p:column headerText="Code">
#{unit.unitCode}
</p:column>
<p:column headerText="Name">
#{unit.unitName}
</p:column>
<p:column headerText="Semester" >
#{unit.semester}
</p:column>
<p:column headerText="Academic Year">
#{unit.academicYear}
</p:column>
<p:column headerText="Twitter Username">
#{unit.twitterUsername}
</p:column>
<p:column headerText="Actions">
<p:commandButton id="editButton" value="Edit" action="#{unitController.setCurrent(unit)}" update=":dialogEditUnit" oncomplete"editUnitDialog.show()" />
</p:column>
</p:dataTable>
</h:form>
此视图正确列出了所有数据。但是,当我按当前时,我的目标是根据单击的按钮设置托管 bean 的当前属性(下面列出的代码)。在此之后,我尝试更新编辑对话框,因此它将填充该单元的值,然后使用 oncomplete 属性使其可见。但是,似乎在单击编辑按钮时从未调用托管方法 setCurrent(unit)。随后对话框显示为空。有人可以帮我解决我做错了什么吗?我也在发布托管 bean 代码。
@ManagedBean(name = "unitController")
@ViewScoped
public class UnitController implements Serializable {
private Unit current;
private List<Unit> unitsOfLoggedInUser;
@ManagedProperty(value="#{loginController.checkedUser}")
private Lecturer lecturer;
@EJB
private web.effectinet.ejb.UnitFacade ejbFacade;
@EJB
private web.effectinet.ejb.LecturerFacade lecturerFacade;
public UnitController() {
}
@PostConstruct
public void init(){
if (lecturer.getLecturerId() == null)
unitsOfLoggedInUser = null;
else
unitsOfLoggedInUser = (List<Unit>) lecturer.getUnitCollection();
}
public List<Unit> getUnitsOfLoggedInUser() {
return unitsOfLoggedInUser;
}
public void setCurrent(Unit current) {
this.current = current;
}
public Lecturer getLecturer() {
return lecturer;
}
public void setLecturer(Lecturer lecturer) {
this.lecturer = lecturer;
}