Sundarrajk's Weblog

PMD – JSP and JSF Rules

Posted on: September 28, 2011


This is the twenty third installment of explanation of PMD rules covering rules related to JSP and JSF

Basic JSF rules

Rules concerning basic JSF guidelines.

DontNestJsfInJstlIteration

Do not nest JSF component custom actions inside a custom action that iterates over its body.

Example

                           
                                       
  •                        

Basic JSP rules

Rules concerning basic JSP guidelines.

NoLongScripts

Scripts should be part of Tag Libraries, rather than part of JSP pages.

Example

<!–

function calcDays(){

  var date1 = document.getElementById(‘d1’).lastChild.data;

  var date2 = document.getElementById(‘d2’).lastChild.data;

  date1 = date1.split(“-“);

  date2 = date2.split(“-“);

  var sDate = new Date(date1[0]+”/”+date1[1]+”/”+date1[2]);

  var eDate = new Date(date2[0]+”/”+date2[1]+”/”+date2[2]);

  var daysApart = Math.abs(Math.round((sDate-eDate)/86400000));

  document.getElementById(‘diffDays’).lastChild.data = daysApart;

}

 

onload=calcDays;

//–>

NoScriptlets

Scriptlets should be factored into Tag Libraries or JSP declarations, rather than being part of JSP pages.

Example

<%
response.setHeader(“Pragma”, “No-cache”);
%>
           
                        String title = “Hello world!”;
           

NoInlineStyleInformation

Style information should be put in CSS files, not in JSPs. Therefore, don’t use or tags, or attributes like “align=’center'”.

Example

text

NoClassAttribute

Do not use an attribute called ‘class’. Use “styleclass” for CSS styles.

Example

 
Some text
 

NoJspForward

Do not do a forward from within a JSP file.

Example

IframeMissingSrcAttribute

IFrames which are missing a src element can cause security information popups in IE if you are accessing the page through SSL. See http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q261188

Example

bad example>

 

good example>

http://foo

NoHtmlComments

In a production system, HTML comments increase the payload between the application server to the client, and serve little other purpose. Consider switching to JSP comments.

Example

bad example>

 

good example>

DuplicateJspImports

Avoid duplicate import statements inside JSP’s.

Example

<img src=\"/foo\”>xxtext

JspEncoding

A missing ‘meta’ tag or page directive will trigger this rule, as well as a non-UTF-8 charset.

Example

Most browsers should be able to interpret the following headers:

               

               

                   

                

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Categories

Advertisements
%d bloggers like this: