Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8969671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:37:32+00:00 2026-06-15T17:37:32+00:00

I have a working JSF application that allows a user to enter their name,

  • 0

I have a working JSF application that allows a user to enter their name, press the Submit button, and they are presented with a page that welcomes them.

The structure is very simple, there is a Person bean that has a setter and getter for a name, and the textfield sets the name, and the welcome page gets the name from the bean to present it on the welcome page.

My question is can I invoke java methods from XHTML when the user presses the Submit button, because I need to open a connection to the database. The code for the first page of the application looks like this in the xhtml file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">

<h:head>
 <title>JSF 2.0 Hello World</title>
</h:head>
<h:body>
 <h3>JSF 2.0 Hello World Example - hello.xhtml</h3>
 <h:form>
  <h:inputText value="#{helloBean.name}"></h:inputText>
  <h:commandButton value="Welcome Me" action="welcome"></h:commandButton>
 </h:form>
</h:body>
</html>

So it looks like when they hit Welcome Me, the welcome.xhtml file is called up and the bean is passed to it. But I also need to execute some code to open the database when the Welcome Me button is pressed, how can I do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T17:37:33+00:00Added an answer on June 15, 2026 at 5:37 pm

    For that, the action attribute of the command button should be bound to the action method of the bean.

    <h:commandButton value="Welcome Me" action="#{helloBean.submit}" />
    

    In the method you’ve all the freedom to write down Java code which should be executed when the button is pressed.

    public String submit() {
        // ...
    
        return "welcome";
    }
    

    The returned string will be used as navigation outcome. If you return null or void, it will return to the same view.

    See also:

    • Our JSF wiki page
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JSF/ICEFaces application that was working fine but all of the sudden
I am working on a JSF application. I have recently faced a problem, that
I am working on project in JSF, using Tomcat 7. The application will have
I'm working on a JSF 2 web application. If I define a facelet that
I'working on a enterprise application that uses JSF 2.0, with Netbeans 7.0 and Glassfish
I have a JSF 1.2 application (Sun RI, Facelets, Richfaces) that was used only
Recently I've been trying to upgrade this application that I'm working on from JSF
I am working on a JSF application that connects with Twitter. In one of
i am working on jsf 1.2 application. i have kept bean in request scope
I am working in primefaces 3.3 and jsf 2.0. I have problem in deleting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.