0

I have a beans page with a button. When a button is clicked the action method should be invoked. Sounds simple enough but nothing happens when said button is clicked. No errors to report.

The method:

@ManagedBean(name="verify")
@SessionScoped
public class VerifyUser {

    public void acceptUser() throws ClassNotFoundException, SQLException{
        System.out.println("acceptUser() method is invoked!");
    }
}

JSF Button:

<h:commandButton value="Accept" action="#{verify.acceptUser}" />

Bean is session scoped.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • This is not related to JSF. What value is returned by `ab.getSearchID()`? Does it exactly return the primary key value of your interest based on which a row in the associated database table is supposed to be updated? This should function, if the database connection is established successfully. – Tiny Apr 16 '15 at 20:00
  • the value by getSearchID() is entered by the user on the previous page. It searches through the database and returns the data for that specific ID entered. Works fine. Then on this page I am using the same value for getSearchID() and it is not working. –  Apr 16 '15 at 20:04
  • Put a debug statement such as `System.out.println("searchID = " + ab.getSearchID())` (or a `Logger` statement) immediately after `ApplicantBean ab = (ApplicantBean)...` to see, if a correct value is returned or not. – Tiny Apr 16 '15 at 20:11
  • I can only run this on server –  Apr 16 '15 at 20:24
  • Uh! Where do you run this application at present then? If replacing the placeholder `?` with a correct primary key value in the given SQL statement works directly on the back-end database as expected, then only the value returned by `ab.getSearchID()` may be supposed to be the culprit assuming the database connection and all other external means are correctly settled. – Tiny Apr 16 '15 at 20:34
  • I changed it to this: ps.setString(1, "SBAC007"); that is I gave it an existing value in the database, but it still did not update the required column to 'accepted'. –  Apr 16 '15 at 20:42
  • Is the `acceptUser()` method invoked or not? This isn't entirely clear form the question. If it is invoked, then the problem is actually completely unrelated to JSF and you should concentrate on JDBC part. If it is actually not invoked, then the method's content (thus, JDBC part) is completely irrelevant. – BalusC Apr 16 '15 at 20:51
  • If the database connection itself fails, then it should throw an exception like `java.sql.SQLException` but this is not the case here. You need to put a debug statement inside the `acceptUser()` method to see, if it is invoked properly or not. There is no technical reason after the database connection is successfully established. – Tiny Apr 16 '15 at 20:51
  • Or there is just a `commit()` missing – Kukeltje Apr 17 '15 at 06:26
  • And how do you populate value that is returned by `ab.getSearchId()`. Keep in mind that in you other question you populate a datatable in a weird, uncommon (risky) way – Kukeltje Apr 17 '15 at 06:28
  • I erased everything in the method and just added a simple return statement and it turns out the acceptUser() method is not even getting invoked. I have no idea why. –  Apr 17 '15 at 15:26
  • Much better now. Please read http://stackoverflow.com/help/mcve how to prepare better for future questions. – BalusC Apr 17 '15 at 15:30

0 Answers0