File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please review code for LookupDisptach using Image Buttons

 
ashish kulkarni
Ranch Hand
Posts: 131
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic