Is JavaBeans able to store an array?

B

byhesed

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; }
}
----------------------------------------------------------------------------------------------------
 
L

Lew

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?
 
B

byhesed

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?

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; }
}
---------------------------------------------------------------------------
 
B

byhesed

Where are your 'value' attributes?

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.
 
L

Lew

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?
 
B

byhesed

Don't quote sigs.


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.



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?


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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top