Moving from JSP to Facelets, how to replace some scriptlets?

I am ready to move my web application that was written in JSF 1.x and JSP to JSF 2 (myFaces 2.1.7) and Facelets. I also explain the switch to Facelets, as this is the default view in JSF 2.0, and libraries like RichFaces 4 require this.

First, I am following the following document as a guide to help me port the code:

Migrating from JSP to Facelets

In terms of complexity, this doesn't seem very complicated based on the migration path in the link above. Is the link not the whole picture?

Also in my current code there are many scripts like

    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %> 

It basePathis then used in various places on the page, for example, in the JavaScript function, which opens a new page basePath + newPage.facesand the document identifier obtained from hidden input.

With Facelets, how can I write above?

+3
source share
1 answer

In terms of complexity, this doesn't seem very complicated based on the migration path in the link above. Is the link not the whole picture?

You can find more details in this answer: Migrating from JSF 1.2 to JSF 2.0


Also in my current code there are many scripts like

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> 

basePathit is then used in various places on the page, for example, in a JavaScript function that opens a new page basePath+ newPage.faces and the document ID obtained from hiddenInput.

Facelets, ?

<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}, , . . URL?

+4

All Articles