History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: IDEA-19371
Type: New Feature New Feature
Status: Resolved Resolved
Resolution: Duplicate
Assignee: Dmitry Avdeev
Reporter: Pavel Feldman
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
IDEA: Feedback

JSP Refactoring: Extract .tag file for JSP with variables usage

Created: 29 Aug 08 23:13   Updated: 12 Sep 08 19:00
Component/s: Refactoring

Issue Links:
Duplicate
This issue duplicates:
IDEADEV-7711 JSP: Extract to tag Normal Open
 

Build: 8,733
Severity: Low


 Description  « Hide
I have to deal with legacy JSP code and refactoring is a big part of my work. Very often I have to extract repeated parts of JSP code like this:
index.jsp
-----------
<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<html>
<head>
<title>Simple jsp page</title>
</head>
<body>
<%
String title = "Name";
String name = "Pavel Feldman";
String color = "blue";
%>
<fieldset style="width:100px;color:<%=color%>">
<legend><%=title.toUpperCase()%></legend>
<%=name%>
</fieldset>
</body>
</html>

Into something more reusable, like this:
/WEB-INF/frame.tag
---------------------------
<%@ tag isELIgnored="false" %>
<%@ attribute name="title" required="true" type="java.lang.String" %>
<%@ attribute name="color" required="true" type="java.lang.String" %>
<fieldset style="width:100px;color:$">
<legend><%=title.toUpperCase()%></legend>
<jsp:doBody/>
</fieldset>


index2.jsp
-------------
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="ui" tagdir="/WEB-INF/tags" %>
<html>
<head>
<title>Simple jsp page</title>
</head>
<body>
<%
String title = "Name";
String name = "Pavel Feldman";
String color = "blue";

pageContext.setAttribute("title", title);
pageContext.setAttribute("name", name);
pageContext.setAttribute("color", color);
%>
<ui:frame title="${title}" color="$
">
${name}
</ui:frame>
</body>
</html>

I think it could be automated as "Refactor .tag file" refactoring which includes
1) Extracting selected piece of JSP code into new .tag file
2) Adding reference to taglib to original page if it was not there
<%@ taglib prefix="ui" tagdir="/WEB-INF/tags" %>
3) Enabling EL in original JSP file if it was not enabled
isELIgnored="false"
4) Putting necessary scriptlet local variables into pageContext to make them available to EL
pageContext.setAttribute("title", title);
5) Asking user which variables are passed as attributes and which one goes as body. Asking which attributes are required.
6) Replacing scriptlet variables usages in .tag file with EL when possible (optional)
<%=color%> to $
but leaving more complex expressions as they are
<%=title.toUpperCase()%>
7) Searching across the page or other pages for duplicated piece of JSP to replace duplicate with tag.

For me it looks like JSP version of Extract Method which saves me a lot of time.

Ability to replace scriptlet variables usage like <%=color%> with EL $
and adding them to pageContext (pageContext.setAttribute("color", color); ) could be separate refactoring.



 All   Comments   Work Log   Change History      Sort Order:
Stephen Friedrich - 12 Sep 08 18:57
duplicate of IDEABKL-3141 and IDEA-7711