Is there a way to run a JSF page without building the whole project?
Asked Answered
B

3

18

Is there a way to just run the one page so that I can see the generated html (and css) as it would look to the user even if it is essentially non-functional? Standalone JSF page as it were. I want to review how I am setting up forms to see if they make sense form a user standpoint before actually coding for the form's fields. I'm using maven and netbeans but not sure if the latter is relevant.

Bullhead answered 8/5, 2012 at 18:19 Comment(0)
C
28

If you're using JSF2 Facelets, then you can just design your forms with plain HTML and use the jsfc attribute to specify the respective JSF component which should be used during JSF runtime. E.g.

<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>

Reading the Facelets <ui:xxx> taglib documentation should also give some insights. E.g.

<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>

And the fact that you can use <ui:composition> to specify the start and end of a Facelet composition (e.g. an include file or a tag file). Any content outside will be disregarded during runtime, but you can still put some HTML around during designtime so that you can easily preview complete designs in which the include file or tag file is supposed to be part of.

<!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>

This all allows you to preview HTML/CSS designs without needing a JSF runtime.

Circumvallate answered 8/5, 2012 at 19:4 Comment(2)
Knew there had to be a way... it's too big of a hole not to. Thanks. Too bad there isn't any more direct way, but I'll take what I can get. :) P.S. I'm guessing that once satisfied with the ui:composition, one would cut and paste the desired section into another file or more likely delete the html stuff. Yes? Regards -- BillRBullhead
You're welcome. No, that's not necessary. If you use it as <ui:include> or <my:customtag>, any content outside <ui:composition> will already be disregarded during Facelets compilation. You can just keep the HTML design "wireframe" there.Circumvallate
S
2

You can not execute a JSF page directly without deploying the built application. You have to deploy it, and only then will you be able to display executed the page.

Stormi answered 8/5, 2012 at 18:23 Comment(0)
D
2

JBoss Tools for Eclipse have rudimentary support for JSF-tags in their visual editor.

I played briefly with it, but it did not support our legacy pages fully, so I left it at that. It may work better when starting with a blank page.

Doubleheader answered 8/5, 2012 at 18:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.