Re: Wizard help

2009-09-25 Thread Pedro Santos
I am just having trouble with the move from Step 1 to Step 2.  I assume
the success logic would be implemented in the onFinish() method of my
ForgotPasswordWizard

You can use an listener to implement success logic, onFinish will to be
called when Finish button get pressed
http://static.ddpoker.com/javadoc/wicket-extensions/1.4-m1/org/apache/wicket/extensions/wizard/IWizardModelListener.html

On Fri, Sep 25, 2009 at 11:00 AM, Jeffrey Schneller 
jeffrey.schnel...@envisa.com wrote:

 Sorry for the duplicate post.  I don't think my first post went through.



 I have looked at the examples and the javadocs but can't figure out how
 to do the following.  I am a wicket newbie.



 I want to create a wizard with 2 steps implemented as panels.



 Step 1:  Asks the user to enter some information.  Validates that the
 information entered is in the database before moving to step 2.  [I have
 this working]

 Step 2:  Based on the information entered in step 1, look in the db for
 the matching data and display the rest of the information.  [part I am
 having trouble with]



 This is to implement a forgot password functionality.  Based on the
 username entered in step 1, look up a question in the db, then display
 the question to the user in step 2 so they can answer it.  Then after
 successfully answering the question perform some logic to reset the
 password.



 I am just having trouble with the move from Step 1 to Step 2.  I assume
 the success logic would be implemented in the onFinish() method of my
 ForgotPasswordWizard



 The code  [just displaying the constructors]:



   public ForgotPasswordWizard(String id) {

  super(id);

  ForgotPasswordModel bean = new ForgotPasswordModel();

  setDefaultModel(new
 CompoundPropertyModelForgotPasswordModel(bean));

  WizardModel model = new WizardModel();

  model.add(new ForgotPasswordStep1());

  model.add(new ForgotPasswordStep2());

  init(model);

   }

   public ForgotPasswordStep1() {

  super(new Model(ForgotPasword), new Model(Enter your
 username [email]));

  RequiredTextField username = new
 RequiredTextField(username);

  username.add(EmailAddressValidator.getInstance());

  add(username);

  IFormValidator validator = new AccountValidator(username);

  this.add(validator);

   }

   public ForgotPasswordStep2() {

  super(new Model(ForgotPasword), new Model(Answer your
 Security Question));



  // ??

  // find the question from the db for the user

  ForgotPasswordModel myModel = (ForgotPasswordModel)
 this.getDefaultModelObject();

  // access the db to get the actual question

  myModel.setQuestion([the question I shoud show]);

  // ???



  add(new Label(question));

  add(new RequiredTextField(answer));

   }





 Thanks.



 Jeff




-- 
Pedro Henrique Oliveira dos Santos


RE: Wizard help

2009-09-25 Thread Jeffrey Schneller
Do I override the onFinish() method of my wizard or do I add a listener
to my wizard and put the logic there?  It looks like the wicket Wizard
that I am extending already implements the IWizardModelListener
[according to the java doc]  This will allow me to perform logic needed
when the wizard finishes.

I still don't know how to perform logic between step 1 and step 2.

Flow is:
Step 1 = ask for username
Step 1 = press next ??
Look up username in db and get additional info  ??
Step 2 = present additional info for edit   ??
Step 2 = press Finish
Update the db and set response page to send the user on their way


Do I use the onActiveStepChanged() method and use getActiveStep() to see
what step I am coming from and do my lookup if the active step is 1?

The examples don't show a good example of a wizard that uses data from
one step to present additional information in another step.  Otherwise
the examples are very good.

Thanks.

-Original Message-
From: Pedro Santos [mailto:pedros...@gmail.com] 
Sent: Friday, September 25, 2009 10:12 AM
To: users@wicket.apache.org
Subject: Re: Wizard help

I am just having trouble with the move from Step 1 to Step 2.  I assume
the success logic would be implemented in the onFinish() method of my
ForgotPasswordWizard

You can use an listener to implement success logic, onFinish will to be
called when Finish button get pressed
http://static.ddpoker.com/javadoc/wicket-extensions/1.4-m1/org/apache/wi
cket/extensions/wizard/IWizardModelListener.html

On Fri, Sep 25, 2009 at 11:00 AM, Jeffrey Schneller 
jeffrey.schnel...@envisa.com wrote:

 Sorry for the duplicate post.  I don't think my first post went
through.



 I have looked at the examples and the javadocs but can't figure out
how
 to do the following.  I am a wicket newbie.



 I want to create a wizard with 2 steps implemented as panels.



 Step 1:  Asks the user to enter some information.  Validates that the
 information entered is in the database before moving to step 2.  [I
have
 this working]

 Step 2:  Based on the information entered in step 1, look in the db
for
 the matching data and display the rest of the information.  [part I am
 having trouble with]



 This is to implement a forgot password functionality.  Based on the
 username entered in step 1, look up a question in the db, then display
 the question to the user in step 2 so they can answer it.  Then after
 successfully answering the question perform some logic to reset the
 password.



 I am just having trouble with the move from Step 1 to Step 2.  I
assume
 the success logic would be implemented in the onFinish() method of my
 ForgotPasswordWizard



 The code  [just displaying the constructors]:



   public ForgotPasswordWizard(String id) {

  super(id);

  ForgotPasswordModel bean = new ForgotPasswordModel();

  setDefaultModel(new
 CompoundPropertyModelForgotPasswordModel(bean));

  WizardModel model = new WizardModel();

  model.add(new ForgotPasswordStep1());

  model.add(new ForgotPasswordStep2());

  init(model);

   }

   public ForgotPasswordStep1() {

  super(new Model(ForgotPasword), new Model(Enter your
 username [email]));

  RequiredTextField username = new
 RequiredTextField(username);

  username.add(EmailAddressValidator.getInstance());

  add(username);

  IFormValidator validator = new
AccountValidator(username);

  this.add(validator);

   }

   public ForgotPasswordStep2() {

  super(new Model(ForgotPasword), new Model(Answer your
 Security Question));



  // ??

  // find the question from the db for the user

  ForgotPasswordModel myModel = (ForgotPasswordModel)
 this.getDefaultModelObject();

  // access the db to get the actual question

  myModel.setQuestion([the question I shoud show]);

  // ???



  add(new Label(question));

  add(new RequiredTextField(answer));

   }





 Thanks.



 Jeff




-- 
Pedro Henrique Oliveira dos Santos

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Wizard help

2009-07-14 Thread Steve Olara
Hello All,
 
Am new to wickets and trying to learn a few things. To do that am trying to 
build a web application that a user can post a exam and a responder can answer 
that exam. So far I have managed to Post a set of questions for a exam into the 
database. my problem is how to answer those questions.
 
A single exam can have 3 different question types Objectives, short answers and 
phrase match. Each of this have different forms of interface for responding to 
it. If there were only 3 questions, one of each type I would just have 3 Wizard 
Steps, but the number of questions can vary depending on the exam. I would like 
to reuse the steps for each question type when needed (Have only 3 predefined 
steps).
 
Can someone guide me on this or point me to a thread that can do the same.
 
A suggestion of an alternate solution is also welcome.
 
Thanks
 
Stephen


  

Re: Wizard help

2009-07-14 Thread John Armstrong
I haven't had time to nice it up but here is a class that does this.
Its a wizard that interviews the user based on pre-configured
questions in the database. There are 3 'types' of questions in this
app I wrote earlier this year (Text Field, Text Area and File) and
there can be any number of each type in each defined interview
process. The app was a website configuration engine essentially. The
user would select a template and the template would have
'Configuration Definitions' associated with it. The app would ask the
user for each of these defs what their answer was.

This example has all of the ugly data access stuff so you should get a
good idea how I pull the data in and add it to the model. This is not
shrinkwrap but just an example.

This is ugly but it should give you the idea:

MetadataWizard---
/*
 *
 */
package mypackage.wicket;

import org.apache.cayenne.DataObjectUtils;
import org.apache.cayenne.ObjectContext;
import org.apache.cayenne.exp.Expression;
import org.apache.cayenne.exp.ExpressionFactory;
import org.apache.cayenne.query.SelectQuery;
import org.apache.wicket.extensions.wizard.Wizard;
import org.apache.wicket.extensions.wizard.WizardModel;

import mypackage.cayenne.Template;

import org.apache.wicket.model.CompoundPropertyModel;

import util.SymLink;

// TODO: Auto-generated Javadoc
/**
 * The Class MetadataWizard is a wizard responsible for interviewing
the user during site configuration
 */
public class MetadataWizard extends Wizard {

/** The template. */
Template theTemplate;

/**
 * Instantiates a new metadata wizard.
 *
 * @param id
 *the id
 * @param theTemplateIn
 *the the template in
 */
public MetadataWizard(String id, Template theTemplateIn){
super(id, false);
theTemplate = theTemplateIn;

setModel(new CompoundPropertyModel(theTemplate));
WizardModel model = new WizardModel();

// We need to put a model on this that is the config DEFs value 
for this user
mypackage.cayenne.Account theAccount = 
MySession.get().getUser();
ObjectContext context = theAccount.getObjectContext();

for (mypackage.cayenne.ConfigurationDef configDefinition :
theTemplate.getConfigurationDefArray()) {

// Get this data element from the users data list
Expression qual = ExpressionFactory.likeIgnoreCaseExp(

mypackage.cayenne.ConfigurationData.TO_ACCOUNT_PROPERTY, theAccount)
.andExp(

ExpressionFactory.likeIgnoreCaseExp(

mypackage.cayenne.ConfigurationData.TO_CONFIGURATION_DEF_PROPERTY,

configDefinition));

SelectQuery query = new
SelectQuery(mypackage.cayenne.ConfigurationData.class, qual);
java.util.List defList = context.performQuery(query);
mypackage.cayenne.ConfigurationData data = null;

// If an element exists assign it so we can pass it to 
our
PropertyModel for population
// If it does not exist then create a new one, map it 
into the
account/template
if(defList.size()0){
data = 
(mypackage.cayenne.ConfigurationData)defList.get(0);
} else {
data = (mypackage.cayenne.ConfigurationData)
context.newObject(mypackage.cayenne.ConfigurationData.class);
data.setToAccount(theAccount);
data.setToConfigurationDef(configDefinition);
}

if(configDefinition.getElementtype().equals(string)){
model.add(new TextStep(configDefinition, data));
} 
if(configDefinition.getElementtype().equals(textarea)){
model.add(new TextAreaStep(configDefinition, 
data));
} else 
if(configDefinition.getElementtype().equals(file)){
model.add(new FileStep(configDefinition, data));
}
}
init(model);
}

/**
 * On cancel.
 *
 * @see org.apache.wicket.extensions.wizard.Wizard#onCancel()
 */
@Override
public void onCancel()
{
setResponsePage(mypackage.wicket.MyPage.class);
}


/**
 * On finish.
 *
 * @see 

Re: Wizard help

2009-07-14 Thread Steve Olara
Thanks a great bunch John, will go through it.
 
Stephen

--- On Tue, 14/7/09, John Armstrong siber...@siberian.org wrote:


From: John Armstrong siber...@siberian.org
Subject: Re: Wizard help
To: users@wicket.apache.org
Date: Tuesday, 14 July, 2009, 5:43 PM


I haven't had time to nice it up but here is a class that does this.
Its a wizard that interviews the user based on pre-configured
questions in the database. There are 3 'types' of questions in this
app I wrote earlier this year (Text Field, Text Area and File) and
there can be any number of each type in each defined interview
process. The app was a website configuration engine essentially. The
user would select a template and the template would have
'Configuration Definitions' associated with it. The app would ask the
user for each of these defs what their answer was.

This example has all of the ugly data access stuff so you should get a
good idea how I pull the data in and add it to the model. This is not
shrinkwrap but just an example.

This is ugly but it should give you the idea:

MetadataWizard---
/*
*
*/
package mypackage.wicket;

import org.apache.cayenne.DataObjectUtils;
import org.apache.cayenne.ObjectContext;
import org.apache.cayenne.exp.Expression;
import org.apache.cayenne.exp.ExpressionFactory;
import org.apache.cayenne.query.SelectQuery;
import org.apache.wicket.extensions.wizard.Wizard;
import org.apache.wicket.extensions.wizard.WizardModel;

import mypackage.cayenne.Template;

import org.apache.wicket.model.CompoundPropertyModel;

import util.SymLink;

// TODO: Auto-generated Javadoc
/**
* The Class MetadataWizard is a wizard responsible for interviewing
the user during site configuration
*/
public class MetadataWizard extends Wizard {
    
    /** The template. */
    Template theTemplate;
    
    /**
 * Instantiates a new metadata wizard.
 *
 * @param id
 *            the id
 * @param theTemplateIn
 *            the the template in
 */
    public MetadataWizard(String id, Template theTemplateIn){
        super(id, false);
        theTemplate = theTemplateIn;
        
        setModel(new CompoundPropertyModel(theTemplate));
        WizardModel model = new WizardModel();
        
        // We need to put a model on this that is the config DEFs value for 
this user
        mypackage.cayenne.Account theAccount = MySession.get().getUser();
        ObjectContext context = theAccount.getObjectContext();
        
        for (mypackage.cayenne.ConfigurationDef configDefinition :
theTemplate.getConfigurationDefArray()) {
            
            // Get this data element from the users data list
            Expression qual = ExpressionFactory.likeIgnoreCaseExp(
                    mypackage.cayenne.ConfigurationData.TO_ACCOUNT_PROPERTY, 
theAccount)
                    .andExp(
                            ExpressionFactory.likeIgnoreCaseExp(
                                    
mypackage.cayenne.ConfigurationData.TO_CONFIGURATION_DEF_PROPERTY,
                                    configDefinition));

            SelectQuery query = new
SelectQuery(mypackage.cayenne.ConfigurationData.class, qual);
            java.util.List defList = context.performQuery(query);
            mypackage.cayenne.ConfigurationData data = null;
            
            // If an element exists assign it so we can pass it to our
PropertyModel for population
            // If it does not exist then create a new one, map it into the
account/template
            if(defList.size()0){
                data = (mypackage.cayenne.ConfigurationData)defList.get(0);
            } else {
                data = (mypackage.cayenne.ConfigurationData)
context.newObject(mypackage.cayenne.ConfigurationData.class);
                data.setToAccount(theAccount);
                data.setToConfigurationDef(configDefinition);
            }
        
            if(configDefinition.getElementtype().equals(string)){
                model.add(new TextStep(configDefinition, data));
            } if(configDefinition.getElementtype().equals(textarea)){
                model.add(new TextAreaStep(configDefinition, data));
            } else if(configDefinition.getElementtype().equals(file)){
                model.add(new FileStep(configDefinition, data));
            }
        }
        init(model);
    }
    
    /**
 * On cancel.
 *
 * @see org.apache.wicket.extensions.wizard.Wizard#onCancel()
 */
    @Override
    public void onCancel()
    {
        setResponsePage(mypackage.wicket.MyPage.class);
    }


    /**
 * On finish.
 *
 * @see org.apache.wicket.extensions.wizard.Wizard#onFinish()
 */
    @Override
    public void onFinish()
    {
        // Commit meta data
        util.Settings settings = new util.Settings();
        MySession.get().getUser().setToTemplate(theTemplate);
        MySession.get().getUser().getObjectContext().commitChanges();

        // Send them on their way
        setResponsePage