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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to