【问题标题】:JSF - dynamic 'name' attribute in ui:insertJSF - ui:insert 中的动态“名称”属性
【发布时间】:2014-01-09 20:50:46
【问题描述】:

在下面的代码中,登录后,ui:include 是 OK(改变),outputText 是 OK(改变),ui:insert 没有改变。

模板.xhtml:

<html xmlns="http://www.w3.org/1999/xhtml" (...) >
  <h:head></h:head>
  <h:body>
    <p:panel header="LoginForm" >
      <ui:insert name="#{userBean.loggedIn?'logoutForm':'loginForm'}" />
      <ui:include src="#{userBean.loggedIn?'incA.xhtml':'incB.xhtml'}" /> 
      <h:outputText value="#{userBean.loggedIn?'print logoutForm':'print loginForm'}" />
    </p:panel>
  </h:body>
</html>

index.xhtml:

<ui:composition template="template.xhtml"
xmlns="http://www.w3.org/1999/xhtml" (...) >
  <ui:define name="loginForm">
    <h:form >
      <p:inputText id="usernameInput" value="#{credentialsBean.username}" />
      <p:password id="passwordInput" value="#{credentialsBean.password}"  /> 
      <p:commandButton value="Log in" action="#{loginBean.actionLogin}" ajax="false" type="submit" />
    </h:form>
  </ui:define>
  <ui:define name="logoutForm" >
    <h:form >
      <p:commandButton value="Logout" type="submit" action="#{loginBean.actionLogout}" ajax="false" /> 
    </h:form>
  </ui:define>
</ui:composition>

这是正常行为吗?

【问题讨论】:

    标签: jsf


    【解决方案1】:

    ui:insert 的 name 属性在构建 JSF 树阶段进行评估。使用 ui:include 代替 ui:insert 来获得快乐。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-12
      • 2015-07-27
      • 1970-01-01
      • 2012-08-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多