Bug 358114 - Formatting XHTML file clears closing brace of Expression Language
Summary: Formatting XHTML file clears closing brace of Expression Language
Status: REOPENED
Alias: None
Product: Java Server Faces
Classification: WebTools
Component: Core (show other bugs)
Version: 3.4.0   Edit
Hardware: PC Windows 7
: P2 normal with 2 votes (vote)
Target Milestone: Future   Edit
Assignee: Nitin Dahyabhai CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2011-09-19 09:09 EDT by Mohsen Saboorian CLA
Modified: 2019-10-13 23:08 EDT (History)
10 users (show)

See Also:


Attachments
Reproduction of bug in Mars (352.81 KB, application/x-shockwave-flash)
2016-08-05 02:07 EDT, Vytenis Bivainis CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mohsen Saboorian CLA 2011-09-19 09:09:34 EDT
1. Create a XHTML file.
2. Copy the following in the file:
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets">
    <div style="text-align: #{bundle['something']}"></div>
</ui:composition>

3. Reformat (Ctrl+Shift+F).

The end brace after ['something'] is removed, resulting in:
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets">
    <div style="text-align: #{bundle['something']"></div>
</ui:composition>


-- Configuration Details --
Product: Eclipse 1.4.0.20110609-1120 (org.eclipse.epp.package.jee.product)
Installed Features:
 org.eclipse.platform 3.7.0.v20110530-9gF7UHNFFt4cwE-pkZDJ7oz-mj4OSEIlu9SEv0f
Comment 1 Nick Sandonato CLA 2011-09-19 16:24:11 EDT
Hi Raghu,

I'm not familiar with if JSF has its own formatter for facelet files. If so, would it be possible for the formatter to remove this EL before running the formatter and swap it back after formatting? Something along the lines of creating a new CSS document where the EL is filled in by placeholders that don't have syntax constructs from CSS and using the formatter there. The problem is that the braces from the EL have syntactical meaning for CSS. These get interpreted incorrectly by the CSS Model resulting in the missing brace after formatting. This occurs because the CSS formatter executes on this malformed node within the style attribute.

I don't think we'll be able to correct the CSS tokenizer or model in any meaningful way and we don't want to incorporate any knowledge of EL into the HTML formatter.
Comment 2 Mohsen Saboorian CLA 2011-10-05 03:00:55 EDT
Any quick workaround? This is really annoying and causes many troubles when writing xhtml codes. Is this possible to disabled css formatting in xhtml files, or something similar to bypass this issue?
Comment 3 Nick Sandonato CLA 2011-10-05 16:17:31 EDT
(In reply to comment #2)
> Any quick workaround? This is really annoying and causes many troubles when
> writing xhtml codes. Is this possible to disabled css formatting in xhtml
> files, or something similar to bypass this issue?

There's no way, at the moment, to disable CSS formatting within the style attributes. Though, it might seem like something worthwhile to add (or change how we do it). Additionally, JSF might be able to introduce their own formatter that correctly accounts for EL regions within style blocks.

I can't think of any workarounds, unfortunately.
Comment 4 Raghunathan Srinivasan CLA 2011-10-06 19:50:17 EDT
(In reply to comment #1)
> Hi Raghu,
> 
> I'm not familiar with if JSF has its own formatter for facelet files. 

I took a quick look and don't see a formatter in the facelet code.  I don't see this behavior in a JSP file and curious to know the reason.

I do agree that this is a serious issue and should be addressed soon. JSF will take a look. Please move this bug to the JSF project.
Comment 5 Ian Trimble CLA 2011-10-06 20:29:47 EDT
There's certainly a difference between HTML (including XHTML) and JSP (including JSPX) files.

Paste just the div element into a basic JSP file:
 - notice the syntax coloring of the style attribute's value, indicating recognition of the attribute's value region and the EL region within the attribute value
 - notice that reformatting the file *doesn't* reformat the style attribute value (the closing brace is not lost)

Paste just the div element into a basic HTML file:
 - notice the syntax coloring of the style attribute's value, indicating possible failure of correct recognition of the attribute's value region and the EL region within the attribute value
 - notice that reformatting the file *does* reformat the style attribute value (the closing brace is lost)

I'm not sure we fully understand the issue yet, given these differences in basic HTML and JSP recognition and formatting. There is no special handling of formatting for facelets, they are being formatted as any HTML documents will be. More investigation is required.
Comment 6 Nick Sandonato CLA 2011-10-07 11:55:17 EDT
(In reply to comment #5)
> There's certainly a difference between HTML (including XHTML) and JSP
> (including JSPX) files.
> 
> Paste just the div element into a basic JSP file:
>  - notice the syntax coloring of the style attribute's value, indicating
> recognition of the attribute's value region and the EL region within the
> attribute value
>  - notice that reformatting the file *doesn't* reformat the style attribute
> value (the closing brace is not lost)
> 
> Paste just the div element into a basic HTML file:
>  - notice the syntax coloring of the style attribute's value, indicating
> possible failure of correct recognition of the attribute's value region and the
> EL region within the attribute value
>  - notice that reformatting the file *does* reformat the style attribute value
> (the closing brace is lost)
> 
> I'm not sure we fully understand the issue yet, given these differences in
> basic HTML and JSP recognition and formatting. There is no special handling of
> formatting for facelets, they are being formatted as any HTML documents will
> be. More investigation is required.

Thanks for taking a look, Raghu and Ian. So I think the difference is that JSP acknowledges the EL, and so the attribute value region actually becomes an ITextRegionContainer. The HTMLElementFormatter bails on formatting style attributes that are an instanceof ITextRegionContainer because it likely wouldn't be able to be formatted as CSS.
Comment 7 Cameron Bateman CLA 2013-04-19 17:47:44 EDT
I don't think there are resources to handle this case since it appears to mean JSF writing its own formatter.  That's a lot of effort for what seems like a fairly small edge case.  If someone wants to contribute something in this area, please attach and reopen.  Alternatively, if there are many more such edge cases and a significant expression of interest, please reopen and we can consider for a future release.
Comment 8 Mohsen Saboorian CLA 2013-04-20 00:52:04 EDT
(In reply to comment #7)
> I don't think there are resources to handle this case since it appears to
> mean JSF writing its own formatter.  That's a lot of effort for what seems
> like a fairly small edge case.  If someone wants to contribute something in
> this area, please attach and reopen.  Alternatively, if there are many more
> such edge cases and a significant expression of interest, please reopen and
> we can consider for a future release.

Any way to disable formatting of attribute values?
BTW, could you please explain why do you see this as an edge case? It's very common to write and XHTML, and decide formatting of an element using style attribute+EL.
Comment 9 Cameron Bateman CLA 2013-04-22 18:47:44 EDT
> Any way to disable formatting of attribute values?
> BTW, could you please explain why do you see this as an edge case? It's very
> common to write and XHTML, and decide formatting of an element using style
> attribute+EL

Can you provide evidence of how prevalent this case is?  For example, do any popular books or best practice web sites promote doing this?  Are there examples in the wild?  Alternatively, can you get other people to vote on this bug and leave a comment indicating their interest in getting it fixed?
Comment 10 Marc Woerner CLA 2015-02-23 09:51:50 EST
I also run into the same formatting problem with Eclipse Kepler, but I was able to find a workaround for my case.

First I had:

<div style="background-color:#{_node.getColorHex('#f0f0f0')}" />

Then, after formatting the same problem occured:

<div style="background-color:#{_node.getColorHex('#f0f0f0')" />

However, if I use a JSF Tag instead of plain HTML/XHTML then the EL syntax remains valid, even after running the formatter, i.e.:

<h:panelGroup layout="block" style="background-color:#{_node.getColorHex('#f0f0f0')}" />
Comment 11 Joerg Hohwiller CLA 2015-04-30 06:37:10 EDT
Eclipse formatter is still buggy in this area. In case someone cares:
https://github.com/oasp/oasp4j-ide/issues/35

Should I file another bug? Or would you still insist on WONTFIX?
Comment 12 Raghunathan Srinivasan CLA 2015-04-30 13:56:15 EDT
No need to open another bug, yet. We will review and comment here.
Comment 13 Raghunathan Srinivasan CLA 2015-04-30 19:59:20 EDT
As noted in comment 7, a proper fix would require writing a new formatter for JSF. We currently don't have the resource to work on this. I am re-opening the bug, flagging it as 'helpwanted' to invite a contribution to address this issue.
Comment 14 Raghunathan Srinivasan CLA 2015-05-26 18:52:22 EDT
Moving it out of MARS release
Comment 15 Vytenis Bivainis CLA 2016-08-05 02:07:34 EDT
Created attachment 263471 [details]
Reproduction of bug in Mars

There is still a bug in Mars. JSF EL expressions are damaged in various ways, sometimes expression is removed, sometimes curly bracket is removed.
Comment 16 Luigi Labigalini CLA 2018-02-19 21:09:00 EST
Reproduced on:

Version: Oxygen.2 Release (4.7.2)
Build id: 20171218-0600

Sometimes expression is removed, sometimes curly bracket is removed.

before
<div="style="#{cc.attrs.style}">
after
<div="style="">

before
<div="style="height: #{cc.attrs.height}">
after
<div="style="height: #{cc.attrs.height">
Comment 17 Torsten Schrobe CLA 2019-01-28 03:10:54 EST
I am having the same problem where formatting completely removes everything within the style="" tag!

This is super annoying and took me hours to realize it was happening.

I think the code formatter should never _remove_ any of the code but only whitespaces and restructure the rest.
Comment 18 Eclipse Genie CLA 2019-05-30 02:03:50 EDT
New Gerrit change created: https://git.eclipse.org/r/143052
Comment 19 Lakshminarayana CLA 2019-05-30 02:13:47 EDT
(In reply to Eclipse Genie from comment #18)
> New Gerrit change created: https://git.eclipse.org/r/143052

The fix is just workaround. Otherwise, We need to regenerate the jflex grammar for CSS with the latest template. I am not sure how it to be done.