• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Cant get DispatchAction to work

 
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is my first attempt at a DispatchAction and I cant seem to get it to work
<action forward="/select.jsp" path="/select"/>
<action path="/dispatchUserSubmit" type="ch12.UserDispatchAction" parameter="method">
<forward name="insert" path="/setUpForm.do"/>
</action>
select.jsp
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<html:html>
<body>
<html:form action="/dispatchUserSubmit">

<html:select property="method" size="4" onchange="submit()">
<html ption value="create">Create</html ption>
<html ption value="delete">Delete</html ption>
<html ption value="insert">Insert</html ption>
<html ption value="update">Update</html ption>
</html:select>

</html:form>
</body>
</html:html>
package ch12;
import org.apache.struts.actions.DispatchAction;
import javax.servlet.http.*;
import org.apache.struts.action.*;
public class UserDispatchAction extends DispatchAction {

public ActionForward insert(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
return mapping.findForward("insert");
}
}
Im currently getting the following error
javax.servlet.ServletException: Cannot retrieve definition for form bean null
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:867)
 
author
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks like your action-mapping needs a "name" attribute - which points to a <form-bean> definition in struts-config.xml.
 
john mattucci
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
but i dont need a form for what im attempting. Do i still need to define a form even though i wont be using it

and when i define a form I get the error
No getter method available for property method for bean under name org.apache.struts.taglib.html.BEAN
thats because the property named "method" is defined
<html:select property="method" size="4" onchange="submit()">
<html ption value="create">Create</html ption>
<html ption value="delete">Delete</html ption>
<html ption value="insert">Insert</html ption>
<html ption value="update">Update</html ption>
</html:select>
and I define method in the struts-config file
<action path="/dispatchUserSubmit" type="ch12.UserDispatchAction" parameter="method">
what am i doing wrong or forgetting to do to get this to work
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
When you use DispatchAction class we can have more than one method in our action class(I think you know this right )Now I will show a small example how to use DispatchAction class
I have a action class for my registration of a form. In that i have methods for inserting the registered data to the table, deleting some record and for modifying the record
the class will be like this
public RegAction extends DispatchAction
{
public ActionForward insertDetails(ActionMapping mapping,
ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
*** your code**
return mapping.findForward("inserted");
}
public ActionForward deleteDetails(ActionMapping mapping,
ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
*** code ***
return mapping.findForward("deleted");
}
}
This class i am mappiing as
<action mapping="/register" name="regForm" type="mypackage1.RegAction" parameter="option" input="/register.jsp">
<forward name="inserted" path="/menu.jsp"/>
<forward name="deleted" path="/login.jsp"/>
</action>
You can give the forward as you want. Now in the jsp you have to give the form action as
<html:form action="/register?option=insertDetails">
</html:form> . This is for insertion part for delete part give option=deleteDetails.
Here insead of option you can use what name you want . Only thing is that it should match with what we are specifying as parameter in the action mapping.
there option= whatever we are giving is the method name which we want to use for that particular action
hope this will help you
Try like this
 
I claim this furniture in the name of The Ottoman Empire! You can keep this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic