重装使用Ajax DIV [英] Reloading div using Ajax

查看:91
本文介绍了重装使用Ajax DIV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经找到<一href="http://stackoverflow.com/questions/4555778/jsf-2-ajax-reload-whole-div-e-g-uiinclude-src-toreloaddata-xhtml">this话题,哪里还有一点code。使用Ajax来加载一个div。 我试图建立这样的例子,但没有成功。

I have found this topic, where's a bit of code to reload a div using Ajax. I've tried creating such example, but not successfully.

下面是我的code:

  • 的index.xhtml             

  • index.xhtml

        <h:form>
            <f:ajax render=":content">
                <h:commandButton value="News" action="#{navigationBean.requestPage}">
                    <f:param name="requestedPage" value="news.xhtml"/>
                </h:commandButton>
            </f:ajax>
            <br/><br/>
            <f:ajax render=":content">
                <h:commandButton value="News" action="#{navigationBean.requestPage}">
                    <f:param name="requestedPage" value="games.xhtml"/>
                </h:commandButton>
            </f:ajax>
        </h:form>

    </h:panelGroup>

    <h:panelGroup id="content" layout="block">
        <ui:include src="#{navigationBean.viewedPage}"/>
    </h:panelGroup>

  • 支持bean

  • backing bean

    @ManagedBean
    @ViewScoped
    public class NavigationBean
    {
        private String viewedPage;
    
        public NavigationBean()
        {
            viewedPage = "news.xhtml";
        }
    
        public String getViewedPage()
        {
            return viewedPage;
        }
    
        public void setViewedPage(String viewedPage)
        {
            this.viewedPage = viewedPage;
        }
    
        public void requestPage()
        {
            Map<String,String> map = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
            viewedPage = map.get("requestedPage");
        }
    }
    

  • 它的外观:

  • how it looks:

    所以我缺少什么?可变viewedPage更新,正常的标签/文本等的更新,但无法获得该div的工作。

    So what am I missing? Variable viewedPage is updated, normal labels/texts etc. are updated, but can't get this div working.

    推荐答案

    找到了解决办法:

    <h:commandButton value="Games" action="#{navigationBean.requestPage}">
        <f:param name="requestedPage" value="games.xhtml"/>
        <f:ajax execute="@this" render="@none" />
        <f:ajax render=":content"/>
    </h:commandButton>
    

    加改变@ViewScoped到@SessionScoped。

    plus changing @ViewScoped to @SessionScoped.

    这篇关于重装使用Ajax DIV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆