You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Alexander Czernay <al...@czernay.com> on 2004/12/07 12:02:52 UTC

LookupDispatchAction doesn't lookup mapping

I have a strange problem with LookupDispatchAction:
I built a form displaying several entries from a db as a list. There are 
several buttons for editing/removing the entries an also two buttons for 
paging though the list. The problem is, that only one of those buttons 
works, while the other throws a MissingResourceAction. That sounds like 
a typo, but the strange thing is, that it tries to lookup the button's 
value rather than it's name (eg. having a ressource mapping like 
mybutton.forward=go it would try to lookup "go"). All this works 
perfectly well with my back-button on the same page, using the same action.

Any ideas?

Alexander

ApplicationRessources.properties:
# Form Labels
authors-form.button.create = Autor hinzufügen
authors-form.button.remove = Autor löschen
authors-form.button.edit = Autor bearbeiten
authors-form.button.list = Autoren auflisten
authors-form.button.forward = weiter
authors-form.button.back = zurück

list.jsp
<%@ page language="java"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" 
prefix="logic"%>
<logic:messagesPresent message="false">
<div class="error">
	<html:messages id="msg" message="false">
	      <bean:write name="msg" filter="false"/>
	</html:messages>
</div>
</logic:messagesPresent>
<logic:messagesPresent message="true">
<div class="status">
	<html:messages id="msg" message="true">
	      <bean:write name="msg" filter="false"/>
	</html:messages>
</div>
</logic:messagesPresent>
<div class="group">
<html:form action="/authors-list"><html:submit 
property="submit"><bean:message 
key="authors-form.button.create"/></html:submit></html:form>
<html:form action="/authors-list"><html:submit 
property="submit"><bean:message 
key="authors-form.button.back"/></html:submit></html:form>
<bean:write name="authorForm" property="strutsPage"/>
<html:form action="/authors-list"><html:submit 
property="submit"><bean:message 
key="authors-form.button.forward"/></html:submit></html:form>
</div>
<div class="group">
<table class="list">
<tr><th>Command</th><th>Author</th></tr>
<logic:iterate name="AUTHORS" id="author" indexId="author_id">
<tr><td><html:form action="/authors-list"><html:submit 
property="submit"><bean:message 
key="authors-form.button.edit"/></html:submit><html:submit 
property="submit"><bean:message 
key="authors-form.button.remove"/></html:submit><html:hidden 
property="id" name="author"/></html:form></td><td><bean:write 
name="author" property="name"/> - <bean:write name="author" 
property="description"/></td></tr>
</logic:iterate>
</table>
</div>
<div class="group">
<html:form action="/authors-list"><html:submit 
property="submit"><bean:message 
key="authors-form.button.create"/></html:submit></html:form>
</div>

AuthorsActionList.java
package de.sbow.struts.action.Authors;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.logging.Log;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.LookupDispatchAction;

import de.sbow.MSys.Authors.value.AuthorBeanValue;
import de.sbow.common.ServiceLocator;
import de.sbow.struts.form.AuthorEditForm;
import de.sbow.struts.model.AuthorModel;

/**
  * @author Alexander
  *
  * The Struts action-class for presenting
  * the Authors list.
  *
  */
public class AuthorsListAction extends LookupDispatchAction {
	private static Log log = ServiceLocator.getInstance().getLog(
			AuthorsListAction.class);


	/**
	 * Key method for mapping methods to buttons
	 */
	protected Map getKeyMethodMap() {
	 	  Map map = new HashMap();
	 	  map.put("authors-form.button.create", 	"create");
	 	  map.put("authors-form.button.edit", 		"edit");
	 	  map.put("authors-form.button.remove", 	"remove");
	 	  map.put("authors-form.button.forwar", 		"forward");
	 	  map.put("authors-form.button.back", 		"back");
	 	  return map;
	 	}

	/**
	 * Method create
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 */
	public ActionForward create(
			ActionMapping mapping,
			ActionForm form,
			HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		// get form
		AuthorEditForm authorForm = (AuthorEditForm) form;
		// TODO check if this makes sense!
		authorForm.reset(mapping, request);
		
		
		log.debug("Forwarding to \"authors create\".");
		return mapping.findForward("create");
			}	

	/**
	 * Method edit
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 */
	public ActionForward edit(
			ActionMapping mapping,
			ActionForm form,
			HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		// get form
		AuthorEditForm authorForm = (AuthorEditForm) form;
		// get author-model
		AuthorModel am = new AuthorModel();
		// retieve author via model
		AuthorBeanValue author = am.findById(authorForm.getId());
		// copy author into form
		BeanUtils.copyProperties(authorForm, author);
		
		log.debug("Forwarding to \"authors edit\".");
		return mapping.findForward("edit");
			}	

	/**
	 * Method remove
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 */
	public ActionForward remove(
			ActionMapping mapping,
			ActionForm form,
			HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		// get form
		AuthorEditForm authorForm = (AuthorEditForm) form;
		// get author-model
		AuthorModel am = new AuthorModel();
		// retieve author via model
		AuthorBeanValue author = am.findById(authorForm.getId());
		// copy author into form
		BeanUtils.copyProperties(authorForm, author);

		log.debug("Forwarding to \"authors remove\".");
		return mapping.findForward("remove");
			}	

	/**
	 * Method forward
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 */
	public ActionForward forward(
			ActionMapping mapping,
			ActionForm form,
			HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		// get form
		AuthorEditForm authorForm = (AuthorEditForm) form;
		authorForm.setStrutsPage(authorForm.getStrutsPage() +1 );
		
		log.debug("Forwarding to \"authors list\".");
		return mapping.findForward("list");
			}	
	
	/**
	 * Method back
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 */
	public ActionForward back(
			ActionMapping mapping,
			ActionForm form,
			HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		// get form
		AuthorEditForm authorForm = (AuthorEditForm) form;
		authorForm.setStrutsPage(authorForm.getStrutsPage() -1 );
		
		log.debug("Forwarding to \"authors list\".");
		return mapping.findForward("list");
			}	
	
}

struts-config.xml
		<action path="/authors-list"
			name="authorForm"
			input="msys.authors-list"
			scope="request"
			validate="false"
			parameter="submit"
			type="de.sbow.struts.action.Authors.AuthorsListAction">
			<forward name="list" path="msys.authors-list"/>
			<forward name="edit" path="msys.authors-edit" />
			<forward name="create" path="msys.authors-create" />
			<forward name="remove" path="msys.authors-remove" />
		</action>

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


Re: LookupDispatchAction doesn't lookup mapping

Posted by Susan Bradeen <sb...@gmail.com>.
On Tue, 07 Dec 2004 15:54:20 +0100, Alexander Czernay
<al...@czernay.com> wrote:
> Susan Bradeen wrote:
> 
> 
> 
> >
> > <snip>
> >
> >>        /**
> >>         * Key method for mapping methods to buttons
> >>         */
> >>        protected Map getKeyMethodMap() {
> >>                  Map map = new HashMap();
> >>                  map.put("authors-form.button.create",         "create");
> >>                  map.put("authors-form.button.edit",           "edit");
> >>                  map.put("authors-form.button.remove",         "remove");
> >>                  map.put("authors-form.button.forwar",                 "forward");
> >
> >
> > Is the above line in your code correct ...  "authors-form.button.forwar" ?
> >
> 
> That was just a copy & paste mistake. That's not actually in my code.
> Alexander
> 
> 

Ok, bummer. Doesn't look to me like there's any difference in your
code set up for 'back' and 'forward', and if 'back' is working, I am
not seeing where the problem is. Does stepping through a debugger tell
you what class is actually throwing the "MissingResourceAction'
exception? I've not heard of that one before, but I don't have a whole
lof of experience with LookupDispatchAction.


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

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


Re: LookupDispatchAction doesn't lookup mapping

Posted by Alexander Czernay <al...@czernay.com>.
Susan Bradeen wrote:

> 
> <snip>
> 
>>        /**
>>         * Key method for mapping methods to buttons
>>         */
>>        protected Map getKeyMethodMap() {
>>                  Map map = new HashMap();
>>                  map.put("authors-form.button.create",         "create");
>>                  map.put("authors-form.button.edit",           "edit");
>>                  map.put("authors-form.button.remove",         "remove");
>>                  map.put("authors-form.button.forwar",                 "forward");
> 
> 
> Is the above line in your code correct ...  "authors-form.button.forwar" ?
> 

That was just a copy & paste mistake. That's not actually in my code.
Alexander

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


Re: LookupDispatchAction doesn't lookup mapping

Posted by Susan Bradeen <sb...@gmail.com>.
On Tue, 07 Dec 2004 12:02:52 +0100, Alexander Czernay
<al...@czernay.com> wrote:
> I have a strange problem with LookupDispatchAction:
> I built a form displaying several entries from a db as a list. There are
> several buttons for editing/removing the entries an also two buttons for
> paging though the list. The problem is, that only one of those buttons
> works, while the other throws a MissingResourceAction. That sounds like
> a typo, but the strange thing is, that it tries to lookup the button's
> value rather than it's name (eg. having a ressource mapping like
> mybutton.forward=go it would try to lookup "go"). All this works
> perfectly well with my back-button on the same page, using the same action.
> 
> Any ideas?
> 
> Alexander
> 

<snip>

>         /**
>          * Key method for mapping methods to buttons
>          */
>         protected Map getKeyMethodMap() {
>                   Map map = new HashMap();
>                   map.put("authors-form.button.create",         "create");
>                   map.put("authors-form.button.edit",           "edit");
>                   map.put("authors-form.button.remove",         "remove");
>                   map.put("authors-form.button.forwar",                 "forward");

Is the above line in your code correct ...  "authors-form.button.forwar" ?


>                   map.put("authors-form.button.back",           "back");
>                   return map;
>                 }
> 
> 

</snip>

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


Re: LookupDispatchAction doesn't lookup mapping

Posted by Dakota Jack <da...@gmail.com>.
The code in LookupDispatchAction is:


        String key = (String) lookupMap.get(name);

        String methodName = (String) keyMethodMap.get(key);

Therefore, if you know what your code is returning as "key" and you
know what your code is returning as "methodName" and if the "key" is
correct, the keyMethodMap has to contain the wrong value for the
"key".

Jack


On Wed, 08 Dec 2004 14:14:18 +0100, Alexander Czernay
<al...@czernay.com> wrote:
> Dakota Jack wrote:
> > My experience is that the computer is always right, so I would look in
> > my properites file, if I were you, and see whether or not I had
> > reversed the myButtonForward=go to go=myButtonForward.  Did you?  I
> > feel compelled to reiterate that LookupDispatchAction is a fairly poor
> > example of the code needed to do this stuff, in my opinion.
> >
> > Jack
> >
> >
> 
> I will definitely try your suggestion out, but before that, I wanted to
> figure out, what I had done wrong using the LookupDispatchAction.
> 
> So now some direct copy & paste from my code.
> My ApplicationRessurces.properties looks like this:
> <snip>
> authors-form.button.forward = weiter
> authors-form.button.back = zurück
> </snip>
> 
> The jsp:
> <snip>
> <html:form action="/authors-list"><html:submit
> property="submit"><bean:message
> key="authors-form.button.back"/></html:submit></html:form>
> <html:form action="/authors-list"><html:submit
> property="submit"><bean:message
> key="authors-form.button.forward"/></html:submit></html:form>
> </snip>
> 
> And finally the Action-Map:
> <snip>
>         protected Map getKeyMethodMap() {
>                   Map map = new HashMap();
>                   map.put("authors-form.button.create",         "create");
>                   map.put("authors-form.button.edit",           "edit");
>                   map.put("authors-form.button.remove",         "remove");
>                   map.put("authors-form.button.forward",        "forward");
>                   map.put("authors-form.button.back",           "back");
>                   return map;
>                 }
> </snip>
> 
> The back-button works, while the forward doesn't.
> 
> The LookupDispatchAction tries to call a method named "weiter" instead
> of "forward", while it calls the "back"-method as expected.
> 
> 
> 
> Alexander
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 


-- 


"You can't wake a person who is pretending to be asleep."

~Native Proverb~

"Each man is good in His sight. It is not necessary for eagles to be crows."

~Hunkesni (Sitting Bull), Hunkpapa Sioux~

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


Re: LookupDispatchAction doesn't lookup mapping

Posted by Alexander Czernay <al...@czernay.com>.
Dakota Jack wrote:
> My experience is that the computer is always right, so I would look in
> my properites file, if I were you, and see whether or not I had
> reversed the myButtonForward=go to go=myButtonForward.  Did you?  I
> feel compelled to reiterate that LookupDispatchAction is a fairly poor
> example of the code needed to do this stuff, in my opinion.
> 
> Jack
> 
> 

I will definitely try your suggestion out, but before that, I wanted to 
figure out, what I had done wrong using the LookupDispatchAction.

So now some direct copy & paste from my code.
My ApplicationRessurces.properties looks like this:
<snip>
authors-form.button.forward = weiter
authors-form.button.back = zurück
</snip>

The jsp:
<snip>
<html:form action="/authors-list"><html:submit 
property="submit"><bean:message 
key="authors-form.button.back"/></html:submit></html:form>
<html:form action="/authors-list"><html:submit 
property="submit"><bean:message 
key="authors-form.button.forward"/></html:submit></html:form>
</snip>

And finally the Action-Map:
<snip>
	protected Map getKeyMethodMap() {
	 	  Map map = new HashMap();
	 	  map.put("authors-form.button.create", 	"create");
	 	  map.put("authors-form.button.edit", 		"edit");
	 	  map.put("authors-form.button.remove", 	"remove");
	 	  map.put("authors-form.button.forward", 	"forward");
	 	  map.put("authors-form.button.back", 		"back");
	 	  return map;
	 	}
</snip>

The back-button works, while the forward doesn't.

The LookupDispatchAction tries to call a method named "weiter" instead 
of "forward", while it calls the "back"-method as expected.

Alexander

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


Re: LookupDispatchAction doesn't lookup mapping

Posted by Dakota Jack <da...@gmail.com>.
I meant mybutton.forward=go to go=mybutton.forward


On Wed, 8 Dec 2004 04:46:58 -0800, Dakota Jack <da...@gmail.com> wrote:
> My experience is that the computer is always right, so I would look in
> my properites file, if I were you, and see whether or not I had
> reversed the myButtonForward=go to go=myButtonForward.  Did you?  I
> feel compelled to reiterate that LookupDispatchAction is a fairly poor
> example of the code needed to do this stuff, in my opinion.
> 
> Jack
> 
> On Wed, 08 Dec 2004 09:51:58 +0100, Alexander Czernay
> 
> 
> <al...@czernay.com> wrote:
> > Dakota Jack wrote:
> >
> >
> > > On Tue, 07 Dec 2004 12:02:52 +0100, Alexander Czernay
> > > <al...@czernay.com> wrote:
> > >
> > >> The problem is, that only one of those buttons
> > >>works, while the other throws a MissingResourceAction. That sounds like
> > >>a typo, but the strange thing is, that it tries to lookup the button's
> > >>value rather than it's name (eg. having a ressource mapping like
> > >>mybutton.forward=go it would try to lookup "go").
> > >
> > >
> > > I presume that you know that lookup dispatch action DOES lookup the
> > > buttons value rather than its name?  I just mention this because your
> > > wording half indicates that you find this surprising.
> > >
> > > Jack
> > >
> >
> > Well, as far as I understand it, it takes the button value (eg. "go")
> > and tries to match it in Application.properties, where it should find
> > "mybutton.forward" that it looks up in the getKeyMethodMap() inside the
> > LookupDispatchAction. My problem is, that my application tries to lookup
> > "go" rather than "mybutton.forward" for one button, while it works for
> > the other.
> >
> > I double-checked all occurences of the lookup-string and also tried to
> > rename it in case of some cruel naming conflict. It just doesn't work.
> >
> > Alexander
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
> 
> --
> 
> "You can't wake a person who is pretending to be asleep."
> 
> ~Native Proverb~
> 
> "Each man is good in His sight. It is not necessary for eagles to be crows."
> 
> ~Hunkesni (Sitting Bull), Hunkpapa Sioux~
> 


-- 


"You can't wake a person who is pretending to be asleep."

~Native Proverb~

"Each man is good in His sight. It is not necessary for eagles to be crows."

~Hunkesni (Sitting Bull), Hunkpapa Sioux~

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


Re: LookupDispatchAction doesn't lookup mapping

Posted by Dakota Jack <da...@gmail.com>.
My experience is that the computer is always right, so I would look in
my properites file, if I were you, and see whether or not I had
reversed the myButtonForward=go to go=myButtonForward.  Did you?  I
feel compelled to reiterate that LookupDispatchAction is a fairly poor
example of the code needed to do this stuff, in my opinion.

Jack


On Wed, 08 Dec 2004 09:51:58 +0100, Alexander Czernay
<al...@czernay.com> wrote:
> Dakota Jack wrote:
> 
> 
> > On Tue, 07 Dec 2004 12:02:52 +0100, Alexander Czernay
> > <al...@czernay.com> wrote:
> >
> >> The problem is, that only one of those buttons
> >>works, while the other throws a MissingResourceAction. That sounds like
> >>a typo, but the strange thing is, that it tries to lookup the button's
> >>value rather than it's name (eg. having a ressource mapping like
> >>mybutton.forward=go it would try to lookup "go").
> >
> >
> > I presume that you know that lookup dispatch action DOES lookup the
> > buttons value rather than its name?  I just mention this because your
> > wording half indicates that you find this surprising.
> >
> > Jack
> >
> 
> Well, as far as I understand it, it takes the button value (eg. "go")
> and tries to match it in Application.properties, where it should find
> "mybutton.forward" that it looks up in the getKeyMethodMap() inside the
> LookupDispatchAction. My problem is, that my application tries to lookup
> "go" rather than "mybutton.forward" for one button, while it works for
> the other.
> 
> I double-checked all occurences of the lookup-string and also tried to
> rename it in case of some cruel naming conflict. It just doesn't work.
> 
> Alexander
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 


-- 


"You can't wake a person who is pretending to be asleep."

~Native Proverb~

"Each man is good in His sight. It is not necessary for eagles to be crows."

~Hunkesni (Sitting Bull), Hunkpapa Sioux~

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


Re: LookupDispatchAction doesn't lookup mapping

Posted by Alexander Czernay <al...@czernay.com>.
Dakota Jack wrote:
> On Tue, 07 Dec 2004 12:02:52 +0100, Alexander Czernay
> <al...@czernay.com> wrote:
> 
>> The problem is, that only one of those buttons
>>works, while the other throws a MissingResourceAction. That sounds like
>>a typo, but the strange thing is, that it tries to lookup the button's
>>value rather than it's name (eg. having a ressource mapping like
>>mybutton.forward=go it would try to lookup "go"). 
> 
> 
> I presume that you know that lookup dispatch action DOES lookup the
> buttons value rather than its name?  I just mention this because your
> wording half indicates that you find this surprising.
> 
> Jack
> 

Well, as far as I understand it, it takes the button value (eg. "go") 
and tries to match it in Application.properties, where it should find 
"mybutton.forward" that it looks up in the getKeyMethodMap() inside the 
LookupDispatchAction. My problem is, that my application tries to lookup 
"go" rather than "mybutton.forward" for one button, while it works for 
the other.

I double-checked all occurences of the lookup-string and also tried to 
rename it in case of some cruel naming conflict. It just doesn't work.

Alexander

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


Re: LookupDispatchAction doesn't lookup mapping

Posted by Dakota Jack <da...@gmail.com>.
On Tue, 07 Dec 2004 12:02:52 +0100, Alexander Czernay
<al...@czernay.com> wrote:
>  The problem is, that only one of those buttons
> works, while the other throws a MissingResourceAction. That sounds like
> a typo, but the strange thing is, that it tries to lookup the button's
> value rather than it's name (eg. having a ressource mapping like
> mybutton.forward=go it would try to lookup "go"). 

I presume that you know that lookup dispatch action DOES lookup the
buttons value rather than its name?  I just mention this because your
wording half indicates that you find this surprising.

Jack

-- 


"You can't wake a person who is pretending to be asleep."

~Native Proverb~

"Each man is good in His sight. It is not necessary for eagles to be crows."

~Hunkesni (Sitting Bull), Hunkpapa Sioux~

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


Re: LookupDispatchAction doesn't lookup mapping

Posted by Dakota Jack <da...@gmail.com>.
You might want to look at
http://www.michaelmcgrady.com/button/jsp/dispatch_util.jsp.

This would mean, for example, that you could do what you want with the
following code, requiring nothing else:


JSP CODE  (changes property="submit" for example, to property="edit.dispatch")

<html:form 
  action="/authors-list">
	<html:submit 
	  property="edit.dispatch">
	    <bean:message 
	      key="authors-form.button.edit"/>
	</html:submit>
	<html:submit 
	  property="remove.dispatch">
	    <bean:message 
	      key="authors-form.button.remove"/>
	</html:submit>
	<html:hidden 
	  property="id" 
	  name="author"/>
</html:form>

ACTION CODE (you code the actions, e.g. edit(...) and remove( ...) in
your action as before)

ActionForward forward    = null;

try {
	forward = new DispatchUtil().dispatch(this,mapping,form,request,response);
} catch (Exception e) {
}
return forward;

LookupDispatchAction is pretty complicated, and perhaps unnecessarily
so: http://www.michaelmcgrady.com/button/jsp/button_talk.jsp .

Jack


On Tue, 07 Dec 2004 12:02:52 +0100, Alexander Czernay
<al...@czernay.com> wrote:
> I have a strange problem with LookupDispatchAction:
> I built a form displaying several entries from a db as a list. There are
> several buttons for editing/removing the entries an also two buttons for
> paging though the list. The problem is, that only one of those buttons
> works, while the other throws a MissingResourceAction. That sounds like
> a typo, but the strange thing is, that it tries to lookup the button's
> value rather than it's name (eg. having a ressource mapping like
> mybutton.forward=go it would try to lookup "go"). All this works
> perfectly well with my back-button on the same page, using the same action.
> 
> Any ideas?
> 
> Alexander
> 
> ApplicationRessources.properties:
> # Form Labels
> authors-form.button.create = Autor hinzufügen
> authors-form.button.remove = Autor löschen
> authors-form.button.edit = Autor bearbeiten
> authors-form.button.list = Autoren auflisten
> authors-form.button.forward = weiter
> authors-form.button.back = zurück
> 
> list.jsp
> <%@ page language="java"%>
> <%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>
> <%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
> <%@ taglib uri="http://jakarta.apache.org/struts/tags-logic"
> prefix="logic"%>
> <logic:messagesPresent message="false">
> <div class="error">
>         <html:messages id="msg" message="false">
>               <bean:write name="msg" filter="false"/>
>         </html:messages>
> </div>
> </logic:messagesPresent>
> <logic:messagesPresent message="true">
> <div class="status">
>         <html:messages id="msg" message="true">
>               <bean:write name="msg" filter="false"/>
>         </html:messages>
> </div>
> </logic:messagesPresent>
> <div class="group">
> <html:form action="/authors-list"><html:submit
> property="submit"><bean:message
> key="authors-form.button.create"/></html:submit></html:form>
> <html:form action="/authors-list"><html:submit
> property="submit"><bean:message
> key="authors-form.button.back"/></html:submit></html:form>
> <bean:write name="authorForm" property="strutsPage"/>
> <html:form action="/authors-list"><html:submit
> property="submit"><bean:message
> key="authors-form.button.forward"/></html:submit></html:form>
> </div>
> <div class="group">
> <table class="list">
> <tr><th>Command</th><th>Author</th></tr>
> <logic:iterate name="AUTHORS" id="author" indexId="author_id">
> <tr><td><html:form action="/authors-list"><html:submit
> property="submit"><bean:message
> key="authors-form.button.edit"/></html:submit><html:submit
> property="submit"><bean:message
> key="authors-form.button.remove"/></html:submit><html:hidden
> property="id" name="author"/></html:form></td><td><bean:write
> name="author" property="name"/> - <bean:write name="author"
> property="description"/></td></tr>
> </logic:iterate>
> </table>
> </div>
> <div class="group">
> <html:form action="/authors-list"><html:submit
> property="submit"><bean:message
> key="authors-form.button.create"/></html:submit></html:form>
> </div>
> 
> AuthorsActionList.java
> package de.sbow.struts.action.Authors;
> 
> import java.util.HashMap;
> import java.util.Map;
> 
> import javax.servlet.http.HttpServletRequest;
> import javax.servlet.http.HttpServletResponse;
> 
> import org.apache.commons.beanutils.BeanUtils;
> import org.apache.commons.logging.Log;
> import org.apache.struts.action.ActionForm;
> import org.apache.struts.action.ActionForward;
> import org.apache.struts.action.ActionMapping;
> import org.apache.struts.actions.LookupDispatchAction;
> 
> import de.sbow.MSys.Authors.value.AuthorBeanValue;
> import de.sbow.common.ServiceLocator;
> import de.sbow.struts.form.AuthorEditForm;
> import de.sbow.struts.model.AuthorModel;
> 
> /**
>   * @author Alexander
>   *
>   * The Struts action-class for presenting
>   * the Authors list.
>   *
>   */
> public class AuthorsListAction extends LookupDispatchAction {
>         private static Log log = ServiceLocator.getInstance().getLog(
>                         AuthorsListAction.class);
> 
>         /**
>          * Key method for mapping methods to buttons
>          */
>         protected Map getKeyMethodMap() {
>                   Map map = new HashMap();
>                   map.put("authors-form.button.create",         "create");
>                   map.put("authors-form.button.edit",           "edit");
>                   map.put("authors-form.button.remove",         "remove");
>                   map.put("authors-form.button.forwar",                 "forward");
>                   map.put("authors-form.button.back",           "back");
>                   return map;
>                 }
> 
>         /**
>          * Method create
>          * @param mapping
>          * @param form
>          * @param request
>          * @param response
>          * @return ActionForward
>          */
>         public ActionForward create(
>                         ActionMapping mapping,
>                         ActionForm form,
>                         HttpServletRequest request,
>                         HttpServletResponse response) throws Exception {
> 
>                 // get form
>                 AuthorEditForm authorForm = (AuthorEditForm) form;
>                 // TODO check if this makes sense!
>                 authorForm.reset(mapping, request);
> 
>                 log.debug("Forwarding to \"authors create\".");
>                 return mapping.findForward("create");
>                         }
> 
>         /**
>          * Method edit
>          * @param mapping
>          * @param form
>          * @param request
>          * @param response
>          * @return ActionForward
>          */
>         public ActionForward edit(
>                         ActionMapping mapping,
>                         ActionForm form,
>                         HttpServletRequest request,
>                         HttpServletResponse response) throws Exception {
> 
>                 // get form
>                 AuthorEditForm authorForm = (AuthorEditForm) form;
>                 // get author-model
>                 AuthorModel am = new AuthorModel();
>                 // retieve author via model
>                 AuthorBeanValue author = am.findById(authorForm.getId());
>                 // copy author into form
>                 BeanUtils.copyProperties(authorForm, author);
> 
>                 log.debug("Forwarding to \"authors edit\".");
>                 return mapping.findForward("edit");
>                         }
> 
>         /**
>          * Method remove
>          * @param mapping
>          * @param form
>          * @param request
>          * @param response
>          * @return ActionForward
>          */
>         public ActionForward remove(
>                         ActionMapping mapping,
>                         ActionForm form,
>                         HttpServletRequest request,
>                         HttpServletResponse response) throws Exception {
> 
>                 // get form
>                 AuthorEditForm authorForm = (AuthorEditForm) form;
>                 // get author-model
>                 AuthorModel am = new AuthorModel();
>                 // retieve author via model
>                 AuthorBeanValue author = am.findById(authorForm.getId());
>                 // copy author into form
>                 BeanUtils.copyProperties(authorForm, author);
> 
>                 log.debug("Forwarding to \"authors remove\".");
>                 return mapping.findForward("remove");
>                         }
> 
>         /**
>          * Method forward
>          * @param mapping
>          * @param form
>          * @param request
>          * @param response
>          * @return ActionForward
>          */
>         public ActionForward forward(
>                         ActionMapping mapping,
>                         ActionForm form,
>                         HttpServletRequest request,
>                         HttpServletResponse response) throws Exception {
> 
>                 // get form
>                 AuthorEditForm authorForm = (AuthorEditForm) form;
>                 authorForm.setStrutsPage(authorForm.getStrutsPage() +1 );
> 
>                 log.debug("Forwarding to \"authors list\".");
>                 return mapping.findForward("list");
>                         }
> 
>         /**
>          * Method back
>          * @param mapping
>          * @param form
>          * @param request
>          * @param response
>          * @return ActionForward
>          */
>         public ActionForward back(
>                         ActionMapping mapping,
>                         ActionForm form,
>                         HttpServletRequest request,
>                         HttpServletResponse response) throws Exception {
> 
>                 // get form
>                 AuthorEditForm authorForm = (AuthorEditForm) form;
>                 authorForm.setStrutsPage(authorForm.getStrutsPage() -1 );
> 
>                 log.debug("Forwarding to \"authors list\".");
>                 return mapping.findForward("list");
>                         }
> 
> }
> 
> struts-config.xml
>                 <action path="/authors-list"
>                         name="authorForm"
>                         input="msys.authors-list"
>                         scope="request"
>                         validate="false"
>                         parameter="submit"
>                         type="de.sbow.struts.action.Authors.AuthorsListAction">
>                         <forward name="list" path="msys.authors-list"/>
>                         <forward name="edit" path="msys.authors-edit" />
>                         <forward name="create" path="msys.authors-create" />
>                         <forward name="remove" path="msys.authors-remove" />
>                 </action>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 


-- 


"You can't wake a person who is pretending to be asleep."

~Native Proverb~

"Each man is good in His sight. It is not necessary for eagles to be crows."

~Hunkesni (Sitting Bull), Hunkpapa Sioux~

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