简体   繁体   English

如何在带有对话框的一页上选择JSF Bean Scope传输数据?

[英]how to choose JSF Bean Scope transfer data on one page with dialog?

i have one trouble with beanscope in one page i know if i want redisplay in one page i can use viewscope but now i want get value form datatable pass from dialog to dialog in one page and i use sessionscope. 我在一页中遇到beanscope问题,我知道是否要在一页中重新显示,我可以使用Viewscope,但是现在我要在一页中从对话框到对话框获取值形式的datatable传递,我使用sessionscope。 I can get this value but the first select the value not show, i must press f5 (refresh) page the value is show, i know it mean in session scope data pass from one page to another page but now i want pass data in 1 page throws dialog i user primepface dialog how can i do it? 我可以获取此值,但首先选择不显示的值,我必须按f5(刷新)页面以显示该值,我知道这意味着在会话范围数据中从一个页面传递到另一页面,但现在我想在1中传递数据页面引发对话框我的用户primepface对话框我该怎么做? it mean when i on click to image the dialog one display data table list and when i click to edit button it call dialog two display details one of data list (details instance of object). 这意味着当我单击以对对话框的一个图像进行显示时,单击对话框中的第二个显示详细信息(详细的对象实例)。 I can do it but i must refresh page (reload page) how can i do it , don't refresh page? 我可以做到,但是我必须刷新页面(重新加载页面),我怎么做,不刷新页面?

i want to use SessionScoped and i want id pass from dialog to dialog , and dont want refresh page for session scoped maintain data how can i do it? 我想使用SessionScoped,并且我希望ID从对话框传递到对话框,并且不希望刷新会话范围维护数据的页面,我该怎么办?

my Code JSF 我的代码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>

and my backing bean 还有我的菜豆

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;
    }




}

You use @ViewScoped and reRender (update) the dialog. 您使用@ViewScoped@ViewScoped (更新)对话框。

<p:commandButton update="dialog" action="#{catController.showDetails(item)}"  onclick="editcate.show()" style="cursor: pointer;width: 10px; height: 15px;" image="edit"/>

and add id to the dialog: 并将id添加到对话框:

<p:dialog id="dialog" >
   ...
  </p:dialog>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM