struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bill Siggelkow <bills...@bellsouth.net>
Subject Re: prepopulating forms
Date Wed, 24 Nov 2004 23:27:52 GMT
Did you try changing the LogonAction to implement 'execute' instead of 
the old 'perform' method?

Brij Naald wrote:
>> Not unless you would like to try posting
>> non-private parts of your action class for list members to review.
> 
> In advance: thanks for all the work you put in some 'newbie'-problems!
> I've checked the "success"-issue, but this was'nt the problem.
> 
> Here are the java-files
> 
> **********************
> * EvaluatiePreAction *
> **********************
> 
> 
> public final class EvaluatiePreAction extends Action {
> 
>     public ActionForward execute(ActionMapping mapping, ActionForm form,
>             HttpServletRequest request, HttpServletResponse response)
>             throws Exception {
>         servlet.log("Does he get here?"); //==>The output never gives 
> this!!
> 
>         HttpSession session = request.getSession();
>         LogonForm logon = (LogonForm) 
> session.getAttribute(Constants.USER_KEY);
> 
>         if (logon == null)
>             return (mapping.findForward("logon"));
>         EvaluatieForm evaluatieForm = readEvaluatie(logon.getUsername());
>         EvaluatieForm evform = (EvaluatieForm) form;
>         try {
>             PropertyUtils.copyProperties(evform, evaluatieForm);
>         } catch (InvocationTargetException e) {
>             Throwable t = e.getTargetException();
>             if (t == null)
>                 t = e;
>             throw new ServletException("RegistrationForm.populate", t);
>         } catch (Throwable t) {
>             throw new ServletException("RegistrationForm.populate", t);
>         }
>         return (mapping.findForward("success"));
>     }
> 
>     /**
>      * @param username
>      * @return
>      */
>     private EvaluatieForm readEvaluatie(String username) {
>         EvaluatieForm form = null;
>         try {
>             FileInputStream fis = new FileInputStream(username + ".txt");
>             ObjectInputStream ois = new ObjectInputStream(fis);
>             form = (EvaluatieForm) ois.readObject();
>             ois.close();
>         } catch (Exception e) {
>         }
>         if (form == null) form = new EvaluatieForm();
>         return form;
>     }
> }
> 
> ********************************************
> * LogonAction-Class (as in struts-examples *
> ************************************
> 
> public final class LogonAction extends Action {
> 
> 
>    /**
>     * Validate credentials with business tier.
>     *
>     * @param username The username credential
>     * @param password The password credential
>     * @returns true if credentials can be validated
>     * @exception UserDirectoryException if cannot access directory
>     */
>    public boolean isUserLogon(String username,
>        String password) {
>       return true;
>    }
> 
> 
>    /**
>     * Login the user.
>     * The event is logged if the debug level is >= Constants.DEBUG.
>     *
>     * @param mapping The ActionMapping used to select this instance
>     * @param actionForm The ActionForm bean for this request (if any)
>     * @param request The HTTP request we are processing
>     * @param response The HTTP response we are creating
>     *
>     * @exception IOException if an input/output error occurs
>     * @exception ServletException if a servlet exception occurs
>     */
>    public ActionForward perform(ActionMapping mapping,
>            ActionForm form,
>            HttpServletRequest request,
>            HttpServletResponse response)
>        throws IOException, ServletException {
>        // Obtain username and password from web tier
>        String username = ((LogonForm) form).getUsername();
>        String password = ((LogonForm) form).getPassword();
> 
>        // Validate credentials with business tier
>        boolean validated = false;
> 
> 
>            validated = isUserLogon(username,password);
> 
> 
> 
> 
>        if (!validated) {
>            // credentials don't match
>            ActionErrors errors = new ActionErrors();
>            errors.add(ActionErrors.GLOBAL_ERROR,
>            new ActionError("error.logon.invalid"));
>            saveErrors(request,errors);
>            // return to input page
>            return (new ActionForward(mapping.getInput()));
>        }
> 
>        // Save our logged-in user in the session,
>        // because we use it again later.
>        HttpSession session = request.getSession();
>        session.setAttribute(Constants.USER_KEY, form);
>        // Log this event, if appropriate
>        if (servlet.getDebug() >= Constants.DEBUG) {
>            StringBuffer message =
>                new StringBuffer("LogonAction: User '");
>            message.append(username);
>            message.append("' logged on in session ");
>            message.append(session.getId());
>            servlet.log(message.toString());
>        }
> 
>        // Return success
>        return (mapping.findForward(Constants.SUCCESS));
> 
>    }
> 
> 
> 
> *******************
> * Action-mappings *
> *******************
> <action-mappings>
> 
>        <action
>            path="/Logon"
>            type="org.apache.struts.actions.ForwardAction"
>            parameter="/pages/Logon.jsp"/>
> 
>        <action
>            path="/LogonSubmit"
>            type="app.LogonAction"
>            name="logonForm"
>            scope="request"
>            validate="true"
>            input="/pages/Logon.jsp">
>            <forward
>                name="success"
>                path="/EvaluatiePre.do"/>
>        </action>
> 
>      <action    path="/EvaluatiePre"
>                 type="app.EvaluatiePreAction"
>                 name="evaluatieForm"
>                scope="request"
>             validate="false">
>        <forward name="logon"      path="/Logon"/>
>        <forward name="success"    path="/pages/Evaluatie.jsp" 
> redirect="true"/>
>      </action>
> 
> 
> 
>        <action
>            path="/EvaluatieSubmit"
>            type="app.EvaluatieAction"
>            name="evaluatieForm"
>            scope="request"
>            validate="true"
>            input="/pages/Evaluatie.jsp">
>            <forward
>                name="success"
>                path="/pages/Evaluatie.jsp"/>
>        </action>
> 
>    </action-mappings>
> 
> _________________________________________________________________
> Is jouw domeinnaam nog vrij? http://hostbasket.msn.be/domains/index.asp


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message