java - JSF adding object to arrayList -


i have been trying add student object arraylist using java server faces, can figure out how it, here hat got far. method need use, , put it?

index

<h:body>     <h:form >         <h:panelgrid columns="2" >             <h:outputtext value="name"/>             <p:inputtext value="#{student.name}" required="true">             <h:outputtext value="age"/>             <p:inputtext value="#{student.age}" required="true">                 <p:commandbutton value="add" action="#{student.showgo()}"><!--go jsf page-->                    <!-- actionlistener needed-->                 </p:commandbutton>           </h:panelgrid>       </h:form> </h:body> 

student bean

@named(value = "student") @requestscoped public class studentbean {   private string name; private int age;  public studentbean(string name, int age) {     this.name = name;     this.age = age; }   public studentbean() { }  public string showgo(){     return "show"; }  public int getage() {     return age; }  public void setage(int age) {     this.age = age; }  public string getname() {     return name; }  public void setname(string name) {     this.name = name; }  } 

list bean

@named(value = "list") @requestscoped public class list {  private arraylist<studentbean> studentlist = new arraylist<>(); public list() { }   public void addstudent() {     studentbean student = new studentbean();     studentlist.add(student); } 

i not sure understood you. if intention save name , age in object , add list, following should serve purpose:

  1. the managed bean in sessionscope can access in next page (`show.xhtml??):

    @named(value = "student") @sessionscoped public class studentbean {   private arraylist<student> studentlist = new arraylist<>();       private string name;      private int age;       public studentbean(string name, int age) {         this.name = name;         this.age = age;      }         public studentbean() {       }        public string showgo(){          stundent student = new student(name, age);          studentlist.add(student);           return "show";      }      public int getage() {         return age;     }      public void setage(int age) {         this.age = age;     }      public string getname() {         return name;     }      public void setname(string name) {         this.name = name;     }      public list<student> getstundentlist() {         return studentlist;     } } 
  2. define simple sundent class javabean:

    public class stundent {     private string name;     private int age;      public stundent() { }      public stundent(string name, int age) {          this.name = name;          this.age = age;     }      // getters , setters } 

    if still have question leave me comment.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -