- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在使用 JSF/Facelets,我正在尝试迭代一些我保存在 HashMap 中的文档对象(自定义对象)。加载页面时,出现错误“在类型 java.util.HashMap$Values 上找不到属性‘名称’”。这是我的支持 bean 中的内容:
private Map<String, Document> documents = new HashMap<String, Document>();
public Collection<Document> getDocuments(){
return documents.values();
}
在我的 xhtml 页面中:
<h:dataTable id="documentTable"
value="#{DocumentManager.allDocuments}"
var="doc" rowClasses="list-row-odd, list-row-even"
headerClass="table-header" styleClass="bordered">
<h:column id="col_name">
<f:facet name="header">Name</f:facet>
${doc.name}
</h:column>
</h:dataTable>
如果我将 getDocuments 函数更改为以下内容,它会起作用(意味着表格显示无误),但我不确定为什么我需要将值放在列表中以使 JSF/Facelets 页面正确显示.
public List<Document> getDocuments(){
List<Document> rtrn = new ArrayList<Document>();
for(Document doc : documents.values())
rtrn.add(doc);
return rtrn;
}
难道我不能遍历集合吗?
最佳答案
事实证明,您不能只对 dataTable 使用任何类型的集合类型,这是有充分理由的。来自MyFaces 1.2 Spec ,值属性必须是:
An EL expression that specifies the data model that backs this table.
The value referenced by the EL expression can be of any type.
- A value of type DataModel is used directly.
- Array-like parameters of type
Object[]
,java.util.List
,java.sql.ResultSet
orjavax.servlet.jsp.jstl.sql.Result
are wrapped in a corresponding DataModelthat knows how to iterate over the elements.- Other values are wrapped in a DataModel as a single row.
Note in particular that unordered collections, eg
Set
are not supported. Therefore if the value expression references such an object then the table will be considered to contain just one element - the collection itself.
从 HashSet.values() 返回的集合未排序,因此不受支持。如果是这样,您将不知道表格中的行将以何种顺序输出,并且页面刷新可能会随机重新排序。不好。
您得到的错误是,从上一段开始,它表示数据表将您的集合视为行对象,而集合没有“名称”属性。
关于java - 在 JSF+Facelets 中迭代 HashMap.values(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/310410/
我有多个模板,它们之间的区别仅在于几个容器。最复杂的一个包含所有其他容器中使用的所有容器的超集,因此为了避免创建多个模板,我按以下格式创建了最复杂的一个 some layout stuff (di
有没有办法将 html 文件的内容插入到 Facelet 模板中? Facelets 标记将不起作用,因为它仅用于包含 Facelet 内容。 换句话说,我正在寻找等同于 JSP include 指令
我有一个用 JSP 编码的应用程序,现在我们正在将页面迁移到 Facelets。 我们的 PhaseListeners 之一正在操作组件树,因为它需要找出树中的一些组件并提取其中的一些值。但是对于 F
我已经读了好几遍了:一些开发人员不提倡在他们的 XHTML 文件中将 JSF/Facelets 标签与 HTML 标签交织在一起。显然 HTML 标签不会成为 UI 组件树的一部分,但这样做的缺点是什
我正在使用 JSF 2.0 构建一个 Web 应用程序,并且在我的 WEB-INF > lib 文件夹中有一个 jaf-facelets.1.1.10 jar,所以现在我正在尝试删除它,以便我可以使用
我正在使用 Apache MyFaces Commons Validator标签库。 我应该如何将它添加到我的 web.xml 中?通过Maven下载和解析commons JAR。 XHTML(我认为
我正在尝试使用 Facelets 创建自定义标签,但它没有呈现(即标签在响应中显示为未替换)。 标签(/WEB-INF/facelets/tags/inputThumbnailSelector.xht
当我的页面无法正确呈现时,我会在 jboss 控制台中看到此信息。有谁知道这是什么意思? 14:22:46,403 INFO [facelet] Facelet[/layout/header.xht
有人知道如何获取 ui:repeat Facelets 标记中元素的索引吗? 最佳答案 指定“varStatus”属性的值: 然后您可以通过 EL 访问循环索引: #{myVarSta
我在使用 Facelets 中的自定义组件时遇到问题。第一次呈现页面时,会在组件类上正确设置属性。但是,当提交表单时,不会设置属性。 这是我用来测试这个的类。 public class TestEch
我在 Tomcat 中使用 JSF 2 和 RichFaces。我是初学者,正在试用我找到的页面 here ,但页面只是空白(未呈现内容)。我尝试添加 Facelets 1.1 库,页面呈现没有问题。
我在我的应用程序中大量使用 bundle 的属性,因为我努力在未来保持代码的可维护性。因此,所有 HTML 文本都是从键/值属性文件中获取的,例如。 'index_en.properties' 当我需
我正在尝试将 Facelets 与 MyFaces 1.2 一起使用。看起来 Facelets 下载地址为 http://facelets.dev.java.net不复存在。 有谁知道 1) 我在哪里
在 Eclipse (Helios) 中打开 JSF 页面(JSF + Apache Trinidad + facelet)时,Eclipse 在页面打开前会卡住几秒钟。 同样在编辑页面时,代码完成/
有没有办法在构建或部署过程中检查您的 Facelets 文件是否有错误? 我不是在寻找一种解决方案,它不仅可以根据架构验证 Facelets 文件,还可以验证 EL 表达式是否有效。例如,如果属性或方
我有一个包含 8 列的 JSF 数据表。最后 4 列是数值列。可以说我的数据表带来了 20 行结果。我想添加最后一行,它只包含最后 4 列的字段并包含 20 行对应值的总和。我想用 Facelets
我想在另一个模板中使用 Facelets 模板。目前我有一个“基本”模板,到目前为止已经足够我完成的所有页面。它有一个顶部和一个内容区域。 顶部具有 Logo 、菜单、登录/注销功能,而内容区域则显示
我有一个使用组合的应用程序(用于页面模板)。但是我们认为在创建一个 web 应用程序( war )来托管所有应用程序共享的所有应用程序的所有模板。 如何包含来自其他上下文的模板?此时我使用从 http
我有一个对象列表,其中我不知道有多少,也不知道将调用哪些属性。我可以创建一个数据表来在不同的列中显示所有对象的属性吗? 我在想类似的事情: "#{object.attribu
使用 Facelets 时,我在导航方面遇到了一些问题。 我在 /WEB-INF 中有我的主模板: Header
我是一名优秀的程序员,十分优秀!