0

我用jsf构建模板。模板的 div 包含另一个 jsf 文件 ////////////////////

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

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

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

嗨,谢谢 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>
4

1 回答 1

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可用于显示内容的属性(您可以拥有多个片段)。

于 2014-03-25T00:25:17.110 回答