• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Bear Bibeault
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • salvin francis
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
Bartenders:
  • Jj Roberts
  • Carey Brown
  • Scott Selikoff

Problem with 2 buttons in the same form

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everybody,
I am working with a database that has a table of 50000 rows.I've made a form that makes researchs on this table and I am able to show all the results from the table for every research by submitting a button in the form.
Now,I need to get relevant informations as the number of rows and the total and average values for some field of this table.I have thought that a solution is to put 2 button in the form.By submitting the first button I get all the results of the researchs,if I submit the second button I get the relevant informations.
Well,the question is:
Should I create another Action to handle these relevant informations?
I have also read something about the LookupDispatchAction class.Can it work for my goal?
Thanks for any answer,
Mattia
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

You can have one action class for both the buttons But, your action class should extend DispatchAction.

The action class will have one dedicated method for each button.

On clicking the button corresponding method of the action class will be called based on the parameter you pass(Parameter will have the exact method name, you will specify it in struts config file)
 
Mattia Merenda
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mr Baskaran,
can your advice work even if I don't have to use javascript in my project?
Thanks,
Mattia
 
saravanaprabu baskaran
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Ya its struts nothing to do with javascript.
 
Mattia Merenda
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mr Baskaran,
can your advice work even if I don't have to use javascript in my project?
Thanks,
Mattia
 
Mattia Merenda
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mr Baskaran,
now I am trying to do this:
Page.jsp
<html:form action="joblogs">
......
<html:submit value="results" />
<html:submit value="total" />
</html:form>

struts-config.xml
<action input="/joblogsForm.jsp"
type="com.myapp.struts.JoblogsAction"
scope="request"
path="/joblogs"
validate="true"
name="JoblogsActionForm"
parameter="dispatch" >
<forward path="/results.jsp" name="success"/>
<forward path="/totals.jsp" name="total"/>
</action>

JoblogsAction.java
public class JoblogsAction extends DispatchAction {

private final static String SUCCESS = "success";
private final static String TOTAL = "total";

For the moment I don't know how to continue and I don't know how to use the parameter "dispatch" defined in struts-config-xml file.I am reading some page for informations.Should I make to methods in my Action class to handle the 2 buttons?
Thanks,
Mattia
 
saravanaprabu baskaran
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Try the following code:

Page.jsp
--------
<html:form action="joblogs">
......
<a href="joblogs.do?dispatch=calculateResult"><img name="result"></a>
<a href="joblogs.do?dispatch=calculateTotal"><img name="total"></a>
</html:form>

struts-config.xml
------------------
<action path="/joblogs"
type="com.myapp.struts.JoblogsAction"
scope="request"
validate="true"
name="JoblogsActionForm"
parameter="dispatch" >

<forward path="/results.jsp" name="success"/>
<forward path="/totals.jsp" name="total"/>
</action>

JoblogsAction.java
--------------------
public class JoblogsAction extends DispatchAction {

private final static String SUCCESS = "success";
private final static String TOTAL = "total";

public ActionForward calculateResult(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception
{
----- your action code here---
return (mapping.findForward(SUCCESS));
}
public ActionForward calculateTotal(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception
{
----- your action code here---
return (mapping.findForward(TOTAL));
}
}
 
Mattia Merenda
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mr Baskaran,
your advices were good for my project.
My project is working fine.
Thank you
Mattia
 
reply
    Bookmark Topic Watch Topic
  • New Topic