Hi Karam,
setResourceBundle(...) allows you to load a resource bundle from a .jar
file (or anywhere in your classpath). When doing this, you need to
supply the full class name to the file. In web development, your
"pages" do not have the same package relationship that java files have
to other files in the same package. However, you can often refer to
files relative to their current location. So if you had .properties
files adjacent to your pages, you could write a handler similar to
setResourceBundle() that would find them... this doesn't exist right
now, and I'd recommend that you not do this as it opens up the
possibility of exposing your .properties file(s).
In the example below, the properties file was not a variable (although
it could be if you need it to be):
setResourceBundle(key="msgs"
bundle="com.sun.webui.jsf.example.resources.Resources"); />
The *key* "msgs" is used to refer to the values in the
"Resources.properties" file, that file will be located in the classpath
in the "com.sun.webui.jsf.example.resources" java package. See
java.util.ResourceBundle.getBundle(...) javadoc for more information on
ResourceBundles and .properties files.
As for the WEB-INF directory, there are predefined "special" directories
that exist here. The 2 most notable are: "libs" and "classes". The
"libs" directory allows you to put any .jar files you want in here and
they will be available to your web application's classloader. The other
("classes") is similar, however, you put .class files under this
directory instead of .jar files. The web.xml and faces-config.xml files
also belong under the WEB-INF directory. This directory structure is
part of the Java EE standard. You might find the following page useful
in describing this:
http://java.sun.com/javaee/5/docs/tutorial/doc/WebApp3.html
As for where to put images, etc. They are often placed in the document
root (not under the WEB-INF/ directory). JSFTemplating provides the
additional option of placing them in the classpath (i.e. in a .jar
file), and loading them through the "/resource/*" faces mapping (you
need to add this to your web.xml file for this to work).
I hope this helps! Let me know if I can answer any more questions.
Thanks,
Ken Paulsen
ken.paulsen_at_sun.com
https://jsftemplating.dev.java.net
Karam Singh Badesha wrote:
> Hi,
> Happy new year to all of you. Hopefully all of you are doing great.
> Let me start with couple of simple questions:
>
> - while setting the resource bundle, you are pointing to some file
> which will basically have the variable definition. Can you talk more
> about this file and its location. Is is possible for me to just look
> for the same file in the current folder, rather than some package?
> What is the real file name (Is it
> com.sun.webui.jsf.example.resources.Resources.properties in our
> example)? And what is the convention in the file (e.g.
> masthead_title=Masthead title )?
>
> - when I create more directories under the WEB-INF folder, do I need
> to do anything to map them? or do they just become available as they
> show up in the WEB-INF directory? e.g images folder etc.
>
> thanks,
> Karam
>
> Ken Paulsen wrote:
>>
>> No, your HTML-enabled email client won't render the contents
>> correctly. You should be able to do a "save as" on the attachment in
>> my original email to save the full contents of the file. Let me know
>> if this doesn't work.
>>
>> Thanks!
>>
>> Ken Paulsen
>> ken.paulsen_at_sun.com
>>
>>
>> Karam Singh Badesha wrote:
>>> Ken,
>>> The mh.jsf file that you attached only has the following content:
>>>
>>> setResourceBundle(key="msgs"
>>> bundle="com.sun.webui.jsf.example.resources.Resources"); />
>>> // Removed, see above
>>> /* * Facets have a different syntax in JSFTemplating,
>>> the following * is the old syntax for the facet defined above left here
>>> for * comparison purposes. * * * * */
>>> // Note the use of a double quote before any line that should be
>>> // rendered directly to the output stream.
>>>
>>> "
>>> "
>>> "
>>> Is this correct?
>>>
>>> -Karam
>>>
>>> Ken Paulsen wrote On 12/12/06 18:57,:
>>>
>>>> Hi Karam,
>>>>
>>>> I'm cc'ing the dev alias... I hope that's OK w/ you.
>>>>
>>>> Attached are the before and after pages for Masthead.jsp. Some
>>>> things to note... JSFTemplating allows Object types which can be
>>>> expressed via EL expressions (either $something{something} or
>>>> #{something} expressions). It also does not do any type conversion
>>>> from property values automatically (it may in the future, but
>>>> doesn't now). So attributes like "immediate" that expect a boolean
>>>> need to look like:
>>>>
>>>> immediate="#{false}"
>>>>
>>>> You'll see a couple of these changes in the mh.jsf. Also, the
>>>> Woodstock components in JSFTemplating have a "sun:" prefix. This
>>>> is mostly b/c we defined this before woodstock defined what they
>>>> were going to use (it was "ui:" which conflicted w/ another
>>>> component set when we defined it). So you'll notice that all
>>>> "webuijsf:" prefixes are changed to "sun:". I removed the "f:view"
>>>> tags which are needed for JSP b/c JSP isn't exclusively a JSF
>>>> format, these aren't needed for JSFTemplating. Facets look
>>>> different, I made a comment in the new file showing this. Loading
>>>> resources is also different (done via a handler), I also
>>>> demonstrated this.
>>>>
>>>> Their example uses property files and managed beans that aren't in
>>>> my environment... the page still comes up for me, but may not
>>>> function correctly b/c these are missing. If you add them or
>>>> change them to your own code it should work. A note about
>>>> processing buttons... they do:
>>>>
>>>> actionExpression="#{MastheadBean.consolePage1Clicked}"
>>>>
>>>> You can also do this. However, JSFTemplating has an additional
>>>> feature (one of its biggest features) which allows you to do this
>>>> instead:
>>>>
>>>> <!command
>>>> println("Hello World!");
>>>> setSessionAttribute(key="foo" value="bar");
>>>> >
>>>>
>>>> These are calls to "Handlers" which is where you can place your
>>>> custom business logic. You can then re-use these anywhere you'd
>>>> like, and of course you can use the built-in handlers as well (like
>>>> those above). This often eliminates the need for a managed bean
>>>> (Java code) completely.
>>>>
>>>> I hope this helps!
>>>>
>>>> Ken
>>>>
>>>> Karam Singh Badesha wrote:
>>>>
>>>>
>>>>> Hi Ken/Anissa,
>>>>> I got a simple example working. So thats good. With woodstock
>>>>> components there is example.war file in which there are bunch of
>>>>> example files. Now is it possible to just take any one of them,
>>>>> say example/faces/masthead/Masthead.jsp and show how it will look
>>>>> using jsftemplating (actual code). Because when I look at the
>>>>> example code in the Masthead.jsp file, there are lot of things
>>>>> there and I don't know what would be the equivalent of that using
>>>>> jsftemplating. Is there something I can look at to understand this
>>>>> more.
>>>>>
>>>>> thanks
>>>>> Karam
>>>>>
>>>>> Ken Paulsen wrote:
>>>>>
>>>>>
>>>>>> Hi Karam,
>>>>>>
>>>>>> Did you put it in the WEB-INF directory or the WEB-INF/lib
>>>>>> directory? The "jasper" message you are getting seems to
>>>>>> indicate that you are using JSP's, which should not be the case
>>>>>> of JSFTemplating files (which is what you have below).
>>>>>>
>>>>>> Your directory structure should look like this in your web
>>>>>> application:
>>>>>>
>>>>>> /WEB-INF/faces-config.xml (optional)
>>>>>> /WEB-INF/web.xml
>>>>>> /WEB-INF/lib/dataprovider.jar (woodstock requirement)
>>>>>> /WEB-INF/lib/json.jar (woodstock requirement in newest version...
>>>>>> I think)
>>>>>> /WEB-INF/lib/webui-jsf (woodstock)
>>>>>> /WEB-INF/lib/webui-jsf-suntheme.jar (woodstock)
>>>>>> /WEB-INF/lib/jsftemplating.jar (jsftemplating)
>>>>>> /WEB-INF/lib/jsftemplating-dynafaces-0.1.jar (new jsftemplating
>>>>>> requirement)
>>>>>> /yourfile.jsf
>>>>>>
>>>>>> I "think" that's all that's required.
>>>>>>
>>>>>> Just yesterday I integrated with Ed Burn's "Dynamic Faces"
>>>>>> project. This introduced "jsftemplating-dynafaces-0.1.jar" as a
>>>>>> requirement to work with the "tip" of JSFTemplating. There is a
>>>>>> branch prior to this integration called "JSF1_1" which does not
>>>>>> have this requirement. It also works with JSF 1.1, JSF 1.2 will
>>>>>> be a requirement going forward. I hope to remove the requirement
>>>>>> to include the Dynamic Faces .jar files, but until I can get Ed
>>>>>> to make some changes this will continue.
>>>>>>
>>>>>> If this doesn't help you get going, you can send me your web
>>>>>> application and I can take a look to see what might be causing
>>>>>> the problem. Also, you may find the "demo" application on the
>>>>>> JSFTemplating site may be a good example to see what is required
>>>>>> in the app... esp. wrt the build environment (it has ant
>>>>>> build.xml files that are already setup to compile with "apt", etc.).
>>>>>>
>>>>>> Good luck!
>>>>>>
>>>>>> Ken
>>>>>>
>>>>>> P.S. Unless there is Sun confidential information, please feel
>>>>>> free to use the "dev_at_jsftemplating.dev.java.net" email alias.
>>>>>> There are others inside Sun and outside that may provide
>>>>>> additional help... or your question may help someone else
>>>>>> experiencing the same problems! ;) If you haven't already
>>>>>> subscribed to that alias you may want to do that by going here:
>>>>>> https://jsftemplating.dev.java.net/servlets/ProjectMailingListList
>>>>>>
>>>>>> Karam Singh Badesha wrote:
>>>>>>
>>>>>>
>>>>>>> Ken/Anissa,
>>>>>>> Here is my first problem just setting up the netbeans env. I
>>>>>>> have copied all the woodstock jar files and jsftemplating jar
>>>>>>> files into the WEB-INF folder and there are no problems in
>>>>>>> building the following code from jsftemplating website:
>>>>>>> <sun:page>
>>>>>>> <sun:html>
>>>>>>> <sun:head title="Pick A Number" />
>>>>>>> <sun:body>
>>>>>>> <sun:form>
>>>>>>> <sun:textField label="Pick a Number:"
>>>>>>> text="#{requestScope.num}" />
>>>>>>> <staticText value="<br />You picked:
>>>>>>> #{requestScope.num}<br />" />
>>>>>>> <sun:button text="OK" />
>>>>>>> </sun:form>
>>>>>>> </sun:body>
>>>>>>> </sun:html>
>>>>>>> </sun:page>
>>>>>>>
>>>>>>> And here is the exception I get.
>>>>>>>
>>>>>>> org.apache.jasper.JasperException: /index.jsp(6,62) #{...} not
>>>>>>> allowed in a template text body.
>>>>>>>
>>>>>>> Is there a page which describes how to debug in this environment?
>>>>>>>
>>>>>>> thanks
>>>>>>> Karam
>>>>>>>
>>>>>>>
>>>>>>> ------------------------------------------------------------------------
>>>>>>>
>>>>>>>
>>>>>>> <jsp:root version="2.0"
>>>>>>> xmlns:f="http://java.sun.com/jsf/core"
>>>>>>> xmlns:h="http://java.sun.com/jsf/html"
>>>>>>> xmlns:jsp="http://java.sun.com/JSP/Page"
>>>>>>> xmlns:webuijsf="http://www.sun.com/webui/webuijsf">
>>>>>>>
>>>>>>> <jsp:directive.page contentType="text/html" />
>>>>>>> <f:view>
>>>>>>> <webuijsf:page id="page2" >
>>>>>>> <webuijsf:html id="html2" >
>>>>>>> <f:loadBundle
>>>>>>> basename="com.sun.webui.jsf.example.resources.Resources"
>>>>>>> var="msgs" />
>>>>>>> <webuijsf:head id="head2" title="#{msgs.masthead_title}">
>>>>>>> <webuijsf:link rel="shortcut icon"
>>>>>>> url="/images/favicon.ico" type="image/x-icon" />
>>>>>>> </webuijsf:head>
>>>>>>> <webuijsf:body id="body2" >
>>>>>>> <webuijsf:form id="form2">
>>>>>>> <!-- Masthead with Attributes -->
>>>>>>> <webuijsf:masthead id="masthead"
>>>>>>> serverInfo="#{MastheadBean.server}"
>>>>>>> userInfo="#{MastheadBean.user}"
>>>>>>> dateTime="true"
>>>>>>> notificationMsg="#{msgs.masthead_notificationmsg}" jobCount="0"
>>>>>>>
>>>>>>> productImageURL="/images/example_primary_masthead.png"
>>>>>>> productImageDescription="#{msgs.mastheadAltText}"
>>>>>>> utilities="#{MastheadBean.links}"
>>>>>>> alarmCounts="#{MastheadBean.alarms}" >
>>>>>>> <!-- Utility Bar Facets
>>>>>>> -->
>>>>>>> <f:facet name="consoleLink" >
>>>>>>> <webuijsf:hyperlink id="hyp1"
>>>>>>> toolTip="#{msgs.masthead_consoleLink}"
>>>>>>>
>>>>>>> actionExpression="#{MastheadBean.consolePage1Clicked}"
>>>>>>> immediate="true" />
>>>>>>> </f:facet>
>>>>>>> <f:facet name="versionLink" >
>>>>>>> <webuijsf:hyperlink id="hyp2"
>>>>>>> onClick="javascript: var versionWin =
>>>>>>> window.open('/example/faces/masthead/Version.jsp',
>>>>>>> 'VersionWindow','scrollbars,resizable,
>>>>>>>
>>>>>>> width=650,height=500,top='+((screen.height -
>>>>>>> (screen.height/1.618)) -
>>>>>>> (500/2))+',left='+((screen.width-650)/2) ); versionWin.focus();
>>>>>>>
>>>>>>> if(window.focus){versionWin.focus();} " immediate="true"
>>>>>>>
>>>>>>> toolTip="#{msgs.masthead_versionLink}"
>>>>>>> actionExpression="#{MastheadBean.versionPage1Clicked}"/>
>>>>>>> </f:facet> <f:facet
>>>>>>> name="logoutLink">
>>>>>>> <webuijsf:hyperlink id="hyp3"
>>>>>>> actionExpression="#{MastheadBean.logoutPage1Clicked}"
>>>>>>> toolTip="#{msgs.masthead_logoutLink}" immediate="true" />
>>>>>>> </f:facet> <f:facet
>>>>>>> name="helpLink" >
>>>>>>> <webuijsf:hyperlink id="hyp4"
>>>>>>> actionExpression="#{MastheadBean.helpPage1Clicked}"
>>>>>>> toolTip="#{msgs.masthead_helpLink}" immediate="true" />
>>>>>>> </f:facet>
>>>>>>> </webuijsf:masthead> <!--
>>>>>>> Breadcrumbs -->
>>>>>>> <webuijsf:breadcrumbs id="breadcrumbs">
>>>>>>> <webuijsf:hyperlink id="hyp5"
>>>>>>> actionExpression="#{IndexBean.showIndex}"
>>>>>>> text="#{msgs.exampleTitle}"
>>>>>>> toolTip="#{msgs.index_title}"
>>>>>>> immediate="true"
>>>>>>>
>>>>>>> onMouseOver="javascript:window.status='#{msgs.index_breadcrumbMouseOver}';
>>>>>>> return true"
>>>>>>>
>>>>>>> onMouseOut="javascript:window.status=''; return true"/>
>>>>>>> <webuijsf:hyperlink id="hyp6"
>>>>>>> actionExpression="#{MastheadBean.goToMastheadIndex}"
>>>>>>> text="#{msgs.masthead_title}"
>>>>>>> toolTip="#{msgs.masthead_titleToolTip}"
>>>>>>>
>>>>>>> onMouseOver="javascript:window.status='#{msgs.masthead_breadcrumbMouseOver}';
>>>>>>> return true"
>>>>>>>
>>>>>>> onMouseOut="javascript:window.status=''; return true"
>>>>>>> immediate="true"/>
>>>>>>> <webuijsf:hyperlink id="hyp7"
>>>>>>> text="#{msgs.masthead_masthead1Title}" />
>>>>>>> </webuijsf:breadcrumbs>
>>>>>>> <!-- Alert -->
>>>>>>> <webuijsf:alert id="message" type="information"
>>>>>>> summary="#{MastheadBean.message}"
>>>>>>> rendered="#{MastheadBean.isRendered1}" />
>>>>>>> <!-- Page Title -->
>>>>>>> <webuijsf:contentPageTitle id="pagetitle"
>>>>>>> title="#{msgs.masthead_pageTitle1}"
>>>>>>> helpText="#{msgs.masthead_helpText1}" />
>>>>>>> <div class="ConMgn_sun4">
>>>>>>> <br/>
>>>>>>> <!-- Hyperlink to Popup window with
>>>>>>> Secondary Masthead -->
>>>>>>> <webuijsf:hyperlink id="hyperlinkpopup"
>>>>>>> text="#{msgs.masthead_link}"
>>>>>>> toolTip="#{msgs.masthead_linkToolTip}" immediate="true"
>>>>>>> onClick="javascript: var popupWin =
>>>>>>> window.open('/example/faces/masthead/Popup.jsp','PopUpWindow','scrollbars,resizable,width=650,
>>>>>>>
>>>>>>> height=500,top='+((screen.height -
>>>>>>> (screen.height/1.618)) -
>>>>>>> (500/2))+',left='+((screen.width-650)/2) ); popupWin.focus();
>>>>>>> if(window.focus){popupWin.focus();}
>>>>>>> return false;" />
>>>>>>> </div>
>>>>>>> </webuijsf:form>
>>>>>>> </webuijsf:body>
>>>>>>> </webuijsf:html>
>>>>>>> </webuijsf:page>
>>>>>>> </f:view>
>>>>>>> </jsp:root>
>>>>>>>
>>>>>>>
>>>>>>> ------------------------------------------------------------------------
>>>>>>>
>>>>>>>
>>>>>>> setResourceBundle(key="msgs"
>>>>>>> bundle="com.sun.webui.jsf.example.resources.Resources"); /> //
>>>>>>> Removed, see above /* * Facets have a different syntax in
>>>>>>> JSFTemplating, the following * is the old syntax for the facet
>>>>>>> defined above left here for * comparison purposes. * * * * */ //
>>>>>>> Note the use of a double quote before any line that should be //
>>>>>>> rendered directly to the output stream. "
>>>>>>> "
>>>>>>> "
>>>>>>>
>>>
>>>
>