gpt4 book ai didi

templates - 通过管理 bean 选择 JSF 动态模板

转载 作者:行者123 更新时间:2023-12-03 18:39:06 24 4
gpt4 key购买 nike

我的用例是为客户提供动态选择模板的便利。
我正在尝试使用托管 bean 选择模板,如下所示:

testTemplate1.xhtml

<?xml version='1.0' encoding='UTF-8' ?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html">

<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="./resources/css/default.css" rel="stylesheet" type="text/css" />
<link href="./resources/css/cssLayout.css" rel="stylesheet" type="text/css" />
<title>Facelets Template</title>
</h:head>

<h:body>
Template 1

<div id="content" class="center_content">
<ui:insert name="content">Content</ui:insert>
</div>

</h:body>

</html>

testTemplate2.xhtml
<?xml version='1.0' encoding='UTF-8' ?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html">

<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="./resources/css/default.css" rel="stylesheet" type="text/css" />
<link href="./resources/css/cssLayout.css" rel="stylesheet" type="text/css" />
<title>Facelets Template</title>
</h:head>

<h:body>
Template 2

<div id="content" class="left_content">
<ui:insert name="content">Content</ui:insert>
</div>

</h:body>

</html>

testTemplateClient.xhtml
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets">

<body>

<ui:composition template="#{templateSelection.selectedTemplate}">

<ui:define name="content">
Hello World
</ui:define>

</ui:composition>

</body>
</html>

TemplateSelection.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

import javax.inject.Named;
import javax.enterprise.context.Dependent;

/**
*
* @author aneeshaider
*/
@Named(value = "templateSelection")
@Dependent
public class TemplateSelection {

/**
* Creates a new instance of TemplateSelection
*/
public TemplateSelection() {
}

private String selectedTemplate="./testTemplate1.xhtml";

public String getSelectedTemplate() {
return selectedTemplate;
}

public void setSelectedTemplate(String selectedTemplate) {
this.selectedTemplate = selectedTemplate;
}


}

我无法动态选择模板,而是根本没有选择模板,只显示客户端。任何想法,如何解决?

最佳答案

实际上,我复制了您的代码,只更改了名称,并且有效。您确定您的路径/名称正确吗?

关于templates - 通过管理 bean 选择 JSF 动态模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18098641/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com