aspose file tools*
The moose likes Servlets and the fly likes Storing boolean from jsp checkbox into arraylist using bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Storing boolean from jsp checkbox into arraylist using bean" Watch "Storing boolean from jsp checkbox into arraylist using bean" New topic
Author

Storing boolean from jsp checkbox into arraylist using bean

margaret gillon
Ranch Hand

Joined: Nov 12, 2008
Posts: 277
    
    2

I have a bean from the instructor and the task is to use the bean to store data that is being retrieved from a jsp then added to an arraylist that is then forwarded to another jsp. There are two values coming from checkboxes on the first jsp form so they are boolean. I don't understand how to store them in the arraylist but it must be possible because the instructor has them as boolean in the bean. I doubt I am loading the arraylist correctly because I have seen other threads where strings and integers can be stored in the same arraylist. The thrid compile error also has to do with the arraylist, I thought .add was inherited .

Instructor's bean.



The servlet code


The errors on the ant compile

Ivan Jozsef Balazs
Rancher

Joined: May 22, 2012
Posts: 865
    
    5
The error message is rather explicit. You want to put a String where a boolean is expected.

BookServlet.java:54: setPaperback(boolean) in com.javaranch.drive.books.BookData cannot be applied to (java.lang.String)
[javac] newbook.setPaperback(servletData.getParameter("paperback"));

margaret gillon
Ranch Hand

Joined: Nov 12, 2008
Posts: 277
    
    2

I understand the error message. I do not understand where the String is coming from.

Am I misunderstanding what a checkbox parameter value is that is coming back from a servlet -- and it is a String not a boolean?
Ivan Jozsef Balazs
Rancher

Joined: May 22, 2012
Posts: 865
    
    5
servletData - which type is it of?

What does its getParameter method return? (Well, obviously String.)
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

All request parameters are strings. Always. That's the way HTTP works.

If a value is something that needs to be converted to something else (a boolean for example) you'll need to write code to do that.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
margaret gillon
Ranch Hand

Joined: Nov 12, 2008
Posts: 277
    
    2

All request parameters are strings. Always. That's the way HTTP works.


Thank you, Bear.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Storing boolean from jsp checkbox into arraylist using bean
 
Similar Threads
Bogging down a bit.....
Create a class which can manage a collection of objects
Servlets 4a blocked
How to delete an element from a list?
session object = null?