Calling a method by a button

Hy outthere,
does anyone know how to call a method in my bean by clicking a button
It's purpose is deleting an item in a Guestbook.
i imagined somethin like that:
<Input type="button" onclick="<% guestbook.deleteItem(); %>">
Or is it a completly different idea for doing something like this?
Thanks much for any help
HECK

Since you are already aware that a client-side script cannot directly call an individual server-side Java Bean method- This is a simple alternative you can follow:
Lets say The Bean is : CDCatalogBean
The method in CDCatalogBean.java : deleteSelectedCD()
The main JSP page: MainOrder.jsp which has the delete
button on it.
The Delete button: <INPUT type=button name=deleteCD value="Delete Entry" onClick="window.location.replace('ModifyList.jsp?buttonPressed=deleteCD')">
//pass button name as a query parameter
ModifyList.jsp : Following Code on this JSP
<jsp:useBean id="catalogBean" class="my.app.CDCatalogBean"
scope="session"/>
<%
if(request.getParameter("buttonPressed").equals("deleteCD")) {
catalogBean.deleteSelectedCD(); // call the bean method
response.sendRedirect("MainOrder.jsp"); //takes you back to the main page
}%>
This page can take appropriate action based on the buttons pressed in the application. I have left out more details but hope you get the idea. There might be a better javaScript function to invoke the ModifyOrder.jsp.
Regards
Sharath

Similar Messages

  • Calling a method with a html Submit button

    hi guys,
    is it possible to call a method from a JSP file using a HTML submit button. I know i can call another website easily doing it this way, is there a similar way available to call a method once the button is clicked?
    FYI
    The method is in a bean file named jdbc. The methods name is getUsername.
    Nice one.
    <form action = <%jdbc.getUsername()%> <input type="submit" value="Submit">

    Dear friend,
    you mentioned that u need to call a method when submit button is clicked. Is the method dynamically created. If not so, then you can include the method on the submit button html file itself.
    Regards,
    Rengaraj.R

  • Calling  dll method from oracle forms

    Hi,
    This is my first post in this forum. I don't know whether this is the right place to post this topic here.
    i wana call DLL method from the button click event of my form.
    I new to oracle development any help will be greatly appreciated.

    Calling DLL using form 6i
    Regards,

  • Calling a method in a bean when i clcked on the radio button of a table

    Hi,
    I need to call a method in the bean when i clicked on the radio button of a table
    I tried it , by callling the method in selectionListener..
    I can able to execute only System.out.prinln method,
    rather than that i am unable to execute any other expression..
    like setting rendering property to a component.
    Thanks in advance,

    Hi,
    what you say is not true. You can execute any code within a selection listener you want. If you can print then it shows the method s called and you can execute whatever you want within this method
    Frank

  • Call java method from button in UIX page

    Greetings,
    I want to call a java method from a button on a uix page.
    Does it have to be a submit button or it maybe a simple button.
    If it was from a JSP page, it would be a much more different process ?
    This method should delete a row from another view (View2).
    delete from tableB ta where ta.field1 = &1
    My question is how do I build the method to delete a row and how do I invoke the method using the button ?
    Thanks

    This sounds like a JDeveloper/ADF issue that is not related to JHeadstart. Can you please log a TAR at MetaLink ( http://metalink.oracle.com/ ), or ask this question at the JDeveloper forum at http://otn.oracle.com/discussionforums/jdev.html ?
    Thanks,
    Sandra Muller
    JHeadstart Team
    Oracle Consulting

  • How to call a method in one JSP from another JSP?

    say that I have 2 JSPs.
    JSP one has a button.
    JSP two has some method that, say, find the square root of the number passed from JPS one.
    How to - when click - the button on page one call the method on page two?
    Please note that I can not use object binding, but I want passing the actual parameter and call the method on page two.
    Please note that this is an update of a previous post on the same topic called "Object scope".
    Thank you all very much.

    No, i dont know how to call other than main methods from other classes
    And one more doubt i have i.e. Like in C can we see the execution of the program like how the code is being compiled step by step and how the value of the variable changes from step to step like(Add Watch).........

  • How to call a method of an other view in the current view

    Hi Guys,
    I have 2 views in my Project: IPrivateValidateIncidentView and IPrivateRoadMapView.  Now, a button in the IPrivateRoadMapView must call a method in the IPrivateValidateIncidentView.  I cannot seem to figgure this out.  I know that I will probably need to arrange things centrally in my Component COntroller somehow.
    I have tried to see what methods I can Invoke on IPrivateValidateIncidentView from within the Controller to see if I can call the method OnActionDoneValidate() from there, but I can only seem to get a constant with this methods name: IPrivateValidateIncidentView.WD_EVENTHANDLER_ON_ACTION_DONE_VALIDATION;
    Please help.
    Christiaan

    Hi,
    You are correct, for your requirement you need to arrange the things centrally that is in Component Controller. As in above reply you need to Create your context in Component controller and then map them to both the views. So data will be available to both the views and finally you create a method in component controller and call that method from second view. So the data changes made in controller will be reflected on First View as they have context mapping.
    Regards
    Raghu

  • How to call a dynamic URL on 'button press' event, in MVC-based BSP

    Hi,
    My requirement is as below:
    On selecting a row in table view, and pressing a button, I need to open a browser.
    The Browser URL depends on the row selected.
    The key field from table view, is added at the end of the URL string.
    Shortly, I can say that, I am getting a value on row selection & want to pass it to button event.
    In Views Section, there are 2 tags- (1)table view & (2)button.
    Right now, I have put the code for getting the key field, in DO_HANDLE_DATA method.
    In Button's OnClientClick method, I have called the Javascript to open the browser.
    If I now write the code to concatenate the key field value to form the dynamic URL in 'OnClick' method,
    it will be called only after the browser is opened.
    (as OnClick event is executed only after OnClientClick event is executed)
    Could anyone please tell me what event (and in which tag) can be used to solve this.
    Is there any event which is triggered, as soon as the row is selected, &  before the button press event is triggered ?
    Would really appreciate responses made to this query.
    Thanks,
    Nisha Vengal.

    Hi Nisha,
    The crux of your issue here is that you want to call the event triggered with onClick before calling the event triggered on onClientClick. This can be achieved by the following code in the function called on the onClientClick.
    function fn_button()
               htmlbSL(this,2,'b_row_selection:onInputProcessing()');
               window.open("new_page",target="BLANK");
    Here, fn_button is the javascript function called on button click, and b_row_selection is the event triggered on the onClick event of row selection.
    Try this out and let us know if it works for you.
    Regards,
    Saurabh

  • Problem calling a method in a servlet witch returns remote ejb

    Hi, I have a problem combining servlets ands ejbs, I expose my problem :
    What I have :
    1 . I have a User table into a SGBD with two attributes login and pass.
    2 . I have a UserBean linked to User table with a remote interface
    3 . I have a stateless UserSessionBean with a remote interface
    4 . I have a UserServlet linked to a jsp page which allows me to add users
    5 . I use Jboss
    What is working ?
    1 - I have a method newUser implemented in my UserSessionBean :
    public class UserSessionBean implements SessionBean {
      private SessionContext sessionContext;
      private UserRemoteHome userRemoteHome;
      public void ejbCreate() throws CreateException {
      // Initialize UserRemoteHome
      // Method to add a new user
      public UserRemote newUser(String login, String password) {
            UserRemote newUser = null;
            try {
                newUser = userRemoteHome.create(login, password);
            } catch (RemoteException ex) {
                System.err.println("Error: " + ex);
            } catch (CreateException ex) {
                System.err.println("Error: " + ex);
            return newUser;
    }2 - When I test this method with a simple client it works perfectly :
    public class TestEJB {
        public static void main(String[] args) {
            Context initialCtx;
            try {
                // Create JNDI context
                // Context initialization
                // Narrow UserSessionHome
                // Create UserSession
                UserSession session = sessionHome.create();
                // Test create
                UserRemote newUser = session.newUser("pierre", "hemici");
                if (newUser != null) {
                    System.out.println(newUser.printMe());
            } catch (Exception e) {
                System.err.println("Error: " + e);
                e.printStackTrace();
    Result : I got the newUser printed on STDOUT and I check in the User table (in the SGBD) if the new user has been created.
    What I want ?
    I want to call the newUser method from the UserServlet and use the RemoteUser returned by the method.
    What I do ?
    The jsp :
    1 - I have a jsp page where a get information about the new user to create
    2 - I put the login parameter and the password parameter into the request
    3 - I call the UserServlet when the button "add" is pressed on the jsp page.
    The Servlet :
    1 - I have a method doInsert which call the newUser method :
    public class UserServlet extends HttpServlet {
        private static final String CONTENT_TYPE = "text/html";
        // EJB Context
        InitialContext ejbCtx;
        // Session bean
        UserSession userSession;
        public void init() throws ServletException {
            try {
                // Open JNDI context (the same as TestClient context)
                // Get UserSession Home
                // Create UserSession
                userSession = userSessionHome.create();
            } catch (NamingException ex) {
                System.out.println("Error: " + ex);
            } catch (RemoteException ex) {
                System.out.println("Error: " + ex);
            } catch (CreateException ex) {
                System.out.println("Error: " + ex);
        protected void service(HttpServletRequest req, HttpServletResponse resp) throws
                ServletException, IOException {
         * Does insertion of the new user in the database.
        public void doInsert(HttpServletRequest req, HttpServletResponse resp) throws
                ServletException, IOException {
            try {
                // Get parameters to create the newUser
                String login = req.getParameter("login");
                String password = req.getParameter("password");
               // Create the newUser
                System.out.println("Calling newUser before");
                UserRemote user = userSession.newUser(login, password);
                System.out.println("Calling newUser after");
            } catch (Exception e) {
        // Clean up resources
        public void destroy() {
    Result :
    When I run my jsp page and click on the "add" button, I got the message "Calling newUser before" printed in STDOUT and the error message :
    ERROR [[userservlet]] Servlet.service() for servlet userservlet threw exception
    javax.servlet.ServletException: loader constraints violated when linking javax/ejb/Handle class
         at noumea.user.UserServlet.service(UserServlet.java:112)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
         at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
         at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
         at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:153)
         at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
         at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
         at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
         at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
         at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
         at java.lang.Thread.run(Thread.java:534)
    Constat :
    I checked into my SGBD and the new user has been created.
    The error appears only when the method return Remote ejbs, if I return simples objects (Strings, int..) it works.
    What can I do to resolve this problem ?
    Thank you.

    "Why do you want to servlet to gain access to another EJB through the stateless session bean. Why cant the servlet call it directly ?"
    Because I want to access to the informations included in the entity bean UserBean (which is remote).
    You said that it is a bad design, but how can I access to my UserBean ejbs from the session bean if I don't do that ?
    For example I want a List of all users to be seen in a jsp page :
    1 - I call the method getUserList which returnsan ArrayList of UserRemote.
    2 - I iterate over the ArrayList to get the users parameters to be seen.
    As the other example (newUser), when I do
    ArrayList users = (ArrayList) userSession.getUserList(); with the simple client it works, but in the servlet I got the same error.
    But, if I call directly the findAll method (as you'are saying) in the servlet
    ArrayList users = (ArrayList) userRemoteHome.findAll(); it works...
    I think that if my servlet calls directly entity ejbs, I don't need UserSession bean anymore. Is that right ?
    I precise that my design is this :
    jsp -> servlet -> session bean -> entity bean -> sgbd
    Is that a bad design ? Do I need the session bean anymore ?
    Thank you.

  • Calling a method in Class from webdynpro

    Hi All,
    I have to perform some action when i click the button created in my webdynpro screen.
    However I must not write the code for the button action inside the button event. But I have to create a class and inside the class i have to create the method for this button event.
    Can anyone tell me how to call a method in a class created in SE24 from webdynpro on clicking the button.
    Thanks in advance.

    hi..
    When you want to perform some action after clicking a Button, then you have to write the code only in 'Events' - 'On Action' event. From your question, i assume that, you wanna use Assistance class in your webdynpro so as to increase better performance. Here is the link which will guide yuo with screen shot for using assistance class in WD-ABAP.
    http://wiki.sdn.sap.com/wiki/display/WDABAP/AssistanceclassfunctionalityinWDA
    thanks,
    Padma

  • Trying to call a method on an RMI server from a GUI

    Hi all, I'm new to the forums and I desperately need some help!
    My question fits into the RMI category but also the database/GUI side so sorry if this is posted in the wrong place.
    My application is a client/server system (programmed in Netbeans 6.8) that also uses GUIs and JDBC-ODBC. Basically, I am trying to call a method that adds an entry to my database from a GUI button.
    Due to the required RMI, I have the ServerInterface that extends Remote and I have a ServerImpl class that implements the Interface, and the RMI works fine so there is no problem there.
    My code for the button is:
    private void addUserActionPerformed(java.awt.event.ActionEvent evt) {                                       
    try{server.addNewUser("new");}
    catch(Exception e){}
    addUser.setText("buttonhaschanged");
    The server variable is declared above as ServerImpl server;
    The actual addNewUser method works fine when it is called explicitly via RMI in my main "Client" class, but this GUI is going to be like an "administrator GUI" that can manipulate the database, so there is no RMI involved here.
    Anyway, my button doesn't have any effect on the database, but the button changes text as desired so the button itself works, but it doesn't do what I want to the database, so I think my problem is the use of my "server" variable. I've tried making it static and I've tried making it of type ServerInterface, but no luck. Would I have to make the GUI class extend the interface too?
    Sorry for rambling on!
    Many thanks in advance
    David
    Edited by: DHD on Feb 26, 2010 6:15 AM

    Would I have to make the GUI class extend the interface too?Your GUI has nothing to do with the RMI. How did you obtaint the "server" ? have you looked in the RMI registry to get the stub object ?
    The second thing to notice is you are invoking a RMI calls on a EDT which you should not do it. Your RMI method calls should be invoked via SwingWorker-->doInBackground(); please take a look at the Java Doc
    [http://java.sun.com/javase/6/docs/api/javax/swing/SwingWorker.html|java Doc SwingWorker sample usage]
    You mentioned that the RMI method invocation works fine from the main class and not from the GUI so what did you do in the main class to get the stub do it in the doInBackground() method
    Regards,
    Alan
    London

  • Calling a method of another Object

    I have 3 panels, panelMain, panelA and panelB
    panelMain is the "main" panel which holds panelA and panelB.
    When a button is clicked in panelB, I wish to call up the a method in panelA, but I get the error
    "non-static method cannot be referenced froma static context"
    What might be the problem?

    It's normal, to call a method of an instance, you must have a handler on the instance. In your case, panelB must have a handler ( a kind of reference if you want) on panelA (i.e. panelB must know the instance of panelA to call a method of panelA).
    For example :
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    class PanelB extends JPanel {
         public PanelA panelA; // to keep the instance of panelA needed to call the methods of panelA
         JLabel messageLabel;
         public PanelB() {
              super();// optional
              JLabel label = new JLabel("This is the panelB");
              add(label);
              JButton button = new JButton("Call panelA method");
              button.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e) {
                        panelA.showMessage(); // call a method of panelA
              add(button);
              messageLabel = new JLabel("");
              add(messageLabel);
         public void setPanelA(PanelA p) { // initialize panelA with the required instance
              panelA = p;
         public void showMessage() {
              messageLabel.setText("Message from panelA");
    class PanelA extends JPanel {
         public PanelB panelB; // to keep the instance of panelB needed to call the methods of panelB
         JLabel messageLabel;
         public PanelA() {
              super();// optional
              JLabel label = new JLabel("This is the panelA");
              add(label);
              JButton button = new JButton("Call panelB method");
              button.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e) {
                        panelB.showMessage(); // call a method of panelB
              add(button);
              messageLabel = new JLabel("");
              add(messageLabel);
         public void setPanelB(PanelB p) { // initialize panelA with the required instance
              panelB = p;
         public void showMessage() {
              messageLabel.setText("Message from panelB");
    public class MainPanel extends JPanel {
         public MainPanel() {
              super(); // optional
              setLayout(new GridLayout(1,2,0,0));
              PanelA pa = new PanelA();
              add(pa);
              PanelB pb = new PanelB();
              add(pb);
              pa.setPanelB(pb);
              pb.setPanelA(pa);
         public static void main(String[] arg) {
              JFrame f = new JFrame("My Frame");
              f.getContentPane().add(new MainPanel());
              f.setBounds(100,100,300,300);
              f.setVisible(true);
    }I hope this helps,
    Denis

  • Calling a method on clicking FileDownload UI

    Hi,
    I need to call a method when I am clicking FileDownload UI. Please tell me if there is any possibilites.
    Best Wishes,
    Idhaya R

    Hi Sumit,
    I want the file to be generated on clicking the filedownload UI. I am having a method to generate the file. If I am able to download and show the file to the user on clicking the button also will be fine. Please tell me is there any possibilities of downloading a file (Working as if clicking File Download) on clicking a button.
    Best Wishes,
    Idhaya R

  • Can we call a method before and after Export operations in ADF 11g

    Hi,
    My problem is I have to execute a method before and after the export operation.Is this posible in ADF 11g
    Regards,
    Felix

    Hi,
    in response to a similatr post of yours, I replied
    1. Drop af:exportCollectionActionListener on a command button
    2. set the command button to display = false
    3. In your Java code, call
    ActionEvent ae = new ActionEvent(button);
    ae.queue();
    Everything you put before
    ActionEvent ae = new ActionEvent(button);
    ae.queue();
    will fires as a pre-trigger, everything after as a post trigger
    Frank

  • Calling ABAP methods in Web-dynpro for ABAP

    Hi
    Can any one tell me how we can call any method which is defined in ABAP.
    eg.
    CALL METHOD ref_edit_chg->get_text_as_stream.
    This is the method i want to call in the first view.
    on the button action Process.
    Please reply at the earliest.
    Ragards,
    Rahul

    Hi Rahul,
    You can use WebServices, please have a look at below links,
    Re: The webdynpro/ABAP (WDA) calling RFC enabled FM of other ECC systems
    /people/thomas.jung3/blog/2004/11/15/bsp-150-a-developer146s-journal-part-xiii-developing-abap-webservices
    BSP a Developer's Journal Part XIV - Consuming WebServices with ABAP
    Regards,
    Nitin

Maybe you are looking for