wood burning stoves 2.0*
The moose likes Struts and the fly likes Please review code for LookupDisptach using Image Buttons Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Please review code for LookupDisptach using Image Buttons" Watch "Please review code for LookupDisptach using Image Buttons" New topic
Author

Please review code for LookupDisptach using Image Buttons

ashish kulkarni
Ranch Hand

Joined: Aug 15, 2002
Posts: 130
Hi,
I have a jsp with 2 image buttons, and i needed to
forward the request to different jsp depending upon
the image button clicked by the user, and I want to do
it without using javascript ( I was using javascript
along with DispatchAction class)
Here is what I have done,
I wrote a new class called TestLookupDispatchAction
which extend DispatchAction class, override execute
method and has one abrstact method called
getMethodName
I am pasting the code of my
TestLookupDispatchAction and the class which extends
this TestLookupDispatchAction class and my jsp
definitation of code,
Can people please comment on it
public abstract class TestLookupDispatchAction extends
DispatchAction
{
public ActionForward execute (
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception
{
String methodName = getMethodName(request ,
mapping);
return dispatchMethod (mapping, form,
request, response, methodName);
}
protected abstract String getMethodName
(HttpServletRequest request, ActionMapping mapping );
}
/** class that extends this class**/
public class TestImageButton extends
TestLookupDispatchAction
{
protected String
getMethodName(javax.servlet.http.HttpServletRequest
request, ActionMapping mapping)
{
Enumeration enu = request.getParameterNames
();
String att="";
while(enu.hasMoreElements ())
{
att = (String)enu.nextElement ();
System.out.println ("parameter name: " +
att + "... value: " + request.getParameter (att));
if(att.equals ("add.x"))
{
return "add";
}
else if(att.equals ("change.x"))
{
return "change";
}
else if(att.equals ("back.x"))
{
return "back";
}


}
return "";
}
public ActionForward add (ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
}
}
My jsp definiation
/**
I am using normal html tag because i want to use the
mouse over effect, which is not possible to get using
struts taglib
**/
<html:form action="pages/TestImageButton" >
<input type="image" src="<bean:message
key="button.addoff"/>" name="add"
on Mouse Over="MM_swapImage('add','','<bean:message
key="button.addon"/>',1)"
on Mouse Out="MM_swapImgRestore()"/>
<input type="image" src="<bean:message
key="button.changeoff"/>" name="change"
on Mouse Over="MM_swapImage('change','','<bean:message
key="button.changeon"/>',1)"
on Mouse Out="MM_swapImgRestore()"/>
</html:form>


A$HI$H
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Please review code for LookupDisptach using Image Buttons