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

Bil*_*mus 17 java testing jsf

有没有办法只运行一个页面,以便我可以看到生成的html(和css),因为它会向用户看,即使它本质上是非功能性的?独立的JSF页面.我想回顾一下如何在实际编写表单字段之前设置表单以确定它们是否符合用户的观点.我正在使用maven和netbeans但不确定后者是否相关.

Bal*_*usC 28

如果您正在使用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>
Run Code Online (Sandbox Code Playgroud)

阅读Facelets <ui:xxx>标签库文档也应该提供一些见解.例如

<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>
Run Code Online (Sandbox Code Playgroud)

并且您可以使用它<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>
Run Code Online (Sandbox Code Playgroud)

这一切都允许您预览HTML/CSS设计而无需JSF运行时.