This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 208344 - JSP code formatting can not be changed
Summary: JSP code formatting can not be changed
Status: REOPENED
Alias: None
Product: javaee
Classification: Unclassified
Component: JSP (show other bugs)
Version: 7.1
Hardware: PC Linux
: P3 normal (vote)
Assignee: David Konecny
URL:
Keywords:
Depends on:
Blocks: 208404
  Show dependency tree
 
Reported: 2012-02-13 13:38 UTC by _ wadechandler
Modified: 2017-01-10 10:13 UTC (History)
2 users (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description _ wadechandler 2012-02-13 13:38:58 UTC
To reproduce:
1) Go to Tools|Options|Editor|Formatting
2) Notice in the language drop down there is no JSP
Comment 1 Geertjan Wielenga 2012-02-13 13:49:08 UTC
What kind of formatting changes would you like to be able to make?
Comment 2 Petr Jiricka 2012-02-14 16:41:15 UTC
-> enhancement
Comment 3 _ wadechandler 2012-02-15 16:32:43 UTC
One case is Java scriptlet combos. Take for instance...this dumb java file:
public class test {

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
        //test comment
        }
    }
}

format that in the Java editor, and you will get //test comment indented

Take this dumb jsp (which is similar):
<%@page contentType="text/xml" %>
<someroot>
    <%
    String s = "Hello";
    for(int i=0; i<10;i++){
    %>

    <%
    //this is a for loop test
    }
    %>
</someroot>

Format it and there is no indentation of the for loop comment. Also, notice the ;i++ above, it will not be fixed. Move the i++ back one space in the dumb java, and reformat, it will be fixed. In JSP it will not.

I think I will have to go through JSP specifically looking for some things, but in this case if it would some how correctly apply the Java formatting, upon format, along with JavaScript, HTML, XML, etc depending on page output type or something, then that would be a useful start. There is a lot to be gleaned from the JSP formatting requirements by just opening up the editor and starting to build a simple web application. I will see if I can not do something similar; I have all these past experiences I wish I had made many notes about, but I dropped the ball there, so I will need to put together some kind of an example to refresh those issues.
Comment 4 _ wadechandler 2012-02-15 17:04:21 UTC
A good JSP example, that I have often wondered about is:
<%@page contentType="text/xml" %>
<someroot>
    <%
        String s = "Hello";
        for(int i=0; i<10;i++){
    %>
    <child><statement><%=s%></statement><value><%=i%></value></child>
    <%
    //this is a for loop test
    }
    %>
</someroot>

If the formatter were taking into account the contentType as a mime to judge how to format the above bits outside the scriptlets, and I could configure XML much like I discuss in issue 208339, then I could get reformatted to:

<%@page contentType="text/xml" %>
<someroot>
    <%
        String s = "Hello";
        for(int i=0; i<10;i++){
    %>
    <child>
        <statement><%=s%></statement>
        <value><%=i%></value>
    </child>
    <%
    //this is a for loop test
    }
    %>
</someroot>

should I desire. If that were xhtml or html then that formatting could be used, and if the child were a table tag the inner elements could be formatted similarly as I mention in issue 208339 as well. For unknown, or pure text type mime types which are not structured content, I don't think JSP formatting can do a lot without a formatter, imagine a simple text file output or csv, but for the other types there is a bit that can be done.

For the scriptlets, and I have often dwelled on this on different projects, it would be good to be able to enforce wrapper or closest tag formatting/indentation on the scriptlets or to be able to force them to be left aligned. So if I desired closest inner perhaps:
<%@page contentType="text/xml" %>
<someroot>
    <%
        String s = "Hello";
        for(int i=0; i<10;i++){
    %>
    <child><statement><%=s%></statement><value><%=i%></value></child>
    <%
    //this is a for loop test
    }
    %>
</someroot>

Closest outter:
<%@page contentType="text/xml" %>
<someroot>
    <container>
    <%
        String s = "Hello";
        for(int i=0; i<10;i++){
    %>
        <child><statement><%=s%></statement><value><%=i%></value></child>
    <%
    //this is a for loop test
    }
    %>
    </container>
</someroot>

or left aligned:
<%@page contentType="text/xml" %>
<someroot>
    <container>
<%
        String s = "Hello";
        for(int i=0; i<10;i++){
%>
        <child><statement><%=s%></statement><value><%=i%></value></child>
<%
        //this is a for loop test
        }
%>
    </container>
</someroot>

Left aligned may seem strange, but to me those things are nothing more than breakout points to use the page language in the page, and I often find myself pondering whether they are actually code and require the same formatting, and I have really been preferring them left aligned. Them being to the left it is very easy to see exactly where multi-line/statement(for the most part) scriptlets are used; I just scan the left. 

The Java code would need to be formatted/indented to match the wrapped logic. This cuts out accidental extra output white space, and in my opinion makes the logic a bit more readable. Notice the formatting of the contentType remains, and the Java logic is formatted per its rules. Thus if the above logic for the Java should be indented, it would be; imagine nested ifs, loops, etc.

I need to look at the XML formatted JSPs though, and will have to do that another day.
Comment 5 Petr Jiricka 2012-02-16 08:42:07 UTC
David, I believe you are the one who understands this area the most.
Comment 6 Martin Balin 2016-07-07 08:54:17 UTC
This old bug may not be relevant anymore. If you can still reproduce it in 8.2 development builds please reopen this issue.

Thanks for your cooperation,
NetBeans IDE 8.2 Release Boss
Comment 7 terje7601 2017-01-10 10:13:43 UTC
Still reproducable in 8.2. At the very least, it should be possible to override the "Tabs And Indents" settings for JSP files.