RE: Converting struts-html tags to be XHTML-compliant
I got this to work, thanks. However, I was not able to follow Martin's advice and do the following comparison: if (xhtml != null (xhtml == Boolean.TRUE)) I had to do the following: if (xhtml != null xhtml.booleanValue()) Just an FYI... Thanks, Matt -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Monday, November 12, 2001 6:59 PM To: Struts Developers List; [EMAIL PROTECTED] Subject: RE: Converting struts-html tags to be XHTML-compliant What you're seeing is probably a result of cache updating issues. I don't recall the exact details, but I believe there are documented (in the JSP spec) points where various caches are updated, and you're most likely falling foul of this. To avoid problems, you should set the attribute using: pageContext.setAttribute(Constants.XHTML_KEY, new Boolean(xhtml), PageContext.REQUEST_SCOPE); and retrieve it using: pageContext.getAttribute(Constants.XHTML_KEY, PageContext.REQUEST_SCOPE); Also, in the doEndTag() method of HtmlTag, you should remove it using: pageContext.removeAttribute(Constants.XHTML_KEY, PageContext.REQUEST_SCOPE); Note that I used Constants.XHTML_KEY in the above - the constant value for this should be in class org.apache.struts.taglib.html.Constants. -- Martin Cooper At 03:56 PM 11/12/01, Matt Raible wrote: So based on Hal (and Martin's advice), I have attempted to implement the following: in HtmlTag.java, added to end of doStartTag() method: // Get the request from the page context HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); // Set the XHTML attribute request.setAttribute(Action.XHTML_KEY, new Boolean(xhtml)); and after adding System.out.println's, I know this is getting set correctly. HOWEVER, in the FormTag, where I'm trying to grab this attribute, it's not working at all: // Get the request from the page context HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); Boolean xhtml = (Boolean) request.getAttribute(Action.XHTML_KEY); If I print the xhtml value in FormTag, it's null. This all seems like pretty straight forward stuff, so don't know why it's not working. Do I have to do something like pageContext.setAttribute(name, obj, PageContext.REQUEST_SCOPE)? This doesn't seem to work either? Thanks guys, Matt -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Monday, November 12, 2001 4:03 PM To: Struts Developers List Subject: Re: Converting struts-html tags to be XHTML-compliant Using findAncestorWithClass() is tempting, because it's simple and clean. However, it causes problems with included pages, because it doesn't work across page boundaries. Using page context has a similar problem, as Hal Deadman points out. Prior to Struts 1.0, Struts used to use page context (I don't know if it ever used findAncestorWithClass()). However, that was changed to use request context, to avoid the issues described above. Particularly since this is going to be a property of the outermost (X)HTML tag, I would encourage the use of request scope, for maximum flexibility. Something else I would recommend is that the property tested by other tags (i.e. the request attribute) be a Boolean instead of a String. Then you can use Boolean.TRUE and Boolean.FALSE objects, compare them directly using '==', and avoid costly string conversions. Finally, I don't believe there's a need for an HtmlTei class. That should eliminate the source of the problem you're having. ;-) -- Martin Cooper At 01:57 PM 11/12/01, Craig R. McClanahan wrote: On Sun, 11 Nov 2001, Matt Raible wrote: Date: Sun, 11 Nov 2001 22:00:40 -0700 From: Matt Raible [EMAIL PROTECTED] Reply-To: Struts Developers List [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: Converting struts-html tags to be XHTML-compliant I am taking on the project of converting (with backwards compatibility) all the struts-html tags to be XHTML-compliant. Matt, THANK YOU for taking this on. I've got a suggestion for a slightly different implementation approach. It would go something like this: * Implement xhtml as a boolean property of the HtmlTag class. * In subordinate tags that need to know the current setting, use the findAncestorWithClass() method of the TagSupport class (which all the Struts tags implement) to walk back through the tag hierarchy nesting to locate the surrounding html:html tag (if there is one). Alternatively, you can walk the chain yourself with getParent(). This is similar to the technique used by things like the html:text tag to find their surrounding html:form tag, and avoids polluting the attribute namespace for what is really a low-level presentation detail. In typical use, I'd bet that it even has better performance than the HashMap put
Re: Converting struts-html tags to be XHTML-compliant (Ready toPost)
The preferred format is usually that produced by 'cvs diff -u'. Personally, I'd rather see the current example left intact as an HTML example. As for adding an XHTML version, the main problem I see is keeping the two in sync. Perhaps some documentation on what has to change in converting from HTML to XHTML (Transitional/Strict) would be a good idea? Of course, you're welcome to post an XHTML version of the example, and I'm sure Ted would link to it from his Struts page (as would the Struts Resources page when it gets updated). -- Martin Cooper - Original Message - From: Matt Raible [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, November 13, 2001 9:54 AM Subject: RE: Converting struts-html tags to be XHTML-compliant (Ready to Post) I've completed this task, and can hopefully post today. Do you just need diffs or files and diffs? It's quite a few files (14). Also, I've converted the example application to be XHTML 1.0 Transitional compliant. I would attempt to convert to XHTML 1.0 Strict, but seems like a lot of work there (must remove all things that can be controlled with CSS). Should I post this example app as a separate application, or do you want to update the existing version in CVS? Thanks, Matt -Original Message- From: Matt Raible [mailto:[EMAIL PROTECTED]] Sent: Tuesday, November 13, 2001 9:35 AM To: Struts Developers List Subject: RE: Converting struts-html tags to be XHTML-compliant I got this to work, thanks. However, I was not able to follow Martin's advice and do the following comparison: if (xhtml != null (xhtml == Boolean.TRUE)) I had to do the following: if (xhtml != null xhtml.booleanValue()) Just an FYI... Thanks, Matt -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Monday, November 12, 2001 6:59 PM To: Struts Developers List; [EMAIL PROTECTED] Subject: RE: Converting struts-html tags to be XHTML-compliant What you're seeing is probably a result of cache updating issues. I don't recall the exact details, but I believe there are documented (in the JSP spec) points where various caches are updated, and you're most likely falling foul of this. To avoid problems, you should set the attribute using: pageContext.setAttribute(Constants.XHTML_KEY, new Boolean(xhtml), PageContext.REQUEST_SCOPE); and retrieve it using: pageContext.getAttribute(Constants.XHTML_KEY, PageContext.REQUEST_SCOPE); Also, in the doEndTag() method of HtmlTag, you should remove it using: pageContext.removeAttribute(Constants.XHTML_KEY, PageContext.REQUEST_SCOPE); Note that I used Constants.XHTML_KEY in the above - the constant value for this should be in class org.apache.struts.taglib.html.Constants. -- Martin Cooper At 03:56 PM 11/12/01, Matt Raible wrote: So based on Hal (and Martin's advice), I have attempted to implement the following: in HtmlTag.java, added to end of doStartTag() method: // Get the request from the page context HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); // Set the XHTML attribute request.setAttribute(Action.XHTML_KEY, new Boolean(xhtml)); and after adding System.out.println's, I know this is getting set correctly. HOWEVER, in the FormTag, where I'm trying to grab this attribute, it's not working at all: // Get the request from the page context HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); Boolean xhtml = (Boolean) request.getAttribute(Action.XHTML_KEY); If I print the xhtml value in FormTag, it's null. This all seems like pretty straight forward stuff, so don't know why it's not working. Do I have to do something like pageContext.setAttribute(name, obj, PageContext.REQUEST_SCOPE)? This doesn't seem to work either? Thanks guys, Matt -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Monday, November 12, 2001 4:03 PM To: Struts Developers List Subject: Re: Converting struts-html tags to be XHTML-compliant Using findAncestorWithClass() is tempting, because it's simple and clean. However, it causes problems with included pages, because it doesn't work across page boundaries. Using page context has a similar problem, as Hal Deadman points out. Prior to Struts 1.0, Struts used to use page context (I don't know if it ever used findAncestorWithClass()). However, that was changed to use request context, to avoid the issues described above. Particularly since this is going to be a property of the outermost (X)HTML tag, I would encourage the use of request scope, for maximum flexibility. Something else I would recommend is that the property tested by other tags (i.e. the request attribute) be a Boolean instead of a String. Then you can use Boolean.TRUE
Re: Converting struts-html tags to be XHTML-compliant
On Sun, 11 Nov 2001, Matt Raible wrote: Date: Sun, 11 Nov 2001 22:00:40 -0700 From: Matt Raible [EMAIL PROTECTED] Reply-To: Struts Developers List [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: Converting struts-html tags to be XHTML-compliant I am taking on the project of converting (with backwards compatibility) all the struts-html tags to be XHTML-compliant. Matt, THANK YOU for taking this on. I've got a suggestion for a slightly different implementation approach. It would go something like this: * Implement xhtml as a boolean property of the HtmlTag class. * In subordinate tags that need to know the current setting, use the findAncestorWithClass() method of the TagSupport class (which all the Struts tags implement) to walk back through the tag hierarchy nesting to locate the surrounding html:html tag (if there is one). Alternatively, you can walk the chain yourself with getParent(). This is similar to the technique used by things like the html:text tag to find their surrounding html:form tag, and avoids polluting the attribute namespace for what is really a low-level presentation detail. In typical use, I'd bet that it even has better performance than the HashMap put and get that is required for page attributes. Craig I'd like to use this e-mail to tell you my approach, ask you for advice, and get your feedback. 1. Approach: In HtmlTag.java, add if (xhtml) pageContext.setAttribute(xhtml, true); In all other html-producing tags (i.e. img, input), do a check when closing the tag: // check if this is an XHTML document String xhtml = (String) pageContext.getAttribute(xhtml); if (xhtml != null xhtml.equals(true)) { results.append(\ /); // extra space before close will allow XHTML to work in older browsers } else { results.append(\); } 2. Advice: Should I be setting the xhtml variable in the pageContext, request, or session. Page seems to make the most sense since that is what this variable relates to. However, to do this (to my understanding), I have to create HtmlTei.java and add the teiclass declaration to the struts-html.tld: public class HtmlTei extends TagExtraInfo { /** * Return information about the scripting variables to be created. */ public VariableInfo[] getVariableInfo(TagData data) { return new VariableInfo[] { new VariableInfo(data.getAttributeString(xhtml), java.lang.String, true, VariableInfo.NESTED) }; } } However, this does not work as I'd expect it to. What I'm expecting is that I am exposing the xhtml variable simply by adding the HtmlTei class - but it's not working at all. 3. Feedback: Please let me know what you think of this approach. By doing this, and adding a check if the user wants the doc to be XHTML, we should achieve full backwards compatibility, and be able to convert the struts-html tags to be XHTML-compliant. Thanks, Matt -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
RE: Converting struts-html tags to be XHTML-compliant
I would think request scope would be better than pageContext so the attribute will be available inside jsp:include or template/component includes. -Original Message- From: Matt Raible [mailto:[EMAIL PROTECTED]] Sent: Monday, November 12, 2001 12:01 AM To: [EMAIL PROTECTED] Subject: Converting struts-html tags to be XHTML-compliant I am taking on the project of converting (with backwards compatibility) all the struts-html tags to be XHTML-compliant. I'd like to use this e-mail to tell you my approach, ask you for advice, and get your feedback. 1. Approach: In HtmlTag.java, add if (xhtml) pageContext.setAttribute(xhtml, true); In all other html-producing tags (i.e. img, input), do a check when closing the tag: // check if this is an XHTML document String xhtml = (String) pageContext.getAttribute(xhtml); if (xhtml != null xhtml.equals(true)) { results.append(\ /); // extra space before close will allow XHTML to work in older browsers } else { results.append(\); } 2. Advice: Should I be setting the xhtml variable in the pageContext, request, or session. Page seems to make the most sense since that is what this variable relates to. However, to do this (to my understanding), I have to create HtmlTei.java and add the teiclass declaration to the struts-html.tld: public class HtmlTei extends TagExtraInfo { /** * Return information about the scripting variables to be created. */ public VariableInfo[] getVariableInfo(TagData data) { return new VariableInfo[] { new VariableInfo(data.getAttributeString(xhtml), java.lang.String, true, VariableInfo.NESTED) }; } } However, this does not work as I'd expect it to. What I'm expecting is that I am exposing the xhtml variable simply by adding the HtmlTei class - but it's not working at all. 3. Feedback: Please let me know what you think of this approach. By doing this, and adding a check if the user wants the doc to be XHTML, we should achieve full backwards compatibility, and be able to convert the struts-html tags to be XHTML-compliant. Thanks, Matt -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]