From: <jm...@us...> - 2005-07-11 07:13:25
|
Update of /cvsroot/struts/dialogs/src/net/jspcontrols/dialogs/samples/wizardaction/wizardsubclassed In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12963/src/net/jspcontrols/dialogs/samples/wizardaction/wizardsubclassed Added Files: SubclassedSignupForm.java Log Message: --- NEW FILE: SubclassedSignupForm.java --- /* * Copyright 2004-2005 Michael Jouravlev * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package net.jspcontrols.dialogs.samples.wizardaction.wizardsubclassed; import org.apache.struts.action.ActionMapping; import org.apache.struts.util.LabelValueBean; import net.jspcontrols.wizard.intf.IWizardListener; import net.jspcontrols.dialogs.samples.wizardaction.rules.SignupWizard; import net.jspcontrols.dialogs.samples.wizardaction.accounts.UserAccounts; import net.jspcontrols.dialogs.actions.wizard.WizardForm; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import java.util.ArrayList; /** * Wizard Manager for New User Signup wizard. Very compact, because uses * base WizardForm class. Uses standard WizardAction as dispatching action. * * @author Michael Jouravlev */ public class SubclassedSignupForm extends WizardForm implements IWizardListener { /************************************************************************** * Wizard Controller **************************************************************************/ /** * Returns aggregated wizard controller, typecast to concrete type. * Used to access properties of this from JSP page. */ public SignupWizard getSignupWizard() { return (SignupWizard) wizard; } /************************************************************************** * Session object is used as login storage and to access user accounts **************************************************************************/ /** * This demo uses session to store login info and to access user accounts. */ HttpSession session; /** * Returns current session. Used to access user accounts. */ public HttpSession getSession() { return session; } /************************************************************************** * Wizard lifecycle **************************************************************************/ /** * Disposes wizard and performs housekeeping tasks like removing messages, * event listeneres and other objects created by wizard. */ public void disposeWizard() { // Cleanup wizard super.disposeWizard(); // Remove combobox values session.removeAttribute("simple-signup-questions"); } /************************************************************************** * Implementing IWizardListener **************************************************************************/ /** * Fires event when wizard is about to move forward from current step. * * @param event IWizardListener.STEP_REGULAR if about to leave "middle" step, * IWizardListener.STEP_LAST if about to leave the final wizard * step, effectively finishing the wizard. * @return true if it is allowed to move to the next step, false if step * must not be changed. * @see IWizardListener#STEP_REGULAR * @see IWizardListener#STEP_LAST */ public boolean onTransition(int event) { // Not finishing wizard ==> not interested if (event != IWizardListener.STEP_LAST) return true; // Wizard is about to complete ==> store new user account if (UserAccounts.addUser( session, getSignupWizard().getStepSignup().getName(), getSignupWizard().getStepSignup().getPassword(), getSignupWizard().getStepDetails().getSecurityAnswerId(), getSignupWizard().getStepDetails().getSecurityAnswer(), true) ) return true; // Account was not stored ==> generate error, do not dispose wizard getWizardErrors().put("loginsignupcontrol.loginexists", new String[] {getSignupWizard().getStepSignup().getName()}); return false; } /************************************************************************** * ActionForm methods **************************************************************************/ /** * Resets action form. This method is called each time request is received. * Initialize wizard here if needed, and clear checkboxes. * * @param mapping The ActionMapping used to select this instance * @param request The HTTP request we are processing */ public void reset(ActionMapping mapping, HttpServletRequest request) { super.reset(mapping, request); // Session is used to store login name session = request.getSession(); // This wizard is not a control, it does not have stub pages. // So, initialize wizard each time user navigates to this action // and wizard controller does not exist yet. if (wizard == null) { // Create new Wizard Controller instance; // Use internal to Rule Engine object for error messages. wizard = new SignupWizard(null); // Use this action form as wizard event listener; // it stores account info in the account database when // wizard is about to finish. wizard.addListener(this); // Build combobox data fro wizard array data; // rule engine does not deal with types specific to Struts, // it returns a simple string array. ArrayList questions = new ArrayList(); String[] wizardQuestions = getSignupWizard().getStepDetails().getSecurityQuestions(); for (int i = 0; i < wizardQuestions.length; i++) { questions.add(new LabelValueBean(wizardQuestions[i], Integer.toString(i))); } // This is a combobox object for security question on second step. session.setAttribute( "simple-signup-questions", questions ); } } } |