我正准备将最初使用 JSF 1.x 和 JSP 编写的 Web 应用程序迁移到 JSF 2 (myFaces 2.1.7) 和 Facelets。我也是转向 Facelets 的原因,因为它是 JSF 2.0 中的默认 View ,而且 RichFaces 4 等库也需要它。
首先,我按照以下文档作为指南来帮助我迁移代码:
Migrating from JSP To Facelets
就涉及的复杂性而言,根据上面链接中的迁移路径,它似乎并不复杂。链接不是全图吗?
在我当前的代码中还有许多 scriplet,例如
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
basePath
然后在页面的不同位置使用,例如在打开新页面的 JavaScript 函数中 basePath + newPage.faces
和文档 Id 检索来自 hiddenInput。
使用 Facelets 如何将以上内容归档?
最佳答案
In terms of complexity involved, it doesn't seem very complex based on the migration path in above link. Is the link not the whole picture?
您可以在此答案中找到更多详细信息:Migrating from JSF 1.2 to JSF 2.0
Also in my current code there are many scriplets such as
<% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %>
the
basePath
is then used in the various places in page, one for example is in JavaScript function that opens a new PagebasePath
+ newPage.faces and document Id retrived from hiddenInput.With Facelets how can the above be archived?
只需<ui:param>
和 EL。
<ui:param name="path" value="#{request.contextPath}" />
<ui:param name="basePath" value="#{request.requestURL.substring(0, request.requestURL.length() - request.requestURI.length())}#{path}/" />
它将作为 #{path}
提供和 #{basePath}
.
window.location = '#{basePath}newpage.xhtml?id=' + encodeURIComponent(someparam);
注意这个 #{basePath}
因此不包括与您的方法相反的不必要的端口号。另见 How get the base URL?
关于jsf-2 - 从 JSP 迁移到 Facelets,如何替换一些 scriptlets?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10560297/