我正在尝试使用primefaces中的update标记显示/不显示primefaces datatable。
当我重新加载(F5)页面时,表将正确呈现,但随后我将丢失输入到表单中的所有数据。我到处寻找ajax解决方案,但到目前为止还找不到任何解决方案。
我的代码:
<h:form id="adminForm">
<h:selectOneMenu id="adminTypeMenu" value="#{adminBean.orgType}">
<f:selectItem itemValue="" itemLabel="- Select One -"/>
<p:ajax actionListener="#{adminBean.updateOrgType}" update="adminForm" />
</h:selectOneMenu>
<p:dataTable id="adminMacTable" value="#{adminBean.currentArray}" var="currentOrg"
rendered="#{adminBean.Type eq 'bco'}" selection="#{adminBean.selectedMac}"
emptyMessage="No Records Found">
...
</p:dataTable>
</h:form>当前的实现显示了dataTable,但擦除了我输入的所有表单。有没有一种方法可以在不清除表单值的情况下呈现datatable?
更新:只是尝试了相同的代码,没有使用,但得到了相同的结果,仍然尝试其他方法!
发布于 2011-05-21 13:21:46
试试这个:
<h:form id="adminForm" prependId="false">
<h:selectOneMenu id="adminTypeMenu" value="#{adminBean.orgType}">
<f:selectItem itemValue="" itemLabel="- Select One -"/>
<p:ajax actionListener="#{adminBean.updateOrgType}" update="adminMacOutput" />
</h:selectOneMenu>
<p:outputPanel id="adminMacOutput">
<p:dataTable id="adminMacTable" value="#{adminBean.currentArray}" var="currentOrg"
rendered="#{adminBean.Type eq 'bco'}" selection="#{adminBean.selectedMac}"
emptyMessage="No Records Found">
...
</p:dataTable>
</p:outputPanel>
</h:form>如果这样做不起作用,请尝试将datatable放在一个单独的表单中,然后更新第二个表单。
发布于 2011-05-21 06:49:26
我猜AdminBean可能在request作用域中,在这种情况下,ajax事件将更新它,但是当您按下F5时,它会被重新创建。如果是这样,那么ViewScoped将提供帮助:
@ManagedBean(name = "adminBean")
@ViewScoped
public class AdminBean {
}https://stackoverflow.com/questions/6078178
复制相似问题