Jsf 2 每当我在数据表中单击commandButton时,都会重新创建ViewScope bean
Im使用primefaces版本3.1.1、Mojarra 2.1.3、Netbeans 7.0.1、Glassfish服务器3.1 我的测试应用程序使用了一个facelet模板,该模板具有顶部、左侧、内容、右侧和底部布局以及原始div和css。用户使用容器管理的jdbcrealm登录后,将显示使用上述模板的main index.html 我在左侧面板上放置了一个导航菜单,单击菜单项后,它将使用ajax更新中心面板的内容。通过使用sessionScopedJsf 2 每当我在数据表中单击commandButton时,都会重新创建ViewScope bean,jsf-2,datatable,primefaces,managed-bean,Jsf 2,Datatable,Primefaces,Managed Bean,Im使用primefaces版本3.1.1、Mojarra 2.1.3、Netbeans 7.0.1、Glassfish服务器3.1 我的测试应用程序使用了一个facelet模板,该模板具有顶部、左侧、内容、右侧和底部布局以及原始div和css。用户使用容器管理的jdbcrealm登录后,将显示使用上述模板的main index.html 我在左侧面板上放置了一个导航菜单,单击菜单项后,它将使用ajax更新中心面板的内容。通过使用sessionScopedNavigationBean,中心面板将
NavigationBean
,中心面板将在
中动态更新
在clientList.xhtml
的一个页面中,我放置了一个带有按钮的
,通过弹出一个
来查看详细信息。Im使用viewCoped bean保存dataTable上显示的数据列表
问题是,当我点击按钮选择每行最后一列中的一行时,对话框根本不会出现,我的p:ajaxStatus
gif图像一直在不停地滚动。当我用netbeans调试程序时,我注意到构造函数再次被调用,并且在单击按钮后上一个实例消失了
这是我使用facelets模板的index.xhtml
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<ui:composition template="/BySalesAutomationTemplate.xhtml">
<ui:define name="title">
<h:outputText value="Facelet Index Page"></h:outputText>
</ui:define>
<ui:define name="top">
TOP
</ui:define>
<ui:define name="left">
<ui:include src="users/menu#{request.isUserInRole('ADMIN') ? 'Admin' : 'User'}.xhtml" />
</ui:define>
<ui:define name="right">
<h:outputText value="Cuba2 daan"></h:outputText>
</ui:define>
<ui:define name="maincontent">
<c:if test="#{navigationBean.page!=null}">
<ui:include src="#{navigationBean.page}.xhtml" />
</c:if>
</ui:define>
<ui:define name="bottom">
<center>2012</center>
</ui:define>
</ui:composition>
</html>
这是我的后盾
public class SaClientController implements Serializable {
@EJB
private SaClientFacade saClientFacade;
private SaClient selectedSaClient;
private LazyDataModel<SaClient> lazyModel;
private List<SaClient> saclients;
/** Creates a new instance of SaClientController */
public SaClientController() {
}
@PostConstruct
public void Init() {
saclients = saClientFacade.Retrieve();
lazyModel = new LazyDataModelImp(saclients);
}
public LazyDataModel<SaClient> getLazyModel() {
return lazyModel;
}
public List<SaClient> getClients() {
return saClientFacade.Retrieve();
}
public SaClient getDetails() {
return selectedSaClient;
}
public String showDetails(SaClient selectedSaClient) {
this.selectedSaClient = selectedSaClient;
return "DETAILS";
}
public String update() {
System.out.println("###UPDATE###");
selectedSaClient = saClientFacade.Update(selectedSaClient);
return "SAVED";
}
public String list() {
System.out.println("###LIST###");
return "LIST";
}
public SaClient getSelectedSaClient() {
return selectedSaClient;
}
public void setSelectedSaClient(SaClient selectedSaClient) {
this.selectedSaClient = selectedSaClient;
}
public String dummyAction()
{
return null;
}
}
我已经在web.xml
中禁用了部分状态保存
<context-param>
<param-name>javax.faces.PARTIAL_STATE_SAVING</param-name>
<param-value>false</param-value>
</context-param>
javax.faces.PARTIAL_STATE_保存
假的
在我第一次单击
clienst.xhtml
中数据表最后一列中的view detail commandButton时,backingBean被重新初始化。对话框根本不显示。但按F5之后。对话框可以显示,但没有任何内容,对话框中唯一显示的是标签outputText,而不是bean值,它们是空的。对不起,我是新手。如果有人能告诉我我所做的是错的,我会非常高兴,也许能给我一些关于导航的建议,以及我在index.xhtml
中显示所有内容的策略是否正确(所以我一直只有一个视图id,就是index.xhtml
,对吗?) 这可能是PrimeFaces对话框的问题,您在p:dialog
周围有一个h:form
。我注意到当表单元素的子元素出现时,“PrimeFaces”对话框不能正常工作
尝试将此对话框窗体放置在对话框内容中
<p:dialog id="clientDialog" header="Client Detail" widgetVar="clientDialog" resizable="false" showEffect="explode" hideEffect="explode">
<h:form id="formdialog" prependId="false">
<h:panelGrid id="display" columns="2" cellpadding="4">
...
...
Wow。。。这太过分了。下次请尝试只包含与您遇到的问题直接相关的代码和配置。如果这是不可能的,请尝试在测试页面中重现该问题。谢谢maple_shaft。很抱歉我只是想把所有的细节都写进去。下次我会放短一点的。顺便说一句,您认为我的解决方案是什么,让浏览器始终只显示/index.xhtml。只有中央面板的内容通过动态包含其他xhtml页面来更新?可以吗?这是一个常见的解决方案,其他人也使用过。由于您已经在使用Primefaces,因此使用Primefaces布局模板可能会使您受益匪浅。早上好@BalusC,我希望你能告诉我是哪部分代码导致了这个问题。tq当我只运行clientList.xhtml而不使用模板时,它会自行运行。它运行良好。但是,当我使用divs css布局将clientList.xhtml动态(使用)放入index.xhtml时,我得到了前面描述的不稳定行为。我已经关闭了部分状态保存。是什么导致了这个问题?请帮忙…嗨,maple_shaft,还有其他建议吗?@frazkok我可能会尝试Primefaces布局,看看这是否会带来不同,但这可能并不重要。我建议尽量缩小这个问题的范围。创建一个测试页面,其中只包含一个数据表和对话框,看看是否可以用更少的代码重新创建问题。如果是这样,那么继续从托管bean中删除不必要的代码,直到问题消失。这将为您提供问题所在的线索。现在我没有看到任何其他看起来不正确的东西,但我可能遗漏了一些东西,因为有太多的代码。。。。另外,我建议重构prependId=“true”
的表单。可能存在导致问题的DOM id冲突。如果执行此操作,则必须在整个页面中更新update
attributes中列出的客户端ID。将表单id预先添加到组件id通常更安全,并且被认为是更好的做法。好的,我会试试。谢谢你的帮助。嗨,枫树。我只将页面视图更改为clientList.xhtml,没有使用facelet模板。是的,它成功了。知道为什么会这样吗?
<context-param>
<param-name>javax.faces.PARTIAL_STATE_SAVING</param-name>
<param-value>false</param-value>
</context-param>
<p:dialog id="clientDialog" header="Client Detail" widgetVar="clientDialog" resizable="false" showEffect="explode" hideEffect="explode">
<h:form id="formdialog" prependId="false">
<h:panelGrid id="display" columns="2" cellpadding="4">
...