6

In java/struts/jsp world, is there something like the ASP.NET custom user control, a piece of UI with back end code that performs a specific logic, and can be pulled and used in another place (for example something like the login control).

Mohamed Faramawi
  • 641
  • 5
  • 13

2 Answers2

6

The current Java EE API offers JSF 2.0 on Facelets for this. Note that Struts(2) is actually a competitor to JSF and that JSP is a view technology like ASP, not a MVC framework. As per Java EE 6 / JSF 2.0, JSP is been replaced by Facelets as the default view technology.

On top of the basic JSF implementation you can choose from a lot of "rich" component libraries which adds an extra CSS and Ajax sausage, for example PrimeFaces (showcase) and OpenFaces (showcase).

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
2

What you are after is called tag files in JSP. I found that they are not as easy to learn and use as .NET user controls.

You can use them similarly to user controls .NET.

workflow is like this.

  1. Create a tag file in web-inf/tags/AtillaTagLibrary/DropDownList.tag
  2. reference your tag file in your jsp file like below

    <%@ taglib prefix="ct" tagdir="/WEB-INF/tags/AtillaTagLibrary"%>
    
  3. Use your tag file like normal jsp tag.

    <ct:DropDownList  />
    

This tag files can get attribute values from outside like user controls.

Atilla Ozgur
  • 14,339
  • 3
  • 49
  • 69