You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Bailey, Shane C." <SH...@saic.com> on 2003/05/16 21:36:37 UTC

DispatchAction Cool but...

 

I am trying to use the DispatchAction for the first time.  I wish (unless I
am doing

something wrong) that it would default to the excute(...) if no parameter is
passed.

 

So localhost/login.do would go to execute and

     localhost/login.do?subaction=authenticate would go to authenticate(...)

of the action.

 

After reading O'Reilly Struts book I see that it can't because
DispatchAction is

using that method to do the relection stuff, understandable.

 

I that aside, I am getting an error when I try to use the DispatchAction.

I get this error: 

DispatchMapping[/login] does not define a handler property

 

I am wondering if it is because I am trying to use a DynaActionForm

with this action as well.  I haven't looked at the DispatchAction source

but I am wondering if parameter="method" (in struts-config) means the 

DispatchAction only tries to go to the formbean and do a getMethod() 

instead of trying to do a get("method") to get the value of the parameter

method.

 

If not, what is causing this problem?

 

Checklist:

1.	I have parameter="method" in struts-config
2.	I don't have an execute(...) defined in my subclass of
DispatchAction
3.	I use localhost/login.do?method=display 
4.	I defined a method named display(...) with same access and params as
execute
5.	(Extra info) I am using a DynaActionForm

 

 

 


RE: DispatchAction Cool but...

Posted by Robert Taylor <rt...@mulework.com>.
DispatchAction will look in the request parameter for the method
defined in the action mapping "parameter" attribute and will attempt
to invoke that method.

You could override the execute() of DispatchAction  and have it 
call unspecified() if no method is defined and then take the 
appropriate action there.

robert

> -----Original Message-----
> From: Bailey, Shane C. [mailto:SHANE.C.BAILEY@saic.com]
> Sent: Friday, May 16, 2003 3:37 PM
> To: struts-user@jakarta.apache.org
> Subject: DispatchAction Cool but...
> 
> 
>  
> 
> I am trying to use the DispatchAction for the first time.  I wish 
> (unless I
> am doing
> 
> something wrong) that it would default to the excute(...) if no 
> parameter is
> passed.
> 
>  
> 
> So localhost/login.do would go to execute and
> 
>      localhost/login.do?subaction=authenticate would go to 
> authenticate(...)
> 
> of the action.
> 
>  
> 
> After reading O'Reilly Struts book I see that it can't because
> DispatchAction is
> 
> using that method to do the relection stuff, understandable.
> 
>  
> 
> I that aside, I am getting an error when I try to use the DispatchAction.
> 
> I get this error: 
> 
> DispatchMapping[/login] does not define a handler property
> 
>  
> 
> I am wondering if it is because I am trying to use a DynaActionForm
> 
> with this action as well.  I haven't looked at the DispatchAction source
> 
> but I am wondering if parameter="method" (in struts-config) means the 
> 
> DispatchAction only tries to go to the formbean and do a getMethod() 
> 
> instead of trying to do a get("method") to get the value of the parameter
> 
> method.
> 
>  
> 
> If not, what is causing this problem?
> 
>  
> 
> Checklist:
> 
> 1.	I have parameter="method" in struts-config
> 2.	I don't have an execute(...) defined in my subclass of
> DispatchAction
> 3.	I use localhost/login.do?method=display 
> 4.	I defined a method named display(...) with same access and params as
> execute
> 5.	(Extra info) I am using a DynaActionForm
> 
>  
> 
>  
> 
>  
> 
> 

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


RE: DispatchAction Cool but...

Posted by "Todd G. Nist" <tn...@bellsouth.net>.
Shane,

If you do not specify a parameter, it will default to the unspecified method
in you DispatchAction, seems like it should be called default, but o well.
If you add a the following method and do not specify any parameter you
should see it invoked.  (Take a look at the below source from
DispatchAction).


   /**
     * Dispatch to the specified method.
     * @since Struts 1.1
     */
     protected ActionForward dispatchMethod(ActionMapping mapping,
                                            ActionForm form,
                                            HttpServletRequest request,
                                            HttpServletResponse response,
                                            String name) throws Exception {

        // Make sure we have a valid method name to call.
        // This may be null if the user hacks the query string.
        if (name == null) {
            return this.unspecified(mapping, form, request, response);
        }

	.
	.
	.


So you can do set up your class like below and implement the "unspecified"
method as your default.

public final class LoginAction extends DispatchAction
{


    public ActionForward unspecified(ActionMapping mapping,
                                     ActionForm form,
                                     HttpServletRequest request,
                                     HttpServletResponse response)
        throws Exception {

        // do your default logic here

    }

}

Regards,

Todd G. Nist

-----Original Message-----
From: Bailey, Shane C. [mailto:SHANE.C.BAILEY@saic.com]
Sent: Friday, May 16, 2003 3:37 PM
To: struts-user@jakarta.apache.org
Subject: DispatchAction Cool but...




I am trying to use the DispatchAction for the first time.  I wish (unless I
am doing

something wrong) that it would default to the excute(...) if no parameter is
passed.



So localhost/login.do would go to execute and

     localhost/login.do?subaction=authenticate would go to authenticate(...)

of the action.



After reading O'Reilly Struts book I see that it can't because
DispatchAction is

using that method to do the relection stuff, understandable.



I that aside, I am getting an error when I try to use the DispatchAction.

I get this error:

DispatchMapping[/login] does not define a handler property



I am wondering if it is because I am trying to use a DynaActionForm

with this action as well.  I haven't looked at the DispatchAction source

but I am wondering if parameter="method" (in struts-config) means the

DispatchAction only tries to go to the formbean and do a getMethod()

instead of trying to do a get("method") to get the value of the parameter

method.



If not, what is causing this problem?



Checklist:

1.	I have parameter="method" in struts-config
2.	I don't have an execute(...) defined in my subclass of
DispatchAction
3.	I use localhost/login.do?method=display
4.	I defined a method named display(...) with same access and params as
execute
5.	(Extra info) I am using a DynaActionForm











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