如何使commandButton更改ui中的url src:include with ajax

时间:2014-03-24 07:45:43

标签: ajax jsf commandbutton uiinclude

我用jsf构建模板。 模板具有包含其他jsf文件的div ///////////////////////

<h:panelGroup id="mainCenterBox" styleClass="mainCenterBox" layout="block">
       <ui:include  id="centerView" src="messageBoardView.xhtml"/>
</h:panelGroup>

\\\\\\\\\\\\

如何更改ui中的src:include当我用ajax cregk commandButton时查看其他页面

嗨,谢谢Vasil Lukach的重播 我不知道如何将参数表单commandButton发送到bean 以下是我的代码

\\\\\\\\\\\\\ The Bean File
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;

@Named("urls")
@RequestScoped

public class URLPagesBean 
{
    private String urlSRC = "";

    public String getUrlSRC() {
        return urlSRC;
    }

    public void setUrlSRC(String urlSRC) {
        this.urlSRC = urlSRC;
    }

    public String getURL()
    {
        String url = "";
        if(urlSRC == "page1" || urlSRC == "" || urlSRC == null)
        {
            url = "page1.xhtml";
        }
        else if (urlSRC == "page2")
        {
            url = "page2.xhtml";
        }
       return url;
    }
}
/////////////

\\\\\\\\\\\\\\\\\\\\\\ The Index file

<h:body >
    <h:panelGroup layout="block" styleClass="mainContentBox">
        <h:panelGroup layout="block" styleClass="mainTopBox">
            <h:panelGroup layout="block" styleClass="logoBox"></h:panelGroup>
        </h:panelGroup>
        <h:form id="subMenuForm">
        <h:panelGroup layout="block" styleClass="mainLiftBox">
                <h:panelGroup id="msgBoard" layout="block" styleClass="mainMenuButtons">Message Board
                    <h:panelGroup layout="block" styleClass="subMenuBox">
                        <h:commandButton id="showMsgBoard" styleClass="subMenuButtonCommand" value="Page1"/>
                    </h:panelGroup>
                </h:panelGroup>
                <h:panelGroup layout="block" styleClass="mainMenuButtons">Registrations Book
                        <h:panelGroup layout="block" styleClass="subMenuBox">
                            <h:commandButton id="registrInternalApprov" styleClass="subMenuButtonCommand" value="Page2">
                                <f:ajax render="mainCenterBox" />
                            </h:commandButton>     
                        </h:panelGroup>
                    </h:panelGroup>
          </h:panelGroup>
            <h:panelGroup id="mainCenterBox" styleClass="mainCenterBox" layout="block">
                    <ui:include  id="centerView" src="#{urls.URL}"/>
            </h:panelGroup>
        </h:form>
    </h:panelGroup>
</h:body>

1 个答案:

答案 0 :(得分:0)

在模板中,您可以使用ui:insert,例如

<ui:insert name="footer">
    <ui:include src="/WEB-INF/template/footer.xhtml" />
</ui:insert> 

在您的视图中,您可以重新定义它:<ui:define name="footer"></ui:define>(无页脚)或包含其他文件。

如果您需要支持ajax,则可以使用ui:fragment。它具有rendered属性,可用于显示内容(您可以拥有多个片段)。