Glassfish不显示JSF组件 [英] Glassfish not display JSF components

查看:162
本文介绍了Glassfish不显示JSF组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的index.xhtml上,我有正确显示并使用托管bean的Java Server Face组件。但是,如果我链接到任何其他页面或甚至与EXACT相同的代码的页面,那些页面将不会显示这些组件,只有文本。



假设index.xhtml是并正确显示:

 <?xml version ='1.0'encoding ='UTF-8'?> 
<!DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Transitional // ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
xmlns:h =http://java.sun.com/jsf/html
xmlns:f =http://java.sun.com/jsf/core>
< h:头>
< title> Facelet标题< / title>
< / h:头>
< h:body>
< h:form>
< h:inputText value =#{user.name}/>
< h:commandButton action =#{user.submit}value =Submit/>
< / h:表格>
< / h:body>
< / html>

如果我添加一个链接到任何其他页面(即使是具有相同代码的页面),JSF组件也不会显示给他们。这是因为其他页面可能无法看到托管bean?或者别的什么?



感谢您的帮助。

看起来像你想调用的页面不会被Faces Servlet处理。

在您的应用程序的 web.xml 中,您可以定义要处理的服务器请求的url-模式这个servlet。默认情况下,这通常是 / faces / * 。这意味着您调用的链接必须包含此模式才能被Faces Servlet处理。



如果使用Netbeans创建项目,映射通常看起来像如下:

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

所以请尝试使用包含此url模式的链接或使用相对链接。



如果您使用 h:link 而不是 a:href ,则url -pattern自动添加:

 < h:link value =我的其他页面outcome =otherpage/> 

将呈现为:

 < a href =/ yourAppName / faces / otherpage.xhtml>我的其他页面< / a> 


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 PUBLIC "-//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>

这篇关于Glassfish不显示JSF组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆