How to make Eclipse to format JSP code properly?
Asked Answered
G

3

10

I use code formatting command (Ctrl + Shift + F) a lot in Eclipse IDE. While this works pretty well for Java / CSS source codes, the JSP formatting is just sucks.

Is there any plug-in available to make the JSP formatting better in Eclipse IDE? By formatting I mean proper indenting of JSP/HTML tags.

Gland answered 12/8, 2010 at 15:20 Comment(0)
C
2

A quick search with Google turns up this part of MyEclipse Enterprise Workbench.

But a quick, if obvious, question: do you have the J2EE tools installed?

Clynes answered 12/8, 2010 at 15:23 Comment(4)
@MyEclipse - Isn't it commercial? :) Yes. I have the JEE tools installed.Gland
This screen just shows the WTP (which is part of Java EE tools, yes). Besides, MyEclipse isn't much different from Eclipse nowadays.Automatism
once you press Ctrl+Shift+F in a properly indented JSP code, you'll feel what i'm going through. :-DGland
Yes, I know. I never use it in JSP as well. There is afaik no plugin which does it right.Automatism
M
0

I think it is sucks for java also! It can not detect line code size dynamic and breaking code to Irrational parts,for jsp also in other Ide's like Intelliji editor detects

    <tags>
  .......<tag2>

in understandable format that you can track tag start and end point by your eyes , But unfortunately in eclipse you can just say editor to cut off jsp in specific size , We have a idiom ,Drink soup as you paid!

Mahler answered 14/9, 2013 at 17:21 Comment(0)
N
0

So what I found out was, that eclipse reformat's jsp files by methods not line by line. Only if it can reformat the entire method properly it will try. For example if you have this kind of code in the method.

+ message
    + "</p></div><div class='modal-footer'>
<button type='button' class='btn btn-outline
 btn-flat pull-right' data-dismiss='modal'>"
+ code + "</button>
</div>");

The refactor wont happen.

You need to make it to

+ message
    + "</p></div><div class='modal-footer'> <button type='button' class='btn btn-outline btn-flat pull-right' data-dismiss='modal'>"
+ code + "</button> </div>");

And now refactor will work. To this

+ message
+ "</p></div><div class='modal-footer'><button type='button' class='btn btn-outline btn-flat pull-right' data-dismiss='modal'>"
+ code + "</button></div>");
No answered 27/9, 2017 at 6:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.