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 7083325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:09:50+00:00 2026-05-28T07:09:50+00:00

I am new to jsf jpa rest.I was wondering how do set values in

  • 0

I am new to jsf jpa rest.I was wondering how do set values in beans from the controller beans.

Say suppose once the user registers I want to insert the values to the DB along with date which I generate in the controllerbean.Now how do I set this in the POJO

register.xhtml

<h:form id="registerForm">
            <table>
                <tr>
                    <td colspan="3" id="register">
                        <h2 style="border-bottom: 1px solid #CCCCCC;">Customer
                            Information</h2>
                        <tr>
                            <td class="label">
                                <h:outputLabel for="name" value="Name:"></h:outputLabel>
                            </td>
                            <td class="field">
                                <h:inputText id="name" size="20" required="true" requiredMessage="Please enter your name" value="#{registerController.selected.contactName}">
                                    <f:validateLength maximum="50"></f:validateLength>
                                </h:inputText>
                            </td>
                        </tr>
                        <tr>
                            <td class="label">
                                <h:outputLabel for="company" value="Company:"></h:outputLabel>
                            </td>
                            <td class="field">
                                <h:inputText id="company" size="20" required="true" requiredMessage="Please enter your company" value="#{registerController.selected.company}">
                                    <f:validateLength maximum="50"></f:validateLength>
                                </h:inputText>
                            </td>
                        </tr>
                        <tr>
                            <td class="label">
                                <h:outputLabel for="designation" value="Designation:"></h:outputLabel>
                            </td>
                            <td class="field">
                                <h:inputText id="designation"  size="20" required="true" requiredMessage="Please enter your designation" value="#{registerController.selected.designation}">
                                    <f:validateLength maximum="50"></f:validateLength>
                                </h:inputText>

                            </td>
                        </tr>
                        <tr>
                            <td class="label">
                                <h:outputLabel for="email" value="Email Id:"></h:outputLabel>
                            </td>
                            <td class="field">
                                <h:inputText id="email"  size="20" required="true" requiredMessage="Please enter your email,eg:yourid@domain.com" value="#{registerController.selected.primaryEmailId}" title="eg:www.domain.com OR http://127.0.0.1/domain">
                                    <f:validateLength maximum="70"></f:validateLength>
                                </h:inputText>
                            </td>
                        </tr>
                        <tr>
                            <td class="label">
                                <h:outputLabel for="phone" value="Contact No:"></h:outputLabel>
                            </td>
                            <td class="field">
                                <h:inputText id="phone" size="20" required="true" requiredMessage="Please enter your contact number" value="#{registerController.selected.contactNo}" title="eg:+919999999999">
                                    <f:validateLength minimum="13" maximum="25"></f:validateLength>
                                </h:inputText>
                            </td>
                        </tr>

                    </td>

                </tr>
                <tr>
                    <td colspan="4" id="loginInfo">
                        <h2 style="border-bottom: 1px solid #CCCCCC;">Login Information</h2>
                        <tr>
                            <td class="label"> 
                                <h:outputLabel for="email" value="Login Email:"></h:outputLabel>
                            </td>
                            <td class="field">
                                <h:inputText id="email"  size="20" maxlength="70" required="true" requiredMessage="Please enter your login email id,eg:yourid@domain.com" value="#{loginController.selected.clientId}">
                                    <f:validateLength maximum="70"></f:validateLength>
                                </h:inputText>

                            </td>
                        </tr>
                        <tr>
                            <td class="label">
                                <h:outputLabel for="password" value="Password:"></h:outputLabel>
                            </td>
                            <td class="field">
                                <h:inputSecret id="password"  size="20" maxlength="70" required="true" requiredMessage="Please enter your desired password(minimun 6 characters)" value="#{loginController.selected.password}">
                                    <f:validateLength minimum="6" maximum="50"></f:validateLength>
                                </h:inputSecret>

                            </td>
                        </tr>
                        <tr>
                            <td class="label">
                                <h:outputLabel for="confirm_password" value="Confirm Password:"></h:outputLabel>
                            </td>
                            <td class="field">
                                <h:inputSecret id="confirm_password" size="20" required="true" requiredMessage="Please confirm your password">
                                    <f:validateLength minimum="6" maximum="50"></f:validateLength>
                                </h:inputSecret>
                            </td>
                        </tr>
                    </td>
                    <tr>
                        <td>
                            <h:commandButton value="Sign Up" action="">
                            </h:commandButton>
                        </td>
                    </tr>
                </tr>
                </table>

Now my Register and login bean contain getters and setters

login bean

       public String getLoginEmail() {
        return loginEMail;
    }

    public void setLoginEmail(String loginEMail) {
        this.loginEMail = loginEMail;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

Register bean

    public String getContactName() {
        return contactName;
    }

    public void setContactName(String ContactName) {
        this.contactName = contactName;
    }

    public String getCompany() {
        System.out.println("get....." + company);
        return company;
    }

    public void setCompany(String company) {
        this.company = company;
        System.out.println("set....." + company);
    }

    public String getDesignation() {
        System.out.println("get....." + designation);
        return designation;
    }

    public void setDesignation(String designation) {
        this.designation = designation;
        System.out.println("set....." + primaryDesignation);
    }

    public String getContactNo() {
        return contactNo;
    }

    public void setContactNo(String contactNo) {
        this.contactNo = contactNo;;
    }

    public String getEmailId() {
        return emailId;
    }

    public void setEmailId(String emailId) {
        this.emailId = emailId;
    }

    public String getActiveFlag() {
        return activeFlag;
    }

    public void setActiveFlag(String activeFlag) {
        this.activeFlag = activeFlag;
    }

    public String getCreatedBy() {
        System.out.println("get create name....." + createdBy);
        createdBy=getPrimaryContactName();
        return createdBy;
    }

    public void setCreatedBy(String primaryContactName) {
        this.createdBy = primaryContactName;
    }

    public Date getCreatedOn() {
        return createdOn;
    }

    public void setCreatedOn(Date createdOn) {
        this.createdOn = createdOn;
        System.out.println("set....." + createdOn);
    }
    public String getLastUpdatedBy() {
        return lastUpdatedBy;
    }

    public void setLastUpdatedBy(String primaryContactName) {
        this.lastUpdatedBy = primaryContactName;
    }
    public Date getLastUpdatedOn() {
        return lastUpdatedOn;
    }

   public void setLastUpdatedOn(Date lastUpdatedOn) {
       this.lastUpdatedOn = lastUpdatedOn;
    }

I have two controllers registerController and loginController where I have the business logic.

@ManagedBean(name = "registerController")
@SessionScoped
    public String prepareCreate() {
    System.out.println("Inside create");
    current = new Register();
    System.out.println("Inside create current");
    selectedItemIndex = -1;
    return "Signup Success";
}

public String create() {
    try {
        System.out.println("I am inside create");
        getFacade().create(current);
        JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/Bundle").getString("RegisterCreated"));
        return prepareCreate();
    } catch (Exception e) {
        System.out.println("I am here inside create exception");
        e.printStackTrace();
        JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
        return null;
    }
}

public Date generateCurrentTime()
{
    // get current system time yyyy/MMM/dd HH:mm:ss
    Calendar currentDate = Calendar.getInstance();
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
    String dateNow = formatter.format(currentDate.getTime());
            Date convertedDate=null;
            try
            {
            convertedDate=formatter.parse(dateNow);
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
            System.out.println("date now is:"+dateNow);
            return convertedDate;
}

Similarly loginController also contains the same code.
How do I set the convertedDate attribute for createdOn and lastUpdatedOn feilds in the pojo??

I used @ManagedBeanProperty but it dint set the value…

@ManagedBeanProperty(value=#{registerController.getgenerateCurrentTime})
  @Column(name = "created_on")
   @Temporal(TemporalType.DATE)
   private Date createdOn;


  @ManagedBeanProperty(value=#{registerController.getgenerateCurrentTime})
  @Column(name = "created_on")
   @Temporal(TemporalType.DATE)
   private Date lastUpdatedOn;

Kindly point out where I am goin wrong.I have used @sessionscoped

Also as u can see I have two tables in a form and they are dependent on each other.How do I insert them into database when user clicks on register button…Should I pass the control initially on the button click to controller say setupController and then call register and login controller

Thanks:)

  • 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-28T07:09:51+00:00Added an answer on May 28, 2026 at 7:09 am
    <h:commandButton value="Sign Up" action="">
    

    does the submission of the form which leads to storing the values of fields in back bean (if no ajax used)

    and providing an action in command button like action="#{setupController.create}" will cause the invokation of that method create on the submission of the form after the assignment of the fields to the bean.

    also you can provide it in action of form

    refer How to define form action in JSF?

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

Sidebar

Related Questions

I'm new to JSF and am wondering if I got things right. Let's say
Standard Java EE environment: JPA + EJB called from JSF beans. Server: glassfish 3.1.1
I am new to JSF and managed beans. I have a managed bean with
In a create new user jsf page, I have a SelectOneMenu with a custom
I am new to JSF and was wondering if there is any way to
As I'm new to JSF framework, wanted to know how to add the user
I'm new in jsf and jpa technologies, and trying my first web application with
i'm new with JPA, i'm using in a JSF 2 Project with Glassfish 3
I'm new to JSF and I have been trying to store data from a
I am VERY new to JSF, and I need some help doing, what I

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.