我正在完成课程最终作业,我遇到了一些JSF和HTML5的问题。在问这个之前,我看了this和this回答。
在我的项目设置(属性 - >项目构面)中,我有:
我创建了我的HTML5文件separeted,现在我想将我的Java软件与我的前端代码合并。但我遇到问题,JSF不会渲染.html文件。
这是我原来的HTML:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE HTML>
<html xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<meta charset="utf-8">
<meta name="description" content="">
<meta name="author" content="Fernando Paladin">
<title>Locus - Disciplinas </title>
<link href="../../css/bootstrap.css" rel="stylesheet">
<link href="../../css/custom.css" rel="stylesheet">
</h:head>
<h:body>
<div class="container">
<div class="row">
<div class="col-lg-8 center">
<h:form role="form">
<div class="form-group">
<div class="col-md-10">
<h:inputText id="disciplina" class="form-control" value="#{disciplinaMBean.nome}" />
<!-- <input type="text" size="20" class="form-control" id="disciplina" placeholder="Pesquise ou crie uma nova disciplina"
required> -->
</div>
<div class="col-md-2">
<h:commandButton class="btn btn-md btn-success" action="#{disciplinaMBean.cadastrar}">
Adicionar
</h:commandButton>
<!-- <a type="button" href="#" class="btn btn-md btn-success">Adicionar</a> -->
</div>
</div>
<div class="col-md-10">
<div class="form-group">
<br/>
<h:dataTable value="#{disciplinaMBean.listaDisciplinas}" var="disciplina">
<h:column>
<f:facet name="header">Nome</f:facet>
<h:outputText value="#{disciplinaMBean.nome}" />
</h:column>
</h:dataTable>
<!-- <textarea class="form-control" placeholder="Aqui vão ser carregadas as disciplinas" rows="5"></textarea> -->
</div>
</div>
</h:form>
</div>
</div>
</div>
<!-- JavaScripts e Complementos -->
<script src="../../js/jquery.js"></script>
<script src="../../js/bootstrap.min.js"></script>
<script src="../../js/bootstrap-progressbar.min.js"></script>
</h:body>
</html>
这就是所呈现的:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE HTML>
<html xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<meta charset="utf-8">
<meta name="description" content="">
<meta name="author" content="Fernando Paladin">
<title>Locus - Disciplinas </title>
<link href="../../css/bootstrap.css" rel="stylesheet">
<link href="../../css/custom.css" rel="stylesheet">
</h:head>
<h:body>
<div class="container">
<div class="row">
<div class="col-lg-8 center">
<h:form role="form">
<div class="form-group">
<div class="col-md-10">
<h:inputText id="disciplina" class="form-control" value="#{disciplinaMBean.nome}" />
<!-- <input type="text" size="20" class="form-control" id="disciplina" placeholder="Pesquise ou crie uma nova disciplina"
required> -->
</div>
<div class="col-md-2">
<h:commandButton class="btn btn-md btn-success" action="#{disciplinaMBean.cadastrar}">
Adicionar
</h:commandButton>
<!-- <a type="button" href="#" class="btn btn-md btn-success">Adicionar</a> -->
</div>
</div>
<div class="col-md-10">
<div class="form-group">
<br/>
<h:dataTable value="#{disciplinaMBean.listaDisciplinas}" var="disciplina">
<h:column>
<f:facet name="header">Nome</f:facet>
<h:outputText value="#{disciplinaMBean.nome}" />
</h:column>
</h:dataTable>
<!-- <textarea class="form-control" placeholder="Aqui vão ser carregadas as disciplinas" rows="5"></textarea> -->
</div>
</div>
</h:form>
</div>
</div>
</div>
<!-- JavaScripts e Complementos -->
<script src="../../js/jquery.js"></script>
<script src="../../js/bootstrap.min.js"></script>
<script src="../../js/bootstrap-progressbar.min.js"></script>
</h:body>
如您所见,我的原始文件是渲染文件。所以,我无法点击任何字段,无法在输入中输入文字,最终,我无能为力。
这是如何引起的?如何解决?
答案 0 :(得分:2)
你忘了调用JSF的FacesServlet
。这是负责这项工作的人。仔细查看您在浏览器地址栏中输入的网址,并确保它与您在网络应用<url-pattern>
中定义的FacesServlet
的{{1}}相匹配。或者,只需将web.xml
更改为<url-pattern>
(或*.xhtml
,如果这是您的物理文件扩展名,并且您打算通过JSF运行所有*.html
网址,那么您永远不会需要摆弄虚拟网址。
请注意,此问题与您最初抱怨的HTML5完全无关。