Created attachment 103538 [details]
Sample JSP file formatted incorectly
JSP file formatter does not format the content correctly if the JSP (custom) tag contains any attribute starting with '_'.
This is my observation. Cause may be different. Attached the screen shot of a JSP file after formating
The formatter underlines '_' as error for any attribute starting with underscore.
Marek, can custom tag's attribute name starts with underscore character??
If I am reading the JSP 2.2 spec correctly it says the custom tag's attribute name should be a XML name (XML::Name). The non-normative part of XML spec says XML name can start with underscore.
The problem here is that the JSP custom tags are not recognized properly (would be in bold font if so) hence considered as html code by the editor. And AFAIK html tags' attribute names cannot start with underscore so the html lexer considers then as errors.
I do not have an idea how such situation is handled by the formatting infrastructure. I can just guess it considers the unknown html tags as xml tags and formats accordingly. I also assume the formatter scans the document at lexical level for tags so the broken html tags lexing affects the process significantly.
I can fix the html lexer so the attributes started with underscore are not considered as lexical error if that will help. Such tags will be flagged as errors by the validator anyway.
Thanks Marek. I think that pragalathan when he talks about "formatting" he refers to attributes starting with underscore not being bold and being marked as erroneous. So what needs to be fixed first is "the JSP custom tags are not recognized properly". I'm leaving that one for Anton.
Thanks Marek and David for the detailed explanation.
There are two issues.
1. As David said, the attributes starting with _ are not recognized as attributes and shown as errors(with red underline).
2. when you use Alt+Shift+F to format the code, the indentation is not correct as you can see in the screen shot attached. eg. yt_apex:row, yt_apex:module and span tags, etc
As per the explanation above, what I understand is that making the lexer recognize
attribute may fix the indentation too, as Marek said.
(In reply to comment #5)
> 2. when you use Alt+Shift+F to format the code, the indentation is not correct
> as you can see in the screen shot attached. eg. yt_apex:row, yt_apex:module and
> span tags, etc
Sorry, I did not really notice the indentation problem, although on second look at your screenshot it is pretty obvious. :-) Yeap, it is very likely side effect of attributes not being recognized.
The problem with underscore as the first character of attribute name fixed in web-main#556b45749edf
I'm not closing the issue, please verify it the formatting works properly David. Thanks.
And of course Anton should verify why the tags are not recognized as JSP custom tags. I believe there's not enough information for this pragalathan. Can you please doublecheck if your project is properly configured? A sufficient way should be to deploy and check if works. If so there's a bug in netbeans. In such case, could you please pack the project or its part which can be used to demonstrate the issue? Thanks in advance.
Created attachment 103822 [details]
Sorry folks for not utilizing your times effectively.
I tried resolving all the POM dependencies. And now I'm able to format(indention) properly.
However I remember once I said the IDE not to check errors on this JSP file when I saw too many error underline.
But they are no more. And the attribute with _ is in green color (I assume that lexer recognized it properly)
No problem. The original usecase is still valid since one may want to work with the code even if the libraries are unresolved. Since there doesn't seem to be a problem on the JSP parser side and the lexing of underline prefixed html attributes has been fixed today I consider this issue as fixed.
Thanks for your feedback.
Integrated into 'main-golden', will be available in build *201012100001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
User: Marek Fukala <email@example.com>
Log: #192803 - Incorrect JSP file formating