Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 950
Joergi Avatar asked Nov 13 '12 11:11

Joergi


2 Answers

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?

like image 62
Magnilex Avatar answered Oct 17 '22 20:10

Magnilex


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!

like image 5
Daniela Mogini Avatar answered Oct 17 '22 20:10

Daniela Mogini