开发者

Glassfish not display JSF components

开发者 https://www.devze.com 2023-02-18 09:15 出处:网络
On my index.xhtml I have Java Server Face components which are displayed correctly and use a managed bean. But if I link to any other page or even a page with the EXACT same code those pages will not

On my index.xhtml I have Java Server Face components which are displayed correctly and use a managed bean. But if I link to any other page or even a page with the EXACT same code those pages will not display these components, only the text.

Suppose index.xhtml is like this and displays correctly:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PU开发者_JAVA技巧BLIC "-//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:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core">
    <h:head>
        <title>Facelet Title</title>
    </h:head>
    <h:body>
        <h:form>
            <h:inputText value="#{user.name}"/>
            <h:commandButton action="#{user.submit}" value="Submit" />
        </h:form>
    </h:body>
</html>

If I add a link to any other page (even one with the same code) JSF components are not displayed for them. Is this because the other pages perhaps can't 'see' the managed bean? Or something else?

Thanks for your help.


It looks like the pages which you want to call are not processed by the Faces Servlet.

In the web.xml of your application you define the url-pattern of server requests that will be processed by this servlet. By default this is often /faces/*. This means that the link that you call must contain this pattern in order to be processed by the Faces Servlet.

If you create your project with Netbeans, the mapping usually looks like the following:

<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
</servlet-mapping>

So try to use links that contain this url pattern or use relative links instead.

If you use h:link instead of a:href, the url-pattern is automatically prepended:

<h:link value="My other page" outcome="otherpage" />

will be rendered as:

<a href="/yourAppName/faces/otherpage.xhtml">My other page</a>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号