小编uda*_*day的帖子

如何包含多个xhtml页面,这些页面将相同的模板扩展到摘要xhtml页面,

我们如何将多个xhtml页面包含在摘要页面中.这里所有的xhtml页面都包含相同的模板.

commonTemplate.xhtml

<!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:c="http://java.sun.com/jsp/jstl/core"
    xmlns:ui="http://java.sun.com/jsf/facelets">
<head>
<title> SNS </title>
<meta http-equiv="expires" content="0"/>
<meta http-equiv="pragma" content="no-cache"/>
<meta http-equiv="cache-control" content="no-cache"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="sns.css" type="text/css" />
</head>
<h:body>

    <div id="header">
        <ui:insert name="commonHeader">
            <ui:include src="header.xhtml" />
        </ui:insert>
    </div>
    <div id="content">
        <ui:insert name="commonBodyContent">
            Common Body Content.
        </ui:insert>
    </div>
    <div id="footer">
        <ui:insert name="commonFooter">
            <ui:include src="footer.xhtml" />
        </ui:insert>
    </div>
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)

updatePersonalDetails.xhtml

<ui:composition 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"
                template="commonTemplate.xhtml">

    <ui:define name="commonBodyContent">
        .........;
        ..........;
    </ui:define>

</ui:composition>
Run Code Online (Sandbox Code Playgroud)

updatedAddress.xhtml

<ui:composition …
Run Code Online (Sandbox Code Playgroud)

jsf facelets jsf-2

8
推荐指数
1
解决办法
2万
查看次数

在Tomcat 6中使用JPA2:@PersitenceContext不起作用,EntityManager为null

我正在使用JSF2和Pure JPA2.但问题出在entityManager上,

@PersistenceContext
private EntityManager entityManager;
Run Code Online (Sandbox Code Playgroud)

这里entityManager没有被注入并且总是为null.有人可以帮我解决我的代码中出了什么问题.

这是我的配置.

User.java

    @Entity
    @Table(name="USER")
    public class User {

        private int id;
        private String name;
        private String surname;

        @Id
        @SequenceGenerator(name="user_id_seq_gen", sequenceName="USER_ID_GEN_SEQ", allocationSize=1)
        @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="user_id_seq_gen")
        @Column(name="ID", unique = true, nullable = false)
        public int getId() {
            return id;
        }

        public void setId(int id) {
            this.id = id;
        }

        @Column(name="NAME", unique = true, nullable = false)
        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        @Column(name="SURNAME", unique = true, …
Run Code Online (Sandbox Code Playgroud)

jsf-2 jpa-2.0

7
推荐指数
1
解决办法
1万
查看次数

JSF2 h:selectOneMenu在验证失败时显示旧值

我有一个包含少量输入字段和一个选择菜单的表单.所有字段都是必需的="true",firstName,lastName,emailAddress,密码,国家/地区.

测试用例#1:1)在所有输入字段中输入值,保留firstName字段而不输入任何值,
选择一个国家(例如:美国)并提交表单,我们可以看到所需的firstName字段的错误消息.

2)保持表单不变,保留firstName字段而不输入任何值,然后选择country to"select one",并提交表单.我们可以看到firstName和country字段的错误消息,但是在下拉列表中它没有显示"Select One",它显示美国(之前的选择).

我对输入字段有同样的问题,但我用转换器解决了.有没有办法解决这个问题.我在stackoverflow中发布了一些帖子,后来才知道这是mojarra中的一个bug.

这是我的代码......

userRegistration.xhtml

<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:body>
    <h:form id="registrationForm">     
    <h:messages layout="table" infoClass="infoMsgs" errorClass="errMsgs"/>

    <table>
        <tr>
            <td>First Name:</td>
            <td>
                <h:inputText size="40" maxlength="100" 
                             required="true" 
                             styleClass="#{component.valid ? '' : 'text_error'}"
                             value="#{registrationAction.firstName}" />
            </td>
        </tr>
        <tr>
            <td>Last Name:</td>
            <td>
                <h:inputText size="40" maxlength="100" 
                             required="true" 
                             styleClass="#{component.valid ? '' : 'text_error'}"
                             value="#{registrationAction.lastName}" />
            </td>
        </tr>
        <tr>
            <td>Email Address:</td>
            <td>
                <h:inputText size="40" maxlength="100" 
                             required="true" 
                             styleClass="#{component.valid ? '' : 'text_error'}"
                             value="#{registrationAction.emailAddress}" />
            </td>
        </tr>
        <tr>
            <td>Password:</td>
            <td>
                <h:inputSecret size="20" maxlength="15" …
Run Code Online (Sandbox Code Playgroud)

jsf facelets jsf-2

5
推荐指数
1
解决办法
3248
查看次数

将静态HTML(无效XHTML)文件包括到JSF Facelets中

我有以下问题,我们有在远程主机上运行的Web内容管理器(WCM),它负责生成页眉和页脚HTML文件。即header.html,footer.html。HTML文件的语法格式不正确,WCM生成的文件具有

  1. 空格字符(&nbsp;)X XHTML中不允许使用。
  2. 非关闭换行符(<br>)标记?在XHTML中无效。

因此,WCM生成的HTML页面可能不是有效的XHTML页面。

我们正在JSF中实现一些应用程序,我们需要在其中包含WCM生成的页眉和页脚文件。我们可以将未格式化的HTML文件包含到我们的XHTML文件中吗?

commonTemplate.xhtml

<html>
<head>
..........;
</head>
<body>
<ui:include src="remote_host/header.html" />

<ui:insert name="commonBodyContent" />

<ui:include src="remote_host/footer.html" />
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

facelets jsf-2

3
推荐指数
1
解决办法
1万
查看次数

在Servlet过滤器中访问FacesContext的问题

我试图访问Servlet过滤器中的FacesContext,有时(不是每次)我遇到内部服务器错误.

AuthenticationFilter.java

import java.io.IOException;

import javax.faces.context.FacesContext;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.codec.binary.Base64;


public class AuthenticationFilter implements Filter {
    @Override
    public void destroy() {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response,
            FilterChain chain) throws IOException, ServletException {

        request.setCharacterEncoding("UTF-8");
        UserDetailsBean userBean = null;
        HttpServletRequest req = (HttpServletRequest)request;
        HttpServletResponse res = (HttpServletResponse)response; 
        FacesContext context = FacesUtil.getFacesContext(req, res);
        String param = req.getParameter("PARAMETER_VALUES");

        if((param!=null && param.isEmpty()) || !isAuthenticated(req)) {

            if(param …
Run Code Online (Sandbox Code Playgroud)

tomcat6 jsf-2 servlet-filters

1
推荐指数
1
解决办法
3769
查看次数

标签 统计

jsf-2 ×5

facelets ×3

jsf ×2

jpa-2.0 ×1

servlet-filters ×1

tomcat6 ×1