Re: Modifying XHTML through a filter
Hi David, thanks for the hint. I think for my case it is better to make the modification manually because there is not much to do. But generally it would be a big help to use a framework like htmltidy. Best regards, Rudi On 5/2/07, David Delbecq [EMAIL PROTECTED] wrote: Correct me if i am wrong, but ajax4jsf already has a filter that corrects html responses to make them xhtml compliant (and then parseable by xmlHttpRequest client side) http://labs.jboss.com/file-access/default/members/jbossajax4jsf/freezone/docs/devguide/FAQ.html#FilterUsageDamagesAnApplicationLayout En l'instant précis du 02/05/07 10:53, Rudi Steiner s'exprimait en ces termes: Hi Jonathan, thank you for your answer. This is exactly the way to resolve the problem. A howto can be found here: http://www.javaworld.com/javaworld/jw-08-2003/jw-0829-designpatterns.html?page=2 I know that modifying the generated markup this way is not recommended by software engineers ;) but I lost a lot of time on this topic and I think this is the fastest way. After this discussion: http://www.nabble.com/XHTML-Strict-tf3582852.html, i decided to do this. I'm not a developer, so I hope that someone is reading this mailings and take this discussion as an input for further improvements. I think that one of the primary objectives of a web framework like myFaces should be, to generate standard conform markup. No component should be integrated in a official release, if it dosn't generate clean markup. At the moment, myFaces is neither XHTML nor HTML 4.01 conform. Best regards, Rudi On 4/27/07, Jonathan Harley [EMAIL PROTECTED] wrote: Rudi Steiner wrote: I have still the problem with the generated XHTML from myFaces. I reduced my app to a few basic mechanisms, but this basic mechanisms must produce XHTML strict. To achieve this, i would like to wirte a filter, which makes light modifications of the generated markup, just to satisfy the validator. For example, I would surround a hidden field, generated by myFaces with a div/-Tag. Could anyone please give me a hint how to achieve this. I tried it with regular expressions but I think, it is not possible to work with RE on OutputStreams. You'd have to buffer the output and work on that - I think this is what the MyFaces Extensions filter does too. This is easily done in servlet filters, because each filter passes the request and response objects down the chain, which are then used by everything downstream of your filter. If instead of passing on the same response that you received, you pass on a decorated (enhanced) response, which overrides getOutputStream() and getWriter(), you can give everyone else something which looks like an OutputStream or PrintWriter but actually just captures everything to a buffer. You can then manipulate the buffer as you wish. Fixing MyFaces to generate compliant XHTML in the first place would be a much better solution though, because otherwise you'll probably have to update this filter every time MyFaces or Tomahawk are updated. MyFaces may have to generate HTML 4 to pass the TCK, but what about a context-param setting to switch on strict XHTML markup generation? It presumably wouldn't affect very many things anyway. Jonathan. -- . Dr Jonathan Harley . . Email: [EMAIL PROTECTED] Zac Parkplatz Ltd . Office Telephone: 024 7633 1375 www.parkplatz.net . Mobile: 079 4116 0423
Re: Modifying XHTML through a filter
Hi Jonathan, thank you for your answer. This is exactly the way to resolve the problem. A howto can be found here: http://www.javaworld.com/javaworld/jw-08-2003/jw-0829-designpatterns.html?page=2 I know that modifying the generated markup this way is not recommended by software engineers ;) but I lost a lot of time on this topic and I think this is the fastest way. After this discussion: http://www.nabble.com/XHTML-Strict-tf3582852.html, i decided to do this. I'm not a developer, so I hope that someone is reading this mailings and take this discussion as an input for further improvements. I think that one of the primary objectives of a web framework like myFaces should be, to generate standard conform markup. No component should be integrated in a official release, if it dosn't generate clean markup. At the moment, myFaces is neither XHTML nor HTML 4.01 conform. Best regards, Rudi On 4/27/07, Jonathan Harley [EMAIL PROTECTED] wrote: Rudi Steiner wrote: I have still the problem with the generated XHTML from myFaces. I reduced my app to a few basic mechanisms, but this basic mechanisms must produce XHTML strict. To achieve this, i would like to wirte a filter, which makes light modifications of the generated markup, just to satisfy the validator. For example, I would surround a hidden field, generated by myFaces with a div/-Tag. Could anyone please give me a hint how to achieve this. I tried it with regular expressions but I think, it is not possible to work with RE on OutputStreams. You'd have to buffer the output and work on that - I think this is what the MyFaces Extensions filter does too. This is easily done in servlet filters, because each filter passes the request and response objects down the chain, which are then used by everything downstream of your filter. If instead of passing on the same response that you received, you pass on a decorated (enhanced) response, which overrides getOutputStream() and getWriter(), you can give everyone else something which looks like an OutputStream or PrintWriter but actually just captures everything to a buffer. You can then manipulate the buffer as you wish. Fixing MyFaces to generate compliant XHTML in the first place would be a much better solution though, because otherwise you'll probably have to update this filter every time MyFaces or Tomahawk are updated. MyFaces may have to generate HTML 4 to pass the TCK, but what about a context-param setting to switch on strict XHTML markup generation? It presumably wouldn't affect very many things anyway. Jonathan. -- . Dr Jonathan Harley . . Email: [EMAIL PROTECTED] Zac Parkplatz Ltd . Office Telephone: 024 7633 1375 www.parkplatz.net . Mobile: 079 4116 0423
Re: Modifying XHTML through a filter
Correct me if i am wrong, but ajax4jsf already has a filter that corrects html responses to make them xhtml compliant (and then parseable by xmlHttpRequest client side) http://labs.jboss.com/file-access/default/members/jbossajax4jsf/freezone/docs/devguide/FAQ.html#FilterUsageDamagesAnApplicationLayout En l'instant précis du 02/05/07 10:53, Rudi Steiner s'exprimait en ces termes: Hi Jonathan, thank you for your answer. This is exactly the way to resolve the problem. A howto can be found here: http://www.javaworld.com/javaworld/jw-08-2003/jw-0829-designpatterns.html?page=2 I know that modifying the generated markup this way is not recommended by software engineers ;) but I lost a lot of time on this topic and I think this is the fastest way. After this discussion: http://www.nabble.com/XHTML-Strict-tf3582852.html, i decided to do this. I'm not a developer, so I hope that someone is reading this mailings and take this discussion as an input for further improvements. I think that one of the primary objectives of a web framework like myFaces should be, to generate standard conform markup. No component should be integrated in a official release, if it dosn't generate clean markup. At the moment, myFaces is neither XHTML nor HTML 4.01 conform. Best regards, Rudi On 4/27/07, Jonathan Harley [EMAIL PROTECTED] wrote: Rudi Steiner wrote: I have still the problem with the generated XHTML from myFaces. I reduced my app to a few basic mechanisms, but this basic mechanisms must produce XHTML strict. To achieve this, i would like to wirte a filter, which makes light modifications of the generated markup, just to satisfy the validator. For example, I would surround a hidden field, generated by myFaces with a div/-Tag. Could anyone please give me a hint how to achieve this. I tried it with regular expressions but I think, it is not possible to work with RE on OutputStreams. You'd have to buffer the output and work on that - I think this is what the MyFaces Extensions filter does too. This is easily done in servlet filters, because each filter passes the request and response objects down the chain, which are then used by everything downstream of your filter. If instead of passing on the same response that you received, you pass on a decorated (enhanced) response, which overrides getOutputStream() and getWriter(), you can give everyone else something which looks like an OutputStream or PrintWriter but actually just captures everything to a buffer. You can then manipulate the buffer as you wish. Fixing MyFaces to generate compliant XHTML in the first place would be a much better solution though, because otherwise you'll probably have to update this filter every time MyFaces or Tomahawk are updated. MyFaces may have to generate HTML 4 to pass the TCK, but what about a context-param setting to switch on strict XHTML markup generation? It presumably wouldn't affect very many things anyway. Jonathan. -- . Dr Jonathan Harley . . Email: [EMAIL PROTECTED] Zac Parkplatz Ltd . Office Telephone: 024 7633 1375 www.parkplatz.net . Mobile: 079 4116 0423
Re: Modifying XHTML through a filter
Rudi, The Tomahawk Extensions filter does something similar -- it modifies the generated html. I'd recommend using it as a model for changing the generated xhtml. On 4/27/07, Rudi Steiner [EMAIL PROTECTED] wrote: Hi, I have still the problem with the generated XHTML from myFaces. I reduced my app to a few basic mechanisms, but this basic mechanisms must produce XHTML strict. To achieve this, i would like to wirte a filter, which makes light modifications of the generated markup, just to satisfy the validator. For example, I would surround a hidden field, generated by myFaces with a div/-Tag. Could anyone please give me a hint how to achieve this. I tried it with regular expressions but I think, it is not possible to work with RE on OutputStreams. Thank you, Rudi
Re: Modifying XHTML through a filter
Rudi Steiner wrote: I have still the problem with the generated XHTML from myFaces. I reduced my app to a few basic mechanisms, but this basic mechanisms must produce XHTML strict. To achieve this, i would like to wirte a filter, which makes light modifications of the generated markup, just to satisfy the validator. For example, I would surround a hidden field, generated by myFaces with a div/-Tag. Could anyone please give me a hint how to achieve this. I tried it with regular expressions but I think, it is not possible to work with RE on OutputStreams. You'd have to buffer the output and work on that - I think this is what the MyFaces Extensions filter does too. This is easily done in servlet filters, because each filter passes the request and response objects down the chain, which are then used by everything downstream of your filter. If instead of passing on the same response that you received, you pass on a decorated (enhanced) response, which overrides getOutputStream() and getWriter(), you can give everyone else something which looks like an OutputStream or PrintWriter but actually just captures everything to a buffer. You can then manipulate the buffer as you wish. Fixing MyFaces to generate compliant XHTML in the first place would be a much better solution though, because otherwise you'll probably have to update this filter every time MyFaces or Tomahawk are updated. MyFaces may have to generate HTML 4 to pass the TCK, but what about a context-param setting to switch on strict XHTML markup generation? It presumably wouldn't affect very many things anyway. Jonathan. -- . Dr Jonathan Harley . . Email: [EMAIL PROTECTED] Zac Parkplatz Ltd . Office Telephone: 024 7633 1375 www.parkplatz.net . Mobile: 079 4116 0423