java - 有没有办法在不构建整个项目的情况下运行 JSF 页面?

标签 java jsf testing

有没有一种方法可以只运行一个页面,这样我就可以看到生成的 html(和 css),即使它本质上是非功能性的,也会像用户看到的那样?独立的 JSF 页面。在实际为表单字段编码之前,我想回顾一下我是如何设置表单的,看看从用户的角度来看它们是否有意义。我正在使用 maven 和 netbeans,但不确定后者是否相关。

最佳答案

如果您使用的是 JSF2 Facelets,那么您只需使用纯 HTML 设计表单并使用 jsfc属性指定应在 JSF 运行时期间使用的相应 JSF 组件。例如

<form jsfc="h:form">
    <label jsfc="h:outputLabel" for="input1" />
    <input type="text" jsfc="h:inputText" id="input1" value="#{bean.input1}" required="true" />
    <span jsfc="h:message" for="input1" />
    <input type="submit" jsfc="h:commandButton" value="Submit" action="#{bean.submit}" />
</form>

阅读 Facelets <ui:xxx> taglib documentation也应该给出一些见解。例如

<span jsfc="ui:remove">
    This is present during design time, but is removed during JSF runtime.
</span>

<div jsfc="ui:repeat" value="#{bean.items}" var="item">#{item}</div>

<table>
    <tr jsfc="ui:repeat" value="#{bean.items}" var="item">
        <td>#{item.id}</td>
        <td>#{item.name}</td>
    </tr>
</table>

事实上,您可以使用 <ui:composition>指定 Facelet 组合的开始和结束(例如包含文件或标记文件)。在运行时将忽略外部的任何内容,但您仍然可以在设计时放置一些 HTML,以便您可以轻松预览包含文件或标记文件应该属于其中的完整设计。

<!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"
>
    <head>
        ...
    </head>
    <body>
        ...
        <ui:composition>
            Here you can design content of include file or
            tag file as if it's part of the whole design.
        </ui:composition>
        ...
    </body>
</html>

这一切都允许您在不需要 JSF 运行时的情况下预览 HTML/CSS 设计。

关于java - 有没有办法在不构建整个项目的情况下运行 JSF 页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10504190/

相关文章:

jsf - 使用模板在jsf中的tomcat欢迎页面

angularjs - 如何在测试结束时关闭 selenium webdriver?

php - 如何在旧版项目中实现测试框架

java - 读取属性文件的 Maven 依赖项

java - 如何使用 Java URLConnection 进行 FTP 删除?

java - 真正动态的 JPA CriteriaBuilder

django - 测试 Jinja2 支持的 Django View 时如何访问 response.context

java - 如何在 android studio 中从 mysql 数据库检索并显示用户详细信息?

jsf - 有条件地渲染 <ui :include>

jsf - 从 session 中删除特定的 CDI 托管 bean