ITworld.com
  Search  
ITworld Home Page ITworld Webcasts ITworld White Papers ITworld Newsletters ITworld News ITworld Topics Careers ITworld Voices ITwhirled Changing the way you view IT
Personalize Your Web site with Skins, Part 2
ASP TUTOR --- 07/23/2001

Brian R.J. Heumann

After the user submits the form, its values are stored in the JavaBean userProfile and can be processed. Listing 2 shows sample Java code for a user profile bean, which holds a string with the identifier for the skin that the user has chosen to see. This skin identifier is used later to tailor skin server requests to the user's preference. 

On this topic

Listing 2: UserProfileBean.java

// UserProfileBean.java
public class UserProfileBean { String userId ="Anonymous"; String preferredSkin ="Default" ;

public void setUserId( String id ) {
userId = id ; } public String getUserId() { return userId ; } public void setPreferredSkin( String skinName ) { preferredSkin = skinName ; } public String getPreferredSkin() { return preferredSkin ; } } ;

Process the user profile
The form containing the user preferences is submitted to ProcessUserProfile.jsp. Listing 3 shows a sample JSP that you can use to process the user profile information. It does not do anything practical, but you can use it as a starting point for storing the user profile in an LDAP (lightweight directory access protocol) directory or in a database.

Listing 3: ProcessUserProfile.jsp

<%@ page contentType="text/html" %>
<%@ page language="Java" %> <%@ page import="java.util.*, UserProfileBean" %> <jsp:useBean id="userProfile" class="UserProfileBean" scope="session" /> <jsp:setProperty name="userProfile" property="*"/>

User ID is: <jsp:getProperty name="userProfile" property="userId"/> <BR> Preferred Skin : <jsp:getProperty name="userProfile" property="preferredSkin"/> <jsp:forward page="/jsp/PersonalHomepage.jsp"/>

ProcessUserProfile.jsp ultimately forwards the request to a different JSP that makes use of the user profile.

Add personalization to your Website
You have seen how a user can choose a skin and how this information is stored in a JavaBean. Next, you will learn how to use these preferences to display a personalized Website.

Changes to your Website
After the user profile is saved, your JSPs can exploit it to personalize a portal or homepage. Using the user profile bean in your JSPs, you can easily access the relevant properties to generate a personalized page. Listing 4 demonstrates how to use the user profile to create a customized look and feel for the user's preferred skin.

Listing 4: PersonalHomepage.jsp

<%@ page contentType="text/html" language="Java" import="UserProfileBean" %> <JSP:USEBEAN id="userProfile" class="UserProfileBean" scope="session"/> <JSP:SETPROPERTY name="userProfile" property="*"/>

<HEAD>
<TITLE>My Personalized Homepage</TITLE>

<!-- ATN: The following line has been wrapped for better legibility. It should be a single line with no whitespace after "?skin=". --> <LINK rel="stylesheet" href="http://localhost:8080/skins/jsp/SkinServer.jsp?skin= <jsp:getProperty name="userprofile" property="preferredskin"/>&id=css"> </HEAD>

<BODY>

<!-- ATN: The following line has been wrapped for better legibility. It should be a single line with no whitespace after "?skin=" --> <IMG src="http://localhost:8080/skins/jsp/SkinServer.jsp?skin= <jsp:getProperty name="userprofile" property="preferredskin"/>& id=logo">

<H1>My personalized Homepage!</H1>

<TABLE width="100%" border="0" cellspacing="0" cellpadding="0"> <TR> <TD>

<TABLE class="Portlet" width="100%" border="0" cellspacing="0" cellpadding="0"> <TR> <TD class="TitleBar"> Title Bar </TD> </TR>

<TR>
<TD class="ContentArea"> Ipsem lorem retequiem latus gratis forticicum adventiris seculem.<BR> Lorventic marbot simplif forticicum lorentus practicum sempre isbit </TD> </TR> </TABLE> </TD>

<TD>
</TD>

<TD>
<TABLE class="Portlet" width="100%" border="0" cellspacing="0" cellpadding="0"> <TR> <TD class="TitleBar"> Title Bar </TD> </TR> <TR> <TD class="ContentArea"> Ipsem lorem retequiem latus gratis forticicum adventiris seculem.<BR>Lorventic marbot simplif forticicum lorentus practicum sempre isbit </TD> </TR> </TABLE> </TD>

</TR>
</TABLE> </BODY>

PersonalHomepage.jsp makes use of the preferredSkin property for a user profile bean; the <LINK> and <IMG> tags now refer to a JSP's URL and not to files. The following code demonstrates how to write an <IMG> tag for a logo. <IMG SRC = "http://localhost:8080/skins/jsp/SkinServer.jsp? skin=<jsp:getProperty name="userProfile" property="preferredSkin"/>&id=logo"> The <IMG> tag represents the logo for the personalized homepage. Instead of referring to a static file in the SRC attribute, the tag now makes a request to a skin server. The request contains two parameters: the preferredSkin property's value of the userProfile bean and the visual element's identifier. With the pattern demonstrated in Listing 4, you can replace references to static files to make the skins exchangeable.

Next Week: Personalize your Web site, Part 3

 

Brian R.J. Heumann is a user-centered design consultant at IBM. He has several years of experience working with object-oriented technologies and software development, especially Java, HTML, and JSPs. He develops Websites for e-commerce, presentations, and portals.



Advertisements
Sponsored links
Locate Hidden Software on business PCs with this free tool
Top 5 Reasons to Combine App Performance and Security
KODAK i1400 Series Scanners stand up to the challenge
Bring harmony to your mix of UNIX-Linux-Windows computing environments
 Home   Newsletters  ASP TUTOR
www.itworld.com    open.itworld.com     security.itworld.com     smallbusiness.itworld.com
storage.itworld.com     utilitycomputing.itworld.com     wireless.itworld.com

 
Contact Us   About Us   Privacy Policy    Terms of Service   Reprints  

CIO   Computerworld   CSO   GamePro   Games.net   IDG Connect   IDG World Expo   Industry Standard   Infoworld   ITworld   JavaWorld   LinuxWorld  MacUser   Macworld   Network World   PC World   Playlist  

Copyright © Computerworld, Inc. All rights reserved

Reproduction in whole or in part in any form or medium without express written permission of Computerworld Inc. is prohibited. Computerworld and Computerworld.com and the respective logos are trademarks of International Data Group Inc.