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

  • Home
  • SEARCH
  • 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 1057369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:51:26+00:00 2026-05-16T17:51:26+00:00

I am building a JSF application. I defined the GUI and did the select

  • 0

I am building a JSF application. I defined the GUI and did the select statements query the database using select.

Now I must do the insert statements, but I don’t know how to read the value of a JSF input component like <h:inputText> and send it to my bean which performs the insert.

Should <h:inputText> value be mapped through faces-config.xml, so I can have it in my Java code?

  • 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-05-16T17:51:27+00:00Added an answer on May 16, 2026 at 5:51 pm

    You need to put all <h:inputXxx>/<h:selectXxx> components in a <h:form> and bind their value attribute to a bean property via an EL expression like #{bean.property}, backed by a getter/setter pair. When properly set, JSF will automatically set the values in the bean when the form is submitted via a <h:commandXxx> component in the very same form. You can specify a bean action method in action attribute of the <h:commandXxx> component via an EL expression like #{bean.action}, which points to the bare method action(). All submitted values are available right away there the usual Java way.

    Given this JSF form example with one input field and one select field:

    <h:form>
        <h:inputText value="#{bean.text}" required="true" />
        <h:selectOneMenu value="#{bean.choice}" required="true">
            <f:selectItem itemValue="#{null}" />
            <f:selectItem itemValue="One" />
            <f:selectItem itemValue="Two" />
            <f:selectItem itemValue="Three" />
        </h:selectOneMenu>
        <h:commandButton value="submit" action="#{bean.submit}" />
        <h:messages />
        <h:outputText value="#{bean.result}" />
    </h:form>
    

    The following bean prints the submitted values to the stdout, proving that JSF has already set the values long before the moment you access it in the action method.

    package com.example;
    
    import javax.inject.Named;
    import javax.enterprice.context.RequestScoped;
    
    @Named // Use @javax.faces.bean.ManagedBean on outdated environments.
    @RequestScoped // Use @javax.faces.bean.RequestScoped on outdated environments.
    public class Bean {
    
        private String text;
        private String choice;
        private String result;
    
        public void submit() {
            result = "Submitted values: " + text + ", " + choice;
            System.out.println(result);
        }
    
        public String getText() {
            return text;
        }
    
        public void setText(String text) {
            this.text = text;
        }
    
        public String getChoice() {
            return choice;
        }
    
        public void setChoice(String choice) {
            this.choice = choice;
        }
    
        public String getResult() {
            return result;
        }
    }
    

    That’s all. Turning the regular form into an ajax form is a matter of nesting a <f:ajax> in the command component as below.

    <h:commandButton value="submit" action="#{bean.submit}">
        <f:ajax execute="@form" render="@form" />
    </h:commandButton>
    

    You can find another example and valuable links at bottom of our JSF wiki page.

    Do note that whatever you intend to do with the submitted values is beyond the responsibility of JSF. For example, manipulating it, passing into another class, saving it in database, etc. None of this all is related to JSF. It has as being a HTML form based framework already done its job of providing you the submitted values in flavor of usable Java variables. The remainder is up to you.

    To investigate the next step, you should at this point just be doing as if you’ve already a bunch of prepared / hardcoded variables instead of a whole JSF based user interface. For example, in order save to the values in a database, people usually use a business service layer framework like EJB which in turn uses a persistence layer framework like JPA. Some people even use “plain vanilla” JDBC for that. For more links to concrete examples, start here: JSF Controller, Service and DAO.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.