dev@jsftemplating.java.net

Re: JSFTemplating: review request

From: Senthil Chidambaram <cchidamb_at_sun.com>
Date: Wed, 07 Mar 2007 15:36:01 -0800

The value is, let us say each page wants to be encoded differently, one
screen UTF-8, another ISO-8859 etc. then this handler is useful.

thx
Senthil

Anissa Lam wrote:

> Senthil Chidambaram wrote:
>
>> Anissa
>> setEncoding is just a handler method like any other handler method
>> we're using. You can store the output in a pagesession, or attribute,
>> or what ever.
>
> Then why does a user need to go through the handler ? They know
> exactly the value and the scope to set it.
> Instead of doing setEncoding(value="UTF-8"
> value=>$pageAttribute{myEncode});
> they can easily do
> setPageSessionAttribute(key="myEncode" value="UTF-8");
>
> Also, this handler has nothing related to Encoding at all.
> I just don't see the value of this handler. But if you think there is
> a need for this, thats fine.
> Please check in the code, thanks for fixing the issue.
>
> thanks
> Anissa.
>
>> I've added this for page level encoding type set in case if necessary
>> for any other application using jsftemplating. In our case I prefer
>> we use app level encoding type, bcz it's going to be UTF-8 anyway.
>> This is what our localization team folks want. We never use this
>> handler.
>>
>> What we're going to use is set the encoding type in our web.xml, and
>> use it for our entire app. You should look at the utildiff I've sent
>> you earlier.
>>
>> Is Ken aware Hmm... :-) ... part of it. We had a discussion
>> last week on app level, page level etc., we ended it up on using page
>> level encoding using the handler you've reviewed. I thought it's
>> better to use app level at least for our use case, otherwise we've to
>> go, and add this handler in every jsf file. I think Ken should be fine.
>>
>> I'm attaching my web.xml also, look at the ENCODING_TYPE parameter
>> I've added.
>>
>> thx
>> Senthil
>>
>> Anissa Lam wrote:
>>
>>> Hi Senthil,
>>> Regarding the priority of encoding type, is Ken aware of this ?
>>> For setEncoding() in UtilHandlers.java,
>>> It doesn't seem to do anything, just get the input and then set it
>>> to the output. Is this what it really should do ? I am confused.
>>>
>>> + public static void setEncoding(HandlerContext context) {
>>> + String value = (String) context.getInputValue("value");
>>> + context.setOutputValue("value", value);
>>> + }
>>>
>>>
>>> thanks
>>> Anissa
>>>
>>>
>>> Senthil Chidambaram wrote:
>>>
>>>> I'm attaching the diffs for three files LayoutViewHandler.java,
>>>> Util.java, and UtilHanlders.java which takes care of setting
>>>> encoding type, and client locale.
>>>>
>>>> This is the logic I'm using if an app level encoding type is set
>>>> use it, if not look for page level encoding type, then try client
>>>> encoding type, and finally hard coding it to UTF-8.
>>>>
>>>> You can see the above logic in utildiff file, and the handler
>>>> method I've added to set page level encoding type is in
>>>> handlersdiff. LayoutViewHandlerdiff is where the page is being
>>>> served to the client.
>>>>
>>>> P.S: I know Ken is off, but I would appreciate if you any one of
>>>> you could review it, and let me know. I can checkin the changes.
>>>>
>>>> ------------------------------------------------------------------------
>>>>
>>>>
>>>> Index: LayoutViewHandler.java
>>>> ===================================================================
>>>> RCS file:
>>>> /cvs/jsftemplating/src/java/com/sun/jsftemplating/layout/LayoutViewHandler.java,v
>>>>
>>>> retrieving revision 1.19
>>>> diff -c -r1.19 LayoutViewHandler.java
>>>> *** LayoutViewHandler.java 1 Mar 2007 04:41:50 -0000 1.19
>>>> --- LayoutViewHandler.java 7 Mar 2007 22:01:30 -0000
>>>> ***************
>>>> *** 514,526 ****
>>>> contentTypeList = "text/html;q=1.0";
>>>> }
>>>> }
>>>> ! String encType = request.getCharacterEncoding();
>>>> ! if(encType != null && encType.length() > 0) {
>>>> ! response.setCharacterEncoding(encType);
>>>> ! }
>>>> ! else {
>>>> ! response.setCharacterEncoding("UTF-8");
>>>> }
>>>>
>>>> // FIXME: Portlet?
>>>> writer =
>>>> --- 514,527 ----
>>>> contentTypeList = "text/html;q=1.0";
>>>> }
>>>> }
>>>> ! String encType = Util.getEncoding(context);
>>>> ! if(encType == null) {
>>>> ! encType = request.getCharacterEncoding();
>>>> ! if(encType == null) {
>>>> ! encType="UTF-8";
>>>> ! } }
>>>> + response.setCharacterEncoding(encType);
>>>>
>>>> // FIXME: Portlet?
>>>> writer =
>>>>
>>>>
>>>> ------------------------------------------------------------------------
>>>>
>>>>
>>>> Index: Util.java
>>>> ===================================================================
>>>> RCS file:
>>>> /cvs/jsftemplating/src/java/com/sun/jsftemplating/util/Util.java,v
>>>> retrieving revision 1.6
>>>> diff -c -r1.6 Util.java
>>>> *** Util.java 16 Nov 2006 19:22:33 -0000 1.6
>>>> --- Util.java 7 Mar 2007 22:02:45 -0000
>>>> ***************
>>>> *** 29,34 ****
>>>> --- 29,36 ----
>>>> import javax.faces.component.UIViewRoot;
>>>> import javax.faces.context.FacesContext;
>>>>
>>>> + import com.sun.jsftemplating.el.PageSessionResolver;
>>>> + /**
>>>> * <p> This class is for general purpose utility methods.</p>
>>>> ***************
>>>> *** 97,102 ****
>>>> --- 99,122 ----
>>>> // Return the result
>>>> return props;
>>>> }
>>>> + /**
>>>> + * <p> Help obtain the current encoding type.</p>
>>>> + */
>>>> + + public static String getEncoding(FacesContext ctx) {
>>>> + String encType = null;
>>>> + if (ctx != null) {
>>>> + encType =
>>>> ctx.getExternalContext().getInitParameter("ENCODING_TYPE");
>>>> + if(encType == null) {
>>>> + UIViewRoot root = ctx.getViewRoot();
>>>> + Map map = PageSessionResolver.getPageSession(ctx,
>>>> root);
>>>> + if(map != null) {
>>>> + encType = (String)map.get("encoding");
>>>> + }
>>>> + }
>>>> + }
>>>> + return encType;
>>>> + }
>>>>
>>>> /**
>>>> * <p> Help obtain the current <code>Locale</code>.</p>
>>>>
>>>>
>>>> ------------------------------------------------------------------------
>>>>
>>>>
>>>> Index: UtilHandlers.java
>>>> ===================================================================
>>>> RCS file:
>>>> /cvs/jsftemplating/src/java/com/sun/jsftemplating/handlers/UtilHandlers.java,v
>>>>
>>>> retrieving revision 1.14
>>>> diff -c -r1.14 UtilHandlers.java
>>>> *** UtilHandlers.java 6 Nov 2006 08:53:50 -0000 1.14
>>>> --- UtilHandlers.java 7 Mar 2007 22:03:01 -0000
>>>> ***************
>>>> *** 374,379 ****
>>>> --- 374,396 ----
>>>> }
>>>>
>>>> /**
>>>> + * <p> This handler sets the encoding type of the given
>>>> UIComponent's
>>>> + * attribute map.</p>
>>>> + *
>>>> + * @param context The HandlerContext.
>>>> + */
>>>> + @Handler(id="setEncoding",
>>>> + input={
>>>> + @HandlerInput(name="value", type=String.class)
>>>> + },
>>>> + output={
>>>> + @HandlerOutput(name="value", type=String.class)})
>>>> + public static void setEncoding(HandlerContext context) {
>>>> + String value = (String) context.getInputValue("value");
>>>> + context.setOutputValue("value", value);
>>>> + }
>>>> + + /**
>>>> * <p> This handler prints out the contents of the given
>>>> UIComponent's
>>>> * attribute map.</p>
>>>> *
>>>>
>>>>
>>>
>>
>> ------------------------------------------------------------------------
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web
>> Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
>> <web-app>
>> <context-param>
>> <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
>> <param-value>server</param-value>
>> </context-param>
>> <context-param>
>> <param-name>com.sun.webui.jsf.DEFAULT_THEME</param-name>
>> <param-value>suntheme</param-value>
>> </context-param>
>> <context-param>
>> <param-name>javax.faces.CONFIG_FILES</param-name>
>> <param-value>/WEB-INF/jbi-faces-config.xml</param-value>
>> </context-param>
>> <context-param>
>> <param-name>com.sun.jsftemplating.DEBUG</param-name>
>> <param-value>true</param-value>
>> </context-param>
>> <context-param>
>> <param-name>ENCODING_TYPE</param-name>
>> <param-value>UTF-8</param-value>
>> </context-param>
>> <filter>
>> <filter-name>HelpWindowFilter</filter-name>
>>
>> <filter-class>com.sun.enterprise.tools.admingui.servlet.HelpWindowFilter</filter-class>
>>
>> </filter>
>> <filter>
>> <filter-name>UploadFilter</filter-name>
>>
>> <filter-class>com.sun.webui.jsf.util.UploadFilter</filter-class>
>> <init-param>
>> <param-name>maxSize</param-name>
>> <param-value>100000000</param-value>
>> </init-param>
>> <!--
>> <init-param>
>> <param-name>tmpDir</param-name>
>> <param-value>/export/home</param-value>
>> </init-param>
>> -->
>> </filter>
>> <filter-mapping>
>> <filter-name>UploadFilter</filter-name>
>> <servlet-name>FacesServlet</servlet-name>
>> </filter-mapping>
>> <filter-mapping>
>> <filter-name>HelpWindowFilter</filter-name>
>>
>> <url-pattern>/com_sun_webui_jsf/help/helpwindow.jsf</url-pattern>
>> </filter-mapping>
>> <servlet>
>> <servlet-name>FacesServlet</servlet-name>
>> <servlet-class>com.sun.enterprise.tools.admingui.servlet.DelayedInitFacesServlet</servlet-class>
>>
>> <!-- For Dynamic Faces: -->
>> <init-param>
>> <param-name>javax.faces.LIFECYCLE_ID</param-name>
>> <param-value>com.sun.faces.lifecycle.PARTIAL</param-value>
>> </init-param>
>> </servlet>
>> <servlet>
>> <servlet-name>ThemeServlet</servlet-name>
>> <!--
>> <servlet-class>com.sun.rave.web.ui.theme.ThemeServlet</servlet-class>
>> -->
>> <!--
>> <servlet-class>com.sun.web.ui.theme.ThemeServlet</servlet-class> -->
>> <servlet-class>com.sun.webui.theme.ThemeServlet</servlet-class>
>> </servlet>
>> <servlet>
>> <servlet-name>DownloadServlet</servlet-name>
>> <servlet-class>com.sun.enterprise.tools.admingui.servlet.DownloadServlet</servlet-class>
>>
>> <init-param>
>> <param-name>ContentSources</param-name>
>> <param-value>
>>
>> com.sun.enterprise.tools.admingui.servlet.ClientStubsContentSource
>>
>> com.sun.enterprise.tools.admingui.servlet.DiagnosticReportContentSource
>>
>> com.sun.enterprise.tools.admingui.servlet.LBConfigContentSource
>> com.sun.enterprise.tools.admingui.servlet.LockhartContentSource
>> </param-value>
>> </init-param>
>> <init-param>
>> <param-name>contentSourceId</param-name>
>> <param-value>Lockhart</param-value>
>> </init-param>
>> </servlet>
>> <servlet-mapping>
>> <servlet-name>DownloadServlet</servlet-name>
>> <url-pattern>/download/*</url-pattern>
>> </servlet-mapping>
>> <servlet-mapping>
>> <servlet-name>DownloadServlet</servlet-name>
>> <url-pattern>/html/*</url-pattern>
>> </servlet-mapping>
>> <servlet-mapping>
>> <servlet-name>FacesServlet</servlet-name>
>> <url-pattern>*.jsf</url-pattern>
>> </servlet-mapping>
>> <servlet-mapping>
>> <servlet-name>FacesServlet</servlet-name>
>> <url-pattern>/resource/*</url-pattern>
>> </servlet-mapping>
>>
>> <servlet-mapping>
>> <servlet-name>ThemeServlet</servlet-name>
>> <url-pattern>/theme/*</url-pattern>
>> </servlet-mapping>
>>
>> <welcome-file-list>
>> <welcome-file>index.jsf</welcome-file>
>> </welcome-file-list>
>> <security-constraint>
>> <web-resource-collection>
>> <web-resource-name>build</web-resource-name>
>> <url-pattern>*.jsf</url-pattern>
>> <http-method>DELETE</http-method>
>> <http-method>GET</http-method>
>> <http-method>POST</http-method>
>> <http-method>PUT</http-method>
>> </web-resource-collection>
>> <auth-constraint>
>> <role-name>admin</role-name>
>> </auth-constraint>
>> </security-constraint>
>> <login-config>
>> <auth-method>FORM</auth-method>
>> <realm-name>admin-realm</realm-name>
>> <form-login-config>
>> <form-login-page>/login.jsf</form-login-page>
>> <form-error-page>/loginError.jsf</form-error-page>
>> </form-login-config>
>> </login-config>
>> <security-role>
>> <role-name>admin</role-name>
>> </security-role>
>> </web-app>
>>
>