Is JavaBeans able to store an array?

Discussion in 'Java' started by byhesed, May 25, 2011.

  1. byhesed

    byhesed Guest

    Can I handle array values using JavaBeans?
    I could'n find the way to pass an array to JavaBeans.

    Below is my situation.

    There are four checkboxes.
    I want to handle those values in JavaBeans.

    ----------------------------------------------------------------------------------------------------
    1. TestBeanForm.jsp
    ----------------------------------------------------------------------------------------------------
    <form action="TestBean.jsp" method="post">
    <input type="checkbox" name="books"> Java for Student<br>
    <input type="checkbox" name="books"> Compiler Construction<br>
    <input type="checkbox" name="books"> Software Engineering<br>
    <input type="checkbox" name="books"> Core Servlet and JSP<br>
    <p>
    <input type="submit" value="Submit">
    </form>
    ----------------------------------------------------------------------------------------------------

    Here, I use JavaBeans.
    ----------------------------------------------------------------------------------------------------
    2. TestBean.jsp
    ----------------------------------------------------------------------------------------------------
    <%@page import="test.TestBean"%>

    <jsp:useBean id="testBean" class="test.TestBean">
    <jsp:setProperty name="testBean" property="*"/>
    </jsp:useBean>
    <jsp:getProperty name="testBean" property="books"/>
    ----------------------------------------------------------------------------------------------------

    When dealing with thoes values using JavaBeans,
    Only the first books element is passed to JavaBeans.
    Here is my javaBean.

    ----------------------------------------------------------------------------------------------------
    3. TestBean.java
    ----------------------------------------------------------------------------------------------------
    package test;

    public class TestBean {
    private String books;

    public void setBooks(String books) { this.books = books; }
    public String getBooks() { return books; }
    }
    ----------------------------------------------------------------------------------------------------
    byhesed, May 25, 2011
    #1
    1. Advertising

  2. byhesed

    Lew Guest

    On 05/24/2011 09:15 PM, byhesed wrote:
    > Can I handle array values using JavaBeans?
    > I could'n find the way to pass an array to JavaBeans.
    >
    > Below is my situation.
    >
    > There are four checkboxes.
    > I want to handle those values in JavaBeans.
    >
    > ----------------------------------------------------------------------------------------------------
    > 1. TestBeanForm.jsp
    > ----------------------------------------------------------------------------------------------------
    > <form action="TestBean.jsp" method="post">
    > <input type="checkbox" name="books"> Java for Student<br>
    > <input type="checkbox" name="books"> Compiler Construction<br>
    > <input type="checkbox" name="books"> Software Engineering<br>
    > <input type="checkbox" name="books"> Core Servlet and JSP<br>
    > <p>
    > <input type="submit" value="Submit">
    > </form>
    > ----------------------------------------------------------------------------------------------------
    >
    > Here, I use JavaBeans.
    > ----------------------------------------------------------------------------------------------------
    > 2. TestBean.jsp
    > ----------------------------------------------------------------------------------------------------
    > <%@page import="test.TestBean"%>
    >
    > <jsp:useBean id="testBean" class="test.TestBean">
    > <jsp:setProperty name="testBean" property="*"/>
    > </jsp:useBean>
    > <jsp:getProperty name="testBean" property="books"/>
    > ----------------------------------------------------------------------------------------------------
    >
    > When dealing with thoes values using JavaBeans,
    > Only the first books element is passed to JavaBeans.
    > Here is my javaBean [sic].
    >
    > ----------------------------------------------------------------------------------------------------
    > 3. TestBean.java
    > ----------------------------------------------------------------------------------------------------
    > package test;
    >
    > public class TestBean {
    > private String books;
    >
    > public void setBooks(String books) { this.books = books; }
    > public String getBooks() { return books; }
    > }
    > ----------------------------------------------------------------------------------------------------


    Where's the array in your bean?

    --
    Lew
    Honi soit qui mal y pense.
    http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg
    Lew, May 25, 2011
    #2
    1. Advertising

  3. byhesed

    byhesed Guest

    On 5ì›”25ì¼, 오후10ì‹œ15분, Lew <> wrote:
    > On 05/24/2011 09:15 PM, byhesed wrote:
    >
    >
    >
    >
    >
    >
    >
    >
    >
    > > Can I handle array values using JavaBeans?
    > > I could'n find the way to pass an array to JavaBeans.

    >
    > > Below is my situation.

    >
    > > There are four checkboxes.
    > > I want to handle those values in JavaBeans.

    >
    > > --------------------------------------------------------------------------- -------------------------
    > > 1. TestBeanForm.jsp
    > > --------------------------------------------------------------------------- -------------------------
    > > <form action="TestBean.jsp" method="post">
    > >      <input type="checkbox" name="books">  Javafor Student<br>
    > >      <input type="checkbox" name="books">  Compiler Construction<br>
    > >      <input type="checkbox" name="books">  Software Engineering<br>
    > >      <input type="checkbox" name="books">  CoreServlet and JSP<br>
    > >      <p>
    > >      <input type="submit" value="Submit">
    > > </form>
    > > --------------------------------------------------------------------------- -------------------------

    >
    > > Here, I use JavaBeans.
    > > --------------------------------------------------------------------------- -------------------------
    > > 2. TestBean.jsp
    > > --------------------------------------------------------------------------- -------------------------
    > > <%@page import="test.TestBean"%>

    >
    > > <jsp:useBean id="testBean" class="test.TestBean">
    > >    <jsp:setProperty name="testBean" property="*"/>
    > > </jsp:useBean>
    > > <jsp:getProperty name="testBean" property="books"/>
    > > --------------------------------------------------------------------------- -------------------------

    >
    > > When dealing with thoes values using JavaBeans,
    > > Only the first books element is passed to JavaBeans.
    > > Here is my javaBean [sic].

    >
    > > --------------------------------------------------------------------------- -------------------------
    > > 3. TestBean.java
    > > --------------------------------------------------------------------------- -------------------------
    > > package test;

    >
    > > public class TestBean {
    > >    private String books;

    >
    > >    public void setBooks(String books) { this.books = books;}
    > >    public String getBooks() { return books; }
    > > }
    > > --------------------------------------------------------------------------- -------------------------

    >
    > Where's the array in your bean?
    >
    > --
    > Lew
    > Honi soit qui mal y pense.http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg


    I got rid of the code about array.
    Original code is here.

    ---------------------------------------------------------------------------
    -------------------------
    3. TestBean.java
    ---------------------------------------------------------------------------
    -------------------------
    package test;

    public class TestBean {
       private String[] books;
     public void setBooks(String[] books) { this.books = books; }
       public String[] getBooks() { return books; }
    }
    ---------------------------------------------------------------------------
    -------------------------

    However, when I pass multiple check box values,
    A browser only can receive just first one value in checkboxes.
    Do you know how to handle array values in JavaBean?
    byhesed, May 27, 2011
    #3
  4. byhesed

    Lew Guest

    byhesed wrote:
    >>> --------------------------------------------------------------------------- -------------------------
    >>> 1. TestBeanForm.jsp
    >>> --------------------------------------------------------------------------- -------------------------
    >>> <form action="TestBean.jsp" method="post">
    >>> <input type="checkbox" name="books"> Java for Student<br>
    >>> <input type="checkbox" name="books"> Compiler Construction<br>
    >>> <input type="checkbox" name="books"> Software Engineering<br>
    >>> <input type="checkbox" name="books"> Core Servlet and JSP<br>


    Where are your 'value' attributes?

    <http://www.w3schools.com/tags/att_input_value.asp>
    > Note: The value attribute is required with <input type="checkbox">
    > and <input type="radio">.




    --
    Lew
    Honi soit qui mal y pense.
    http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg
    Lew, May 27, 2011
    #4
  5. byhesed

    byhesed Guest

    On 5ì›”27ì¼, 오후2ì‹œ38분, Lew <> wrote:
    > byhesed wrote:
    > >>> --------------------------------------------------------------------------- -------------------------
    > >>> 1. TestBeanForm.jsp
    > >>> --------------------------------------------------------------------------- -------------------------
    > >>> <form action="TestBean.jsp" method="post">
    > >>>       <input type="checkbox" name="books">    Java for Student<br>
    > >>>       <input type="checkbox" name="books">    Compiler Construction<br>
    > >>>       <input type="checkbox" name="books">    Software Engineering<br>
    > >>>       <input type="checkbox" name="books">    Core Servlet and JSP<br>

    >
    > Where are your 'value' attributes?
    >
    > <http://www.w3schools.com/tags/att_input_value.asp>
    >
    > > Note: The value attribute is required with <input type="checkbox">
    > > and <input type="radio">.

    >
    > --
    > Lew
    > Honi soit qui mal y pense.http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg


    I know what the value is in html tag.

    What I want to know is this: Is JavaBean able to handle array values?

    I think JavaBean cannot receive reference values or pointer values.
    byhesed, May 27, 2011
    #5
  6. byhesed

    Lew Guest

    byhesed wrote:
    > Lew wrote:
    >> byhesed wrote:
    >>>>> --------------------------------------------------------------------------- -------------------------
    >>>>> 1. TestBeanForm.jsp
    >>>>> --------------------------------------------------------------------------- -------------------------
    >>>>> <form action="TestBean.jsp" method="post">
    >>>>> <input type="checkbox" name="books"> Java for Student<br>
    >>>>> <input type="checkbox" name="books"> Compiler Construction<br>
    >>>>> <input type="checkbox" name="books"> Software Engineering<br>
    >>>>> <input type="checkbox" name="books"> Core Servlet and JSP<br>


    >> Where are your 'value' attributes?
    >>
    >> <http://www.w3schools.com/tags/att_input_value.asp>
    >>
    >>> Note: The value attribute is required with<input type="checkbox">
    >>> and<input type="radio">.

    >>
    >> --
    >> Lew
    >> Honi soit qui mal y pense.http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg


    Don't quote sigs.
    > I know what the value is in html tag.


    But where is it? You don't show the 'value' attribute. It is REQUIRED
    according to the documentation I cited. Where is it?

    You didn't answer my question. Maybe the omission of the 'value' attribute is
    your problem.

    > What I want to know is this: Is JavaBean able to handle array values?
    >
    > I think JavaBean cannot receive reference values or pointer values.


    Nonsense. You've already told us that the bean did receive a reference value
    when it picked up the string value. So that's crap.

    Why don't you try my advice before redundantly repeating your question again?

    --
    Lew
    Honi soit qui mal y pense.
    http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg
    Lew, May 27, 2011
    #6
  7. byhesed

    byhesed Guest

    On 5ì›”27ì¼, 오후11ì‹œ25분, Lew <> wrote:
    > byhesed wrote:
    > > Lew wrote:
    > >> byhesed wrote:
    > >>>>> --------------------------------------------------------------------------- -------------------------
    > >>>>> 1. TestBeanForm.jsp
    > >>>>> --------------------------------------------------------------------------- -------------------------
    > >>>>> <form action="TestBean.jsp" method="post">
    > >>>>>        <input type="checkbox" name="books">     Java for Student<br>
    > >>>>>        <input type="checkbox" name="books">     Compiler Construction<br>
    > >>>>>        <input type="checkbox" name="books">     Software Engineering<br>
    > >>>>>        <input type="checkbox" name="books">     Core Servlet and JSP<br>
    > >> Where are your 'value' attributes?

    >
    > >> <http://www.w3schools.com/tags/att_input_value.asp>

    >
    > >>> Note: The value attribute is required with<input type="checkbox">
    > >>> and<input type="radio">.

    >
    > >> --
    > >> Lew
    > >> Honi soit qui mal y pense.http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg

    >
    > Don't quote sigs.
    >
    > > I know what the value is in html tag.

    >
    > But where is it?  You don't show the 'value' attribute.  It is REQUIRED
    > according to the documentation I cited.  Where is it?
    >
    > You didn't answer my question.  Maybe the omission of the 'value' attribute is
    > your problem.
    >
    > > What I want to know is this: Is JavaBean able to handle array values?

    >
    > > I think JavaBean cannot receive reference values or pointer values.

    >
    > Nonsense.  You've already told us that the bean did receive a reference value
    > when it picked up the string value.  So that's crap.
    >
    > Why don't you try my advice before redundantly repeating your question again?
    >
    > --
    > Lew
    > Honi soit qui mal y pense.http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg



    As you already know, the default value of checkbox is "on" or "off"

    Although I didn't set values of checkboxes, there is no problem.

    Do you agree with me? (I think you will.)

    I can receive checkbox values as an array If I use getParameter() in
    Servlet.

    However, when I handle it using JavaBeans, I cannot receive the
    checkbox values as an array.

    That's my problem. And I didn't ignore your advice ever!

    I am not sure, but I might read that JavaBeans cannot handle array
    values.

    If you want to deal with array values, you need to use Tag Library.

    Anyway, sorry for late reply. I've been so busy.
    byhesed, May 30, 2011
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?UnVkeQ==?=

    to store or not to store an image

    =?Utf-8?B?UnVkeQ==?=, Mar 29, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    612
    =?Utf-8?B?UnVkeQ==?=
    Mar 30, 2005
  2. Kevin Hooke

    Re: Name of JavaBeans

    Kevin Hooke, Aug 27, 2003, in forum: Java
    Replies:
    1
    Views:
    342
    tommys
    Aug 28, 2003
  3. Chris Beach
    Replies:
    0
    Views:
    566
    Chris Beach
    Sep 8, 2003
  4. Rama Rao Polneni
    Replies:
    3
    Views:
    216
    Chris Angelico
    Jul 31, 2011
  5. sed_y
    Replies:
    0
    Views:
    953
    sed_y
    Feb 15, 2012
Loading...

Share This Page