Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for JSP/JSF in eclipse WTP #645

Open
vbrandl opened this issue Jul 14, 2020 · 7 comments
Open

Add support for JSP/JSF in eclipse WTP #645

vbrandl opened this issue Jul 14, 2020 · 7 comments

Comments

@vbrandl
Copy link

vbrandl commented Jul 14, 2020

When formatting some JSF inside a style attribute, the formatter destroys the JSF by stripping the closing }.

This happens on Gradle 6.4.1 with the plugin version 5.0.0 as well as with Gradle 6.0.1 and plugin version 4.3.0.

Here is a minimal example to reproduce the issue: https://github.com/vbrandl/spotless-formatting-jsf-reprod

After running ./gradlew spotlessApply in the repository, the diff looks like this:

   <div
-    style="width: 30px; height: 20px; background: #{someControllerName.someFunctionToGetTheColor(x)}" />
+    style="width: 30px; height: 20px; background: #{someControllerName.someFunctionToGetTheColor(x)" />

The following configuration is used:

spotless {
  format 'xml', {
    // ratchetFrom 'origin/master'
    target '**/*.xhtml'
    eclipseWtp('html')
    indentWithSpaces(2)
    endWithNewline()
    trimTrailingWhitespace()
    encoding 'UTF-8'
  }
}
@fvgh
Copy link
Member

fvgh commented Jul 14, 2020

I can confirm the problem. I integrated your example quickly into a unit test for HTML formatting.
But I have the same problem when I run the formatting in the Eclipse IDE using a HTML formatter.
When I use the JSF/JSP formatter, it works fine.
I am afraid I have not supported all WTP extensions. A list of the supported/tested once is in this README section.

Looking at the code, it seems that in the end the JSP/JSF formatting is based on HTTP formatter. This also corresponds to Eclipse documentation.

I suspect that Eclipse Webtools-JSF has a feature which provides some JSP/JSF format tweaks, but not sure.
Anyhow, I am afraid this is a feature request, and Spotless Eclipse WTP would need to provide a JSP/JSF formatter type (like it now provides HTML, XML, ...).

@fvgh
Copy link
Member

fvgh commented Jul 14, 2020

@vbrandl I am afraid I personally have right at the moment no time to provide an extension. Should not be that difficult, but some digging in the Eclipse code/config is required. So if you want to provide something, I can give you a quick tour through the spotless-eclipe-wtp code.

@nedtwigg nedtwigg changed the title JSF in style attribute becomes invalid when formatting Add support for JSP/JSF in eclipse WTP Jul 14, 2020
@jpraet
Copy link
Contributor

jpraet commented Mar 23, 2021

I have the same problem, and some more info: the problems seems specifically related to the usage of EL expressions inside a style="" attribute.

style="display: #{dashboard.postIt == null ? 'none': 'block'};">
gets formatted as
style="display: #{dashboard.postIt== null? 'none': 'block'">.

But when I change style="" by something else as a test:
title="display: #{dashboard.postIt == null ? 'none' : 'block'};">
it is left untouched.

So I suspect the problem might be related to formatting of embedded CSS?

@Emkas
Copy link
Contributor

Emkas commented Jan 11, 2023

Of course there is an issue with that, but... I've got o huge project with JSF and Spotless. We use WTP and there are really a few issues on thousands of pages.

I'd never use this kind of inline CSS. In any CSS framework there will be classes like none or display-none or something like this. We have or own displayNone. And if you change:

<div style="display: #{dashboard.postIt== null? 'none': 'block'">

to

<div class="display#{dashboard.postIt == null ? 'None': 'Block'}">

eclipse WTP formatter won't protest.

The only main issue with WTP and JSF we have is that it forces <script> tag to have type="application/javascript" even though it's not needed in HTML 5. But importing JavaScript formatter is a must for embedded JavaScript in XHTML files.

@nedtwigg
Copy link
Member

You can always modify the behavior by following the eclipse step with a replace 'type="application/javascript"', ''. In ~ a week I'll have something to show which will hopefully make maintaining all the eclipse steps a lot easier.

@Emkas
Copy link
Contributor

Emkas commented Mar 7, 2023

You can always modify the behavior by following the eclipse step with a replace 'type="application/javascript"', ''. In ~ a week I'll have something to show which will hopefully make maintaining all the eclipse steps a lot easier.

@nedtwigg, Thanks! After some tries it worked! Since maven properties are trimmed I had to go with:

<replace>
	<name>Remove unnecessary type of script in HTML 5</name>
	<search>script type="text/javascript"</search>
	<replacement>script</replacement>
</replace>

BTW. In the time you wrote this, a replacement in the replace could not be empty (this change was released 3 days after 😃), so I also had to update my maven plugin.

@nedtwigg
Copy link
Member

The broader issue of support JSP/JSF in WTP is possible by finishing #1622.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants