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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:54:04+00:00 2026-06-17T23:54:04+00:00

I have some JSF page and some manage bean. In manage bean I create

  • 0

I have some JSF page and some manage bean. In manage bean I create some odel file and try to fill it by JSF. But it doesn’t setup values in. But when i use existing model object in works great.

Here is my JSF code:

 <h:form>           
            <c:set var="patient" value="#{manageBean.patient}" />
            <p:panel id="panel" header="Patient" style="margin-bottom:10px;">  
                <h:panelGrid columns="2">  
                    <h:outputLabel value="First  name" />  
                    <p:inputText id="firstName" required="true" value="#{patient.firstName}" />  

                    <h:outputLabel value="Family  name" />  
                    <p:inputText id="familyName" required="true" value="#{patient.familyName}" />  

                    <h:outputLabel value="Sex"/>
                    <p:selectOneMenu id="sex" rendered="true" value="#{patient.sex}">
                        <f:selectItem itemLabel="Male" itemValue="male" />  
                        <f:selectItem itemLabel="Female" itemValue="female" />  
                    </p:selectOneMenu>

                    <h:outputLabel value="Birthday date" />  
                    <p:calendar value="#{patient.birthdayDate}" mode="inline" id="birthdayDate"/>  

                    <h:outputLabel value="Nationality"/>
                    <p:selectOneMenu id="nationality" rendered="true" value="#{patient.nationality}">
                        <f:selectItem itemLabel="Russian" itemValue="russian" />  
                        <f:selectItem itemLabel="Ukranian" itemValue="ukranian" />  
                    </p:selectOneMenu>

                    <h:outputLabel value="Adress" />  
                    <p:inputText id="adress" required="true" value="#{patient.adress}" />  

                    <h:outputLabel value="Phone number" />  
                    <p:inputMask id="phoneNumber" required="true" value="#{patient.phoneNumber}" mask="(999) 999-9999"/>
                </h:panelGrid>  
            </p:panel> 
            <p:commandButton value="Save" action="#{manageBean.save}" />  
        </h:form>   

And there is my ManageBean:

@ManagedBean(name = "manageBean")
@SessionScoped
public class ManageBean implements Serializable {

    private Patient patient;
    private SessionFactory factory;

    public ManageBean() {
        factory = SessionFactoryWrap.getInstance();
    }

    public Patient getPatient() {
        patient = (Patient) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("patient");
        if (patient == null) {
            //patient = new Patient("", "", Sex.male, new Date(), Nationality.ukranian, "", "");
            patient = new Patient();
        }
        return patient;
    }

    public String save() {
        Session session = factory.openSession();
        Transaction tx = null;
        try {
            tx = session.beginTransaction();
            session.saveOrUpdate(patient);
            tx.commit();
        } catch (HibernateException ex) {
            if (tx != null) {
                tx.rollback();
            }
            ex.printStackTrace();
        } finally {
            session.close();
        }
        patient=null;
        FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("patient", null);
        return "go_home";

    }
}
  • 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-17T23:54:06+00:00Added an answer on June 17, 2026 at 11:54 pm

    Another way you could solve the problem would be to not using any parameter at all and just binding the UIInput components to your attribute directly:

    <h:form>
        <p:panel id="panel" header="Patient" style="margin-bottom:10px;">
            <h:panelGrid columns="2">
                <h:outputLabel value="First  name" />
                <p:inputText id="firstName" required="true"
                    value="#{manageBean.patient.firstName}" />
    <!-- rest of JSF/Facelets code... -->
    </h:form>
    

    Also, following JSF best practices, you could redefine your managed bean in two ways (as far as I can see atm):

    • You don’t need to have the @SessionScoped annotation in order to handle ajax requests, also it would mean that the constructor (and the @PostConstruct method) will be called only once per session. The best option for this case would be the @ViewScoped annotation. More info: Managed Bean Scopes.

    • You must not have any business logic in your getter/setter method because it will be executed for every #{managedBean.property} in your JSF code, more info: Why JSF calls getters multiple times. Knowing this, it would be better to load the session data just once in the bean constructor or in the @PostConstruct method.

    With all this, your managed bean should look like:

    @ManagedBean(name = "manageBean")
    @ViewScoped
    public class ManageBean implements Serializable {
    
        private Patient patient;
        private SessionFactory factory;
    
        public ManageBean() {
        }
    
        @PostConstruct
        public void init() {
            //it would be better to initialize everything here
            factory = SessionFactoryWrap.getInstance();
            patient = (Patient)FacesContext.getCurrentInstance().getExternalContext().
                getSessionMap().get("patient");
            if (patient == null) {
                patient = new Patient();
            }
        }
    
        public Patient getPatient() {
            return patient;
        }
    
        public void setPatient(Patient patient) {
            this.patient = patient;
        }
    
        public String save() {
            Session session = factory.openSession();
            Transaction tx = null;
            try {
                tx = session.beginTransaction();
                session.saveOrUpdate(patient);
                tx.commit();
            } catch (HibernateException ex) {
                if (tx != null) {
                    tx.rollback();
                }
                ex.printStackTrace();
                //in my opinion, it would be better to show a descriptive message
                //instead of returning to the `go_home` view in case of errors.
            } finally {
                session.close();
            }
            //clumsy code line, no need to have it at all
            //patient = null;
            //Don't set the parameter to null, instead remove it from the session map.
            FacesContext.getCurrentInstance().getExternalContext().
                getSessionMap().remove("patient");
            return "go_home";
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some JSF page and some bean, in cae that it is editing
I have got some problems with my JSF page, and (probably) with backing bean.
I have some problem's with a simple application in JSF 2.0. I try to
Background information: I have a file upload applet in my jsf page. This applet
In my JSF file I have below at the start. <h:form><h:commandLink value=Create New Staff
I have a JSF page that has a h:form that has some textfields and
Hopefully someone can explain some behavior to me. I have a JSF page with
I have a JSF page with some common elements and then 4 parts that
In the code below (jsf page), i have some hotel info in display:table rows
I have some problem using JSF <h:selectManyListbox> and Google Chrome. When my page is

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.