Accueil
AccueilLes ForumsLinks

      »  Access

ACCESSING USER INPUT

What is called a helper class here is a class that contains (and that make this contents available) all the user's inputs for a particular form/step of the wizard. The API provides a method to get such helper in class WizardFlow :

public static Object getHelper(HttpServletRequest request, String action, int type)

The first parameter is the current request. It is needed to know where the user currently is.

The second parameter is the path of the action for which we need the helper. This path must correspond to an action's path in your struts-config file(s). The action path is actually the only way to uniquely identify an action from another, that's why the acion's path is always used to tell the API which step is concerned.

The third parameter is the type of the helper : either WizardFlow.DYNAHELPER or WizardFlow.DYNAHELPER.

You can also ask for a helper from a JSP page, the 'helper' tag is done for that. Its description is at the end of this page.

MAPPED HELPER

When you ask for a mapped helper, the API returns you a class which type is net.aejase.plugin.wizard.helpers.WizardBaseHelper. This a JavaBean which only contains a map which is containing all the fields and their value.

The class provide a getValue(String key) method to let you access the fields. Note that if the field does not exists in the map, a void String is returned. This type od helper is intended to be used in the Model layer of the MVC model, but you can also call one from a JSP page (see tag's description at the end of the page) like this :

<wizard:helper id="helper" formAction="/anAction" dynamic="false" />

<bean:write name="helper" property="value(<FIELD>)" />

This allows you to display helper's contents easily, but you CAN'T use this way if you need to use Struts taglib in the page's form(s). Why ? Let'stake a simple example :

<wizard:helper id="helper" formAction="/anActionPath" dynamic="false" />

<html:form action="/anActionPath">
<html:text name="helper" property="value(<FIELD>)" />
</html:form>

If you look at the output HTML generated by the <struts:html> tag, it looks like this :

<input type="text" name="value(<FIELD>)">

Conclusion : you really need a pure JavaBean as helper. That is where the DYNAHELPER type is done for.

DYNAMIC HELPER

As seen before, sometimes you need a real JavaBean. The problem is that each page has its own fields with their name. So how can I build on the fly a new class ? The reflection API main goal is to navigate in the class and methods hierarchy and relies on declared classes. The common beanutils API can dynamically build beans but in fact, there is always a map behind. When using struts taglib, if you have for example <struts:xxxx name="bean" property="field">, what Struts tries to do is invoking method bean.getField() with reflaction API.

So the solution is to code an API which can take a collection of field, and generate a class with fields and accessor. I don't know if you have an idea about how doing such stuff, but I haven't. Hopefully, clever guy did it, on a project hosted by SourceForge : http://sourceforge.net/projects/dynclass.

In this package is our magic method : BeanCreator.createBeanFormMap(). It returns an object with all fields and methods needed to make a JavaBean. This is great for struts which use reflection, but if you try to get it in one of your class, it is not very useable. You will obtain a Object class, but you won't be able to call any method on it, the compiler won't permit it. That's why I kept the mapped helper in this API.

HELPER TAG

Helper tag has 3 parameters :

a) id : the key under which the helper will be stores in page context [REQUIRED]
b) formAction : the action's inputs you need (must be an existing action in your struts-config files) [REQUIRED]
c) dynamic : boolean parameter to indicate if you want a mapped bean (false) or a dynamic one (true) [DEFAULT=true]

Another usefull thing : you need the user input only if the user already has submitted a form. When it is the first time, no need to initialize fields. So the problem is that you only need a helper bean when the user is coming back. One solution is to make IF statements to look if it is the first visit. Solution : if you get a bean in the page context with this tag and if it is first visit of the user (in other words, the WizardFlow has no trace of the current action), then the API looks the form associated with the action, takes its field and create a map containing all the fields, their value set to ''. So code like this works all time :

<wizard:helper id="helper" formAction="/anActionPath" />

...
<html:text name="helper" property="field"/>
...

Note : it could be good for fields to have their default value different from ''. It will appear in further release (see TODO list) ;op




:: News ::

05 / 03 / 2003
version 0.7 released

04 / 29 / 2003
First release of the plugin (version 0.5)


:: Related ::




 

STRUTS WIZARD