La Chamelle
La Chamelle

Reputation: 2967

JSF questions and advices

I'm doing a JSF2 project. I use mojarra 2.x, PrimeFaces 2.2RC2, Tomcat 6.x and Google Guice.

  1. For the moment I use commandlink to navigate through my site, so everytime I want to reload, the navigator ask for resubmit value. I see on the net that it's possible to redirect. Does it better to use outputlink or commandlink for navigation?

  2. Many times I use action with parameter like this:

    <:commandlink action="#{bean.doSomething(item)}" />
    

    This is good or bad ?

  3. Is there is some conventions in JSF for naming action, properties? Or what's your convention?

  4. When I write a xhtml page, does it better to use only components or just when necessary ?

    Example

    #{bean.foo}
    

    or

    <h:outputText value="#{bean.foo}" />
    
  5. What about the use of JSTL tags like <c:if> ? I use some because I had some problems when I use <ui:fragment rendered=""> during restoring view.

Upvotes: 2

Views: 268

Answers (1)

BalusC
BalusC

Reputation: 1108567

  1. <h:commandLink> fires a POST request. This makes no sense for page-to-page navigation. It's not user friendly nor SEO friendly. Just use <h:outputLink>, <h:link> or even <a> which fires a plain HTTP GET request.

  2. If item is already present in the instance behind #{bean} then this is unnecessary. If it's not, then it's perfectly fine. You only need to keep in mind that your code is this way not backwards compatible on Servlet 2.5 containers anymore while JSF 2.0 itself is backwards compatible on Servlet 2.5. It's namely a Servlet 3.0 / EL 2.2 feature (I only wonder how you get it to run on Tomcat 6. Aren't you using Tomcat 7 or are you using JBoss EL?).

  3. I wouldn't care that much, e.g. ProductManager, ProductController, Products, etc, as long as it is as much as possible self-documenting from the view side on. I.e. not #{pc.submit} or #{pd.column1}, but #{products.find} and #{product.name}.

  4. In Facelets, both are equally valid. Both are XML-escaped. The <h:outputText> only has the advantage that it allows easy access by UIViewRoot and adding attributes like styleClass, id, rendered, etc.

  5. As long as you use it only when you want to control how the view is built, not how view is rendered, then it's perfectly fine. Note that those http://java.sun.com/jstl/core tags are provided by Facelets itself, not by good ol' JSP JSTL JAR's (which has /jsp in taglib URI).

Related

Upvotes: 4

Related Questions