Updates from April, 2010 Toggle Comment Threads | Keyboard Shortcuts

  • Tomás Augusto Müller 11:02 am on April 16, 2010 Permalink | Reply
    Tags: , , jboss-el, , seamframework   

    Read query string using jsf, facelets and Seam-EL 

    If you are familiar with JavaServer Faces, maybe already read or heard someone talk about JSF implicit objects.
    In short, an implicit object is similar to a managed bean, but one that is created and maintained by the JSF engine, which you may make reference to with EL.

    The implicit EL object #{facesContext} maintained by the JSF servlet is instantiated from javax.faces.context.FacesContext, for each JSF request made upon the mid-tier. As the JSF lifecycle processes the current JSF request, the FacesContext instance carries the information about the page to be rendered, essentially the JSF response to the original request.

    You can use this object to retrieve a reference to the request parameter map (which is a Map<String, String>) and through the JBoss-EL, access the value of the desired param.

    Example:

    GET request to: http://localhost:8080/yourApp/yourPage.seam?param1=value%201&param2=1234

    <h:outputText value=”#{facesContext.externalContext.requestParameterMap.get(‘param1′)}” />

    output: value 1

    <h:outputText value=”#{facesContext.externalContext.requestParameterMap.get(‘param2′)}” />
    output: 1234

    Tip: there is also the #{param} implicit object. You can use this reference to grap your query string parameters in a short form as follows:

    <h:outputText value=”#{param.get(‘parameterNameHere’)}” />

    As you may be wondering, there are several other implicit objects. You can check them bellow.

    • facesContext – The FacesContext instance for the current request.
    • param – Maps a request parameter name to a single value.
    • paramValues – Maps a request parameter name to an array of values.
    • header – Maps a request header name to a single value.
    • headerValues – Maps a request header name to an array of values.
    • cookie – Maps a cookie name to a single cookie.
    • initParam – Maps a context initialization parameter name to a single value.
       

    Objects that allow access to various scoped variables:

    • requestScope – Maps request-scoped variable names to their values.
    • sessionScope – Maps session-scoped variable names to their values.
    • applicationScope – Maps application-scoped variable names to their values.
       

    When an expression references one of these objects by name, the appropriate object is returned. An implicit object takes precedence over an attribute that has the same name. For example, #{facesContext} returns the FacesContext object, even if there is an existing facesContext attribute containing some other value.

    source: http://developers.sun.com/docs/jscreator/help/jsp-jsfel/jsf_expression_language_intro.html#implicitobjects

     
  • Tomás Augusto Müller 10:28 pm on January 13, 2010 Permalink | Reply
    Tags: , ,   

    Facelets “com.sun.facelets.impl.DefaultFacelet refresh” error 

    If you are getting this error, just add the following parameter to your web.xml file:

        <context-param>
            <param-name>facelets.REFRESH_PERIOD</param-name>
            <param-value>-1</param-value>
        </context-param>

    facelets.REFRESH_PERIOD
    When a page is requested, what interval in seconds should the compiler check for changes. If you don’t want the compiler to check for changes once the page is compiled, then use a value of -1. Setting a low refresh period helps during development to be able to edit pages in a running application.
    Default value: 2

    More info at:
    https://facelets.dev.java.net/nonav/docs/dev/docbook.html#config-webapp-init
    http://old.nabble.com/Error:-Facelet-was-modified,-flushing-component-applied-td13500808.html

     
    • Tapas Kr. Dey 2:17 am on August 9, 2011 Permalink

      Thank you.It helps me very well.

  • Tomás Augusto Müller 10:26 pm on January 13, 2010 Permalink | Reply
    Tags: , ,   

    How to use Javascript script tag in Facelets xhtml file 

    If you want to use javascript, with the <script> tag in Facelets xhtml file, and your script have characters like ‘>’, ‘<’, you may get this error message:

    com.sun.facelets.FaceletException: Error Parsing /filename.xhtml: Error Traced[line: xx]
    The content of elements must consist of well-formed character data or markup.

    To avoid this parsing error use the script in a "commented" way:

    <script type="text/javascript">
    <!--
    your script here.
    //-->
    </script>
     
    • Jitesh 9:11 am on September 16, 2010 Permalink

      Thanx a lot

    • Fernando 2:10 am on April 2, 2011 Permalink

      thanks for the tip! very helpfull

    • Federico González Brizzio 11:57 am on May 3, 2011 Permalink

      Thank you!

    • Wender Freese 12:41 pm on December 18, 2012 Permalink

      Hey, Thanks a lot.

    • Julian 8:57 pm on February 22, 2013 Permalink

      public void ThankYou(){
      System.out.println(“Thank you!”);
      ThankYou();
      }

  • Tomás Augusto Müller 9:47 pm on January 14, 2009 Permalink | Reply
    Tags: , , translation   

    JavaServer Faces RI (Mojarra) Messages 

    Hello everyone!

    Looking at Mojarra jars (jsf-api.jar and jsf-impl.jar), reference implementation of JavaServer Faces, depending of which version you are using, you’ll find at least one file named Messages.properties. This file holds the standard messages for converters, validators, component errors and other implementation defined messages.

    In the lasted version of Mojarra (1.2_11-b01-FCS), those messages are in:

    jsf-api.jar\javax\faces\Messages.properties
    jsf-impl.jar\com\sun\faces\resources\Messages.properties

    So what?

    If you are from Brazil, involved in some project that use JSF-RI, and if you are seeking for the translated version of those messages in Brazilian Portuguese, your search is over!

    Take a look at this excellent job made by Cristiane Maerker, my team mate at UNISC.

    Once you’ve defined a message bundle for your application, you can selectively override some of the standard error messages as long as you use the proper existing key of the above file.

    By the way, Mojarra developers, what do you think to include this version of standad messages in distribution files of JSF-RI? See the Google Trends graphs for the search JavaServer Faces, JSF, Mojarra. Brazil appears in the top ten regions.

     
    • Rafael Ponte 6:15 pm on January 18, 2009 Permalink

      Congratulations Tomás!!This is a great contribution for the JSF brazilian developers, very nice!

  • Tomás Augusto Müller 12:39 pm on November 8, 2008 Permalink | Reply
    Tags: conversation, frameworks, , , ,   

    Need conversation scope for backing-beans? 

    These days I was looking an alternative solution to JBoss Seam, to provide conversation scope to my JavaServer Faces backing beans, and I wanted that this new solution be easily integrated with Spring Framework and others frameworks used in the application, like JBoss RichFaces, Facelets, Hibernate.

    So I’ve found the MyFaces Orchestra project through this video, recorded at JSFDays 2008 in a session of Thomas Spiegl and Mario Ivankovits, both of Apache MyFaces project.

    About MyFaces Orchestra

    Orchestra is a small library that can be used in web applications to provide the following features:

    • A conversation (aka dialog) scope for beans.
    • Conversation-scope persistence contexts. This fixes the dreaded LazyInitializationException or NonUniqueObjectException problems when working with persistent objects.
    • Declarative transaction annotations (java1.5 only).
    • A “dynaForm” JSF component that helps create forms for editing persistent data.

    Orchestra requires that Spring 2.x be used to declare managed beans that will be stored in conversation context.

    There are no other significant dependencies or structural requirements for code that uses Orchestra (in particular, no requirement to use EJBs).

    Also, Orchestra works with any JSF implementations (e.g. JSF-RI, MyFaces).

    Some Highlights

    • It works with a Java 1.4-compliant syntax, but you can optionally use annotations
    • It utilizes the powerful Spring bean configuration mechanism instead of JSF’s managed-bean facility. The release of Spring 2.0 made it possible to define custom bean scopes in Spring. If a JSF Managed bean is declared in Spring using the Orchestra “conversation” scope, then when that bean is referenced from a JSF EL expression it is automatically created within that conversation scope. It is not necessary for non-conversation-scoped managed beans to be declared via Spring, although we do recommend it: request and session scopes are also supported and you benefit from having one common syntax for defining the beans of your application, from the AOP features Spring provides, and from Spring’s other advanced features.
    • A plus for integrating Orchestra into existing applications: If you configure your application to use Orchestra, whenever the conversational context is opened, Spring configured DAOs and BOs automatically use the new context and gain from the conversational features of Orchestra. Minimal effort for maximal results!
    • MyFaces Orchestra is know to be compatible to persistence frameworks such as Toplink and Hibernate (and generally any JPA-implementation). However, any persistence framework can be plugged into Orchestra.
    • The Orchestra API can be adapted to use other web frameworks than JSF.
    • Orchestra sports a very easy to use API – maximum 3 method calls, and you’re ready to go.

    Installation

    You can read here the installation guide. It is very simple and easy to understand if you are already familiar with Spring.

    Note: to make the variable lookup of beans configured in Spring work correctly, you have to configure the DelegatingVariableResolver in your faces-config.xml.

    <application>

    <variable-resolver>org.springframework.web.jsf.DelegatingVariableResolver</variable-resolver>
    </application>

    This way you not get the following exception at each request:

    java.lang.IllegalArgumentException: No AccessScopeManager found.
    Probably you forgot to add <import resource=”classpath*:/META-INF/spring-orchestra-init.xml” /> to your spring configuration.

    More informations at http://myfaces.apache.org/orchestra/index.html, and in project wiki at http://wiki.apache.org/myfaces/Orchestra.

     
    • mmrack 7:57 pm on December 5, 2008 Permalink

      Why an alternate solution for Seam?

    • Tomás Augusto Müller 9:56 am on December 6, 2008 Permalink

      we are planning to use Jboss Seam. But since we not using Seam yet, and right now we need only this kind of scope level (something between request and session), MyFaces Orchestra comes to the scene. This is a light library that only provide conversational scope (two new scopes for spring beans in fact), and others few things. And the most important: is really easy to use, and already integrated with Spring Framework. I have no doubt that the jsr 299 is a nice stuff.Hail the “King”! ; )

    • ymajoros 5:50 am on July 31, 2009 Permalink

      another bright idea from apache. Every time I see this kind of tricks, I wonder why they always need to implement some proprietary thing (which apache and spring are), to get around a defined standard which had good reasons for not doing this…

    • Anonymous 8:53 am on August 4, 2009 Permalink

      I don't know why, but i add DelegatingVariableResolver in my faces-config.xmland import spring-orchestra-init.xml in my web.xml, and i still avec this exception at the end of the startup.java.lang.IllegalArgumentException: Orchestra was unable to create an instance of bean with name 'AccessScopeManager'

c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
shift + esc
cancel
Follow

Get every new post delivered to your Inbox.

%d bloggers like this: