dev@jsftemplating.java.net

Re: JSFTemplating: review request

From: Senthil Chidambaram <cchidamb_at_sun.com>
Date: Wed, 07 Mar 2007 14:57:49 -0800

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. 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>
>> *
>>
>>
>