Eclipse is making nice looking JSF code (XHTML) unreadable by autoformating
Asked Answered
L

2

6

I have the problem that if I autoformat a XHTML file (JSF 1.2) in Eclipse with the keys CTRL + SHIFT + f, the output looks really bad and is not really readable anymore.

My formated code:

<span class="label viertel alignright"> 
    <h:outputLabel for="itLine5" value="E-Mail:" /> 
</span>

Becomes this:

<span class="label viertel alignright"> <h:outputLabel
       for="itLine5" value="E-Mail:" /> </span>

In this small example, it's still readable - but in longer code it's just chaos!

How do I make sure that my XHTML code is formatted in a readable manner?

I use this version of Eclipse Helios:

  • Eclipse Java EE IDE for Web Developers.
  • Version: Helios Service Release 1 - Build id: 20100917-0705

I use these JBoss Tools:

  • JBoss Archies Tools 3.2.0
  • JBoss Tools RichFaces 3.2.1
  • JBossASTools 2.2.0
  • Hibernate Tools 3.40.0
  • JBoss Seam Tools: 3.2.1
Ligetti answered 13/11, 2012 at 11:4 Comment(9)
Good question, would love if someone has an answer for it. :) I tend to not autoformat my xhtml-code.Uvular
I'm sure there is a cood checkstyle template for that, i hope somebody got one!Ligetti
i hope the bounty helps fixing this problem!Ligetti
For Helios, do you have any plugins installed to help you create and work with JSF projects and xhtml?Uvular
i have the JBoss tools installed. and i can't switch to Juno, i tried, but we have some dependencies which will not work with Indigo or Juno :(Ligetti
Exactly which version of Helios are you using? And which version of JBoss tools?Uvular
@MagnusTengdahl i updated my question with the pluginsLigetti
I downloaded your version of Eclipse and have tried to download the same version of Jboss Tools with no success. Tried both marketplace and the old fashioned update sites. Sorry, but I'm giving up.Uvular
to be honest: i installed it a long time ago... but a new developer is trying now to get everything working with a newer eclipse, then we try your trick (and you will get the bounty, of course)Ligetti
U
7

I think I have a solution that works well enough (Eclipse Juno). A lot of tags/elements are specified as inline causing the wierd formatting. <span> for example is in that list. You could try to remove the list of inline elements (don't worry, you can always select "Restore Defaults"). While you're at it, change the width to something more useful than the default (72 in my case). The preferences are found in Window > Preferences > Web > HTML Files > Editor:

HTML file settings

I removed all the inline elements in the list and formatted a big xhtml file with good result. I set my line width to 120 which is what I use for Java. Of course, this change will affect regular HTML files as well.

From your example, this code:

<span class="label viertel alignright"> <h:outputLabel
        for="itLine5" value="E-Mail:" />
</span>

was formatted to:

<span class="label viertel alignright">
    <h:outputLabel for="itLine5" value="E-Mail:" />
</span>

Is this good enough for you?

Uvular answered 16/11, 2012 at 13:20 Comment(4)
this sounds good, but i can't find this point in Helios, so it is not really helping me with my problem.Ligetti
What a shame... Upgrade to Juno? :)Uvular
finally, we made an update... you trick works perfect, you deserve the bounty, thanks!!!!Ligetti
Nice to hear. Thanks to you too!Uvular
C
5

I don't use CTRL + SHIFT + F to format the code but only CTRL + I to indent. This function works well only if all the code of the page is selected, so I use CTRL+A to select all and CTRL+I to indent.

The indent function preserves the line breaks and only indents the code. I'm using Juno, hope this also works in Helios!

Coomer answered 23/11, 2012 at 8:24 Comment(2)
hmmm it's not really helping, if the code is already damaged from my CTRL + SHIFT + f ;) and if i have a new xhtml file, it make it looks nicer, but there are also some bad side effects on the tabbing which let it loook bad.Ligetti
Yes, you're right. There are some bad side effects when the tag is not empty. I just use it as a quick fix while writing xhtml.Coomer

© 2022 - 2024 — McMap. All rights reserved.