<!-- Enhydra Java Application Server Copyright 1997-1999 Lutris Technologies, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. All advertising materials mentioning features or use of this software must display the following acknowledgement: This product includes Enhydra software developed by Lutris Technologies, Inc. and its contributors. 4. Neither the name of Lutris Technologies nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY LUTRIS TECHNOLOGIES AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LUTRIS TECHNOLOGIES OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --> <JDDI JAVAIMPORT> import com.lutris.appserver.server.session.*; import com.lutris.appserver.server.user.*; import demoApp.presentation.utilities.*; import demoApp.business.user.*; import demoApp.DemoApp; </JDDI> <JDDI INCLUDE="../jinc/Setup.jinc"></JDDI> <JDDI JAVADEF> public void DatabaseQuery(JoltPage page) throws Exception { /**** * simulate a DB query by getting username and ID * sets these up and sets validUser to true if found * sets validUser to false otherwise ****/ DemoApp application = (DemoApp)page.application; SessionUtils.authenticate(page); PageUtils.handlePreviousForm(session, page.data); String username = session.getUser().getName(); SessionData sessionData = session.getSessionData(); String accountType = sessionData.getString("user.accountType", "Unknown"); DemoAppUserManager userManager = application.getUserManager(); // FIX: There will probably be some kind of intervening BO here, // instead of accessing the DO directly. DemoAppUser user = userManager.getDemoAppUser(username); if (user != null) { page.data.set("validUser", "true"); page.data.set("userName", user.getName()); page.data.set("userId", new Integer(user.getUserID())); } else { page.data.set("validUser", "false"); page.data.set("userName", username ); } } </JDDI> <JDDI JAVACALL=DatabaseQuery></JDDI> <HTML> <HEAD> <TITLE>JDDI HTML Example: User Database Query</TITLE> </HEAD> <JDDI INCLUDE="../jinc/Header.jinc"></JDDI> <BODY> <CENTER> <B><FONT FACE="Arial,Helvetica" SIZE=+3> Database Query </FONT></B> </CENTER> </BODY> <JDDI INCLUDE="../jinc/Buttons.jinc"></JDDI> <JDDI INCLUDE="../jinc/Home.jinc"></JDDI> <BODY> <BR> <CENTER> <TABLE COLS=1 WIDTH="60%"> <TR> <TD> <FONT FACE="Arial,Helvetica" SIZE=+1> This page demonstrates a simple database query by getting user information from the database via the UserManager business object. </FONT> </TD> </TR> </TABLE> </CENTER> <BR> <JDDI HTML IFEQ FIELD=cgiArgs.help VALUE="on"> <CENTER> <TABLE COLS=1 WIDTH="40%" > <TR> <TD> <FONT FACE="Arial,Helvetica" COLOR=red> If the user manager successfully found your User Name in the demo database, a table is displayed below which contains the User Name and User ID that were extracted from the database. You can check the source for this file (via the "Source" button above) for the details on how this is done. </FONT> <CENTER><IMG SRC="../media/arrow.gif" BORDER=0 ANCHOR=BOTTOM></CENTER> </TD> </TR> </TABLE> </CENTER> </JDDI> <JDDI HTML IFEQ FIELD=validUser VALUE="true"> <CENTER> <TABLE COLS=1 WIDTH="60%"> <TR> <TD> <FONT FACE="Arial,Helvetica"> <CENTER> <TABLE BORDER=3> <TH>User</TH> <TR> <TD>Username</TD> <TD>(@userName@)</TD> </TR> <TH>DemoAppUser</TH> <TR> <TD>UserID</TD> <TD>(@userId@)</TD> </TR> </TABLE> </CENTER> </FONT> </TD> </TR> </TABLE> </CENTER </JDDI> <JDDI HTML IFEQ FIELD=validUser VALUE="false"> <CENTER> <TABLE COLS=1 WIDTH="60%"> <TR> <TD> <FONT FACE="Arial,Helvetica"> The User Manager couldn't find (@userName@) in the database! </FONT> </TD> </TR> </TABLE> </CENTER </JDDI> <BR> <JDDI INCLUDE="../jinc/VerboseDebug.jinc"></JDDI> </BODY> </HTML>