Results 1 to 2 of 2
  1. #1
    Czarny86 is offline Member
    Join Date
    Jul 2013
    Posts
    3
    Rep Power
    0

    Default JSF - problem with ArrayList

    Hi, I`m tryin to resolve my problem with ArrayList, I need to generate random Array with some values and send it to index.xhtml to create table. And i have problem - Type book not present

    Here is my code:

    Java Code:
    import java.io.Serializable;
    import java.sql.ResultSet;
    import java.util.ArrayList;  
    import java.util.List;  
    import javax.faces.bean.ManagedBean;
    import javax.faces.bean.SessionScoped;
    
    
    @SessionScoped
    @ManagedBean
    
    public class Books implements Serializable {
    
    	public static final long serialVersionUID = 1L;
    
    	public int newRows;
    	
    	public List<book> bookshop = new ArrayList<book>();
    
    	
    	public String getRandomAuthor(){
    		String[] authors = new String[10];
    		
    		for (int i=0; i<10; i++)
    			authors[i] = "Autor" + i+1;
    		return authors[(int)(Math.random() * 10)];
    	}
    	
    	public String getRandomTitle(){
    		String[] titles = new String[10];
    		
    		for (int i=0; i<10; i++)
    			titles[i] = "Tytuł" + i+1;
    		return titles[(int)(Math.random() * 10)];
    	}
    	
    	public int getRandomIssn(){
    		return (int)(Math.random() * 1000 + 1100);
    	}
    
    	public double getRandomPrice(){
    		return (double)(Math.random() * 5.99 + 50);
    	}
    	
    	public void randomArray(){
    		for (int r=0; r<50; r++)
    			list.add(getRandomAuthor(), getRandomTitle(), getRandomIssn(), getRandomPrice());
    	}
    	
    	public List<book> getBookshop(){
    		return bookshop;
    	}
    	
    	
    	public void setNewRows(int newRows){
    		this.newRows = newRows;
    	}
    	
    	public int getNewRows(){
    		return newRows;
    	}  
      
    }

  2. #2
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,895
    Rep Power
    5

    Default Re: JSF - problem with ArrayList

    I don't see any import for a class 'book', no. And on top of that I would expect the class to be named 'Book' and not 'book'.

    This is incredibly basic Java by the way - don't expect that you can get anywhere with web development when you don't know core Java front to back yet. This is going to be a very confusing and frustrating experience for you until you take about 2 months worth of steps back and start at the beginning.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. ArrayList problem
    By bakriawad in forum New To Java
    Replies: 6
    Last Post: 06-01-2013, 11:27 PM
  2. Problem with ArrayList's
    By Teedo in forum New To Java
    Replies: 18
    Last Post: 04-21-2012, 04:00 PM
  3. Replies: 12
    Last Post: 07-07-2011, 08:49 PM
  4. ArrayList problem.
    By keo in forum New To Java
    Replies: 4
    Last Post: 10-15-2010, 11:22 AM
  5. Arraylist problem
    By keo in forum New To Java
    Replies: 3
    Last Post: 05-28-2010, 10:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •