jsf-2 - 从 JSP 迁移到 Facelets,如何替换一些 scriptlets?

标签 jsf-2 migration facelets

我正准备将最初使用 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 Page basePath + 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/

相关文章:

java - 如何将参数传递给 JSF 2.0 页面上的 javascript 函数

validation - 如何在 h :inputText with JSF 上阻止负数

jsf-2 - 焦点丢失时调用 bean 方法

database - 从一个 DBMS 迁移到另一个

jsf - PrimeFaces Dialog + appendToBody=true 不起作用

jsf - RichFaces 和 Facelets,一个好的组合?

security - 保护 JSF 应用程序的安全

database - Rails 3 - 将大量数据从旧数据库模式移动到新数据库模式

ruby-on-rails - 您如何与开发人员团队一起管理 Ruby on Rails 迁移?

jsf - javax.el.E​​LException : Failed to parse the expression [{pz:instanceof(object ,'com.project.domain.MyClass' )}]