3

I'm preparing to move my web application which was intially written with JSF 1.x and JSP to JSF 2 (myFaces 2.1.7) and Facelets. I also reason the move to Facelets since it is default view in JSF 2.0 and also libraries such as RichFaces 4 require it.

Firstly, I am following the following document as guide to help me migrate the code:

Migrating from JSP To 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?

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?

BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
ke3pup
  • 1,675
  • 4
  • 30
  • 60

1 Answers1

4

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?

You can find more detailed information in this answer: 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?

Just with <ui:param> and EL.

<ui:param name="path" value="#{request.contextPath}" />
<ui:param name="basePath" value="#{request.requestURL.substring(0, request.requestURL.length() - request.requestURI.length())}#{path}/" />

It'll be available as #{path} and #{basePath}.

window.location = '#{basePath}newpage.xhtml?id=' + encodeURIComponent(someparam);

Note that this #{basePath} thus doesn't include unnecessary port numbers in contrary to your approach. See also How get the base URL?

Community
  • 1
  • 1
BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
  • thank you so much for your response @BalusC. Appreciate you sharing your knowledge and time. Cheers – ke3pup May 12 '12 at 07:03
  • @BalusC, I was a little surprised that `` can be used that way, but it does appear to work, at least on Mojarra. The docs all talk about using `` to pass parameters to `` files or for templates. Is it generally accepted to use `` in this way to create shortcut variables within a file? – Brian May 14 '12 at 19:20