[英]how to choose JSF Bean Scope transfer data on one page with dialog?
我在一頁中遇到beanscope問題,我知道是否要在一頁中重新顯示,我可以使用Viewscope,但是現在我要在一頁中從對話框到對話框獲取值形式的datatable傳遞,我使用sessionscope。 我可以獲取此值,但首先選擇不顯示的值,我必須按f5(刷新)頁面以顯示該值,我知道這意味着在會話范圍數據中從一個頁面傳遞到另一頁面,但現在我想在1中傳遞數據頁面引發對話框我的用戶primepface對話框我該怎么做? 這意味着當我單擊以對對話框的一個圖像進行顯示時,單擊對話框中的第二個顯示詳細信息(詳細的對象實例)。 我可以做到,但是我必須刷新頁面(重新加載頁面),我怎么做,不刷新頁面?
我想使用SessionScoped,並且我希望ID從對話框傳遞到對話框,並且不希望刷新會話范圍維護數據的頁面,我該怎么辦?
我的代碼JSF
<p:dialog header="Category" widgetVar="cate" width="600">
<f:view>
<h:form>
<p:dataTable value="#{catController.allCate}" var="item" paginator="true" rows="10"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} ">
<p:column>
<f:facet name="header">
<h:outputText value="Category name"/>
</f:facet>
<h:outputText value="#{item.cateName}"/>
</p:column>
<p:column style="width: 10px">
<f:facet name="header">
<h:outputText value=""/>
</f:facet>
<p:commandButton action="#{catController.showDetails(item)}" onclick="editcate.show()" style="cursor: pointer;width: 10px; height: 15px;" image="edit"/>
</p:column>
</p:dataTable>
</h:form>
</f:view>
</p:dialog>
<p:dialog header="Edit category" widgetVar="editcate" height="130" width="300">
<f:view>
<h:form>
<h:panelGrid columns="2">
<h:outputLabel value="" for="cateId" />
<h:inputHidden id="cateId" value="#{catController.details.cateId}" />
<h:outputLabel value="Category Name" for="cateName" />
<h:inputText id="cateName" value="#{catController.details.cateName}" title="CateName" required="true" requiredMessage="The CateName field is required."/>
</h:panelGrid>
</h:form>
</f:view>
</p:dialog>
還有我的菜豆
package com.mcgraw.controller;
import com.DAO.CategoryDAO;
import com.entity.Category;
import java.io.Serializable;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
/**
*
* @author Kency
*/
@ManagedBean
@SessionScoped
public class CatController implements Serializable{
@EJB
private CategoryDAO categoryDAO;
private Category cate;
/** Creates a new instance of CatController */
public CatController() {
cate = new Category();
}
public Category getCate() {
return cate;
}
public void setCate(Category cate) {
this.cate = cate;
}
// lay toan bo danh sach category
public List<Category> getAllCate(){
return categoryDAO.retrieveAllCat();
}
public void showDetails(Category cat){
this.cate = cat;
}
//tra ve thong tin chi tiet cua 1 category
public Category getDetails(){
//return categoryDAO.findByCatID(cate.getCateId());
return cate;
}
}
您使用@ViewScoped
並@ViewScoped
(更新)對話框。
<p:commandButton update="dialog" action="#{catController.showDetails(item)}" onclick="editcate.show()" style="cursor: pointer;width: 10px; height: 15px;" image="edit"/>
並將id
添加到對話框:
<p:dialog id="dialog" >
...
</p:dialog>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.