如果我有一个托管 bean,如下所示:
@ManagedBean
@RequestSchoped
public class Example {
private List<String> stringList;
private List<Long> longList;
// getters, setters, etc. down here
}
Run Code Online (Sandbox Code Playgroud)
并且有一个接受 List 作为属性的自定义组件:
<?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:cc="http://java.sun.com/jsf/composite"
xmlns:h="http://java.sun.com/jsf/html">
<!-- INTERFACE -->
<cc:interface>
<cc:attribute name="aList" type="java.util.List" />
</cc:interface>
<cc:implementation>
<!-- code is in here -->
</cc:implementation>
</html>
Run Code Online (Sandbox Code Playgroud)
我怎么能确保这有效:
<myComp:previousComponent aList="#{example.stringList}" />
Run Code Online (Sandbox Code Playgroud)
但这没有:
<myComp:previousComponent aList="#{example.longList}" />
Run Code Online (Sandbox Code Playgroud)
换句话说,我想做的事情cc:attribute如下:
<cc:attribute name="aList" type="java.util.List<java.lang.String>" />
Run Code Online (Sandbox Code Playgroud)
然而,正如我们所知,xhtml 不喜欢使用 > 或 <。此外,由于仅在编译时检查泛型,我不确定这将如何完成。有谁知道这是否可能?
我正在使用JSF 2.1,我遇到了<h:link>标签的一些问题.我正在尝试将链接的结果点从我的XHTML文件转换为纯HTML文件.但是,当我运行我的Web应用程序时,.html链接生成的URL中的.xhtml扩展名会自动转换为扩展名.
这是我的Facelet文件:
<h:body>
<h:form>
<h:link value="animation" outcome="#{contentForm.ccAnimationLink}"/>
</h:form>
<h:body>
Run Code Online (Sandbox Code Playgroud)
这是我的contentForm bean:
package my.app.content;
import java.io.Serializable;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;
@ManagedBean
@RequestScoped
public class ContentForm implements Serializable {
private static final long serialVersionUID = -8463354828156798513L;
private String ccAnimationLink = "";
@PostConstruct
public void init() {
ccAnimationLink = "/content/cc/CC_animation/story.html";
}
public String getCcAnimationLink() {
return ccAnimationLink;
}
public void setCcAnimationLink(String ccAnimationLink) {
this.ccAnimationLink = ccAnimationLink;
}
}
Run Code Online (Sandbox Code Playgroud)
现在,当我运行此应用程序时,我收到以下错误:
无法从视图ID'/content/modifiedcc.xhtml'中找到匹配的导航案例,以获得结果'/content/cc/CC_animation/story.html'
我确保我的URL正确,所以我story.xhtml …
我正在使用JSF 2.0与eclipse 3.4和Tomcat6.对于Facelets,我需要创建XHTML文件.现在的问题是eclipse中没有XHTML文件.我可以使用新的转换它的etension XHTML,但我编码它没有在自动完成中显示任何标记.在JSP文件中,当我编写<h:它时,显示所有相关标签和相同<f:但不在XHTML文件中.我在Eclipse中使用新文件制作了哪一个,请告诉我它是如何显示所有与之相关的标签<h:.
我是JSF的新手,但我的JSF标签没有在xhtml文件中呈现,我尝试了所有可能的解决方案,但问题没有解决
我的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>JSFProject</display-name>
<welcome-file-list>
<welcome-file>JSFProject/index.html</welcome-file>
<welcome-file>JSFProject/index.htm</welcome-file>
<welcome-file>JSFProject/index.jsp</welcome-file>
<welcome-file>JSFProject/default.html</welcome-file>
<welcome-file>JSFProject/default.htm</welcome-file>
<welcome-file>JSFProject/default.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
</web-app>
Run Code Online (Sandbox Code Playgroud)
我的example.xhtml
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Example</title>
</head>
<body>
<h:form>
Some random data: <h:inputText/><br/> <!-- Textfield ignored -->
Some other data: <h:inputText/><br/> <!-- Textfield ignored …Run Code Online (Sandbox Code Playgroud) 我正在使用带有Facelets的JSF 2.我有一个托管bean,它有一个引用a的属性List<Employee>.现在,我有一个<h:dataTable>标签,可以用简单的方式从该集合中创建一个表.
我需要的是不同的东西,我需要为该集合中的每个项目创建一个<div>元素<img>.如何在面向Facelets的JSF 2中实现这一目标?
你知道这个主题中提到的标签有什么区别吗?
我认为他们应该产生几乎相同的结果但事实证明,在某些情况下ui:repeat(facelets标签)没有像你期望的那样工作,尽管它也被认为是一个基本的迭代组件.
t是tomahawk和a4j是一个richfaces前缀.
欢迎任何评论.
在JSF facelet页面(.xhtml)中我有这个javascript代码
<script type="text/javascript">
function navigateToDetail() {
var id = document.getElementById("idElemento").value;
alert(id);
var isPratica = document.getElementById("isPratica").value;
alert(isPratica);
var box = "#{boxCtrl.idBox}";
alert(box);
if (isPratica==true)
window.location = "DettaglioRichiesta.xhtml?id=" + id + "&box=" + box;
else
window.location = "../Richieste/DettaglioRichiesta.xhtml?id=" + id + "&box=" + box;
}
</script>
Run Code Online (Sandbox Code Playgroud)
它不起作用,因为jfs引擎认为"&box"是相对于绑定的,它说:
Error Parsing /Box/ListaRichieste.xhtml: Error Traced[line: 20] The reference to entity "box" must end with the ';' delimiter
Run Code Online (Sandbox Code Playgroud)
我可以避免这种行为吗?
当我尝试调用Richfaces.showModalPanel('id')时,我得到的Richfaces没有定义javascript错误,也没有发生任何事情.
在我的示例应用程序中,我有两个页面,一个是主视图,另一个页面是子视图.子视图使用上面的调用在主视图中调用popupPanel.我不确定是什么问题.任何指针将不胜感激.
这是我的页面:
第一页:
<!DOCTYPE html>
<html lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:rich="http://richfaces.org/rich"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:richext="http://java.sun.com/jsf/composite/richext">
<h:head>
<title>Page Title</title>
</h:head>
<h:body>
<ui:include id="nextPageInclude" src="secondpage.xhtml"/>
<rich:popupPanel id="logoutDialogId"
width="300"
height="50"
autosized="true"
resizeable="false"
moveable="true"
modal="true"
style="border:5px solid #5e81ac; background-color:#dce3ed;">
<h:outputText value="Inside logout window"/>
</rich:popupPanel>
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)
第二页:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
<h:head/>
<a4j:outputPanel id='headerLinks' layout="block">
<ul id="sddm">
<li>
</li>
<li>
</li>
<li>
<a4j:commandLink id="logoutLinkId"
value="Logout"
onclick="Richfaces.showPopupPanel('logoutDialogId')"
styleClass="linkLogout"/></li>
</ul>
<div style="clear:both"></div>
</a4j:outputPanel>
</ui:composition>
Run Code Online (Sandbox Code Playgroud)
编辑:附加加载JS截图

谢谢,
p:selectOneMenu添加时选择存在问题f:selectItem.
视图:
<p:selectOneMenu value="#{selectionTest.selectedName}">
<f:selectItem itemLabel="Select" noSelectionOption="true" />
<f:selectItems value="#{selectionTest.allNames}" var="varName" itemLabel="#{varName}" itemValue="#{varName}" />
</p:selectOneMenu>
Run Code Online (Sandbox Code Playgroud)
模型:
private List<String> allNames;
private String selectedName;
public MenuSelectionTestBean(){
allNames = new ArrayList<String>();
allNames.add("Ahmed");
allNames.add("Mohamed");
allNames.add("Ibrahim");
allNames.add("Walid");
selectedName ="Walid";
}
Run Code Online (Sandbox Code Playgroud)
结果:

应选择"Walid"项,但选择"Ibrahim".我认为PrimeFaces根据列表中的索引选择项目,而不是项目的值.
这是怎么造成的,我该如何解决?
我是angularjs的新手,并试图在Facelets文件中创建一个示例angularjs.但我<html ng-app>在Eclipse IDE中遇到错误.该错误指定该ng-app属性后跟一个=字符.是不是可以在Facelets XHTML文件中包含angularjs代码?
<?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:ng="http://angularjs.org" ng-app>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
</head>
<body>
<div>
<label>Name:</label>
<input type="text" ng-model="yourName" placeholder="Enter a name here">
<hr>
<h1>Hello {{yourName}}!</h1>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) facelets ×10
jsf ×8
jsf-2 ×4
java ×2
richfaces ×2
xhtml ×2
angularjs ×1
collections ×1
eclipse ×1
foreach ×1
hyperlink ×1
javascript ×1
primefaces ×1
selected ×1
tomahawk ×1