Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Show a bean property in jsf....it's so difficult?????

Reply
Thread Tools

Show a bean property in jsf....it's so difficult?????

 
 
gbattine
Guest
Posts: n/a
 
      07-10-2006
Hi....
i'm a simple problem but i don't found a working solution....
I have a jsf application and i have to show a bean value into a jsp
page.
I show you my passes...please correct me where i go wrong,,,
For the first i declare property in backing bean


private String[] arraylinee;



In my application an user clicks a button, the application calls bean's
method and creates this array of string,that's what i want to show in
my jsp page.
I've developed in my backing bean getter and setter methods..


public String[] getarraylinee(){
return arraylinee;
}
public void setarraylinee(String[] arraylinee){
this.arraylinee=arraylinee;
}



1a Question)
It's not needed that bean return property?

That is...my bean's method is

public String retrieveblob()throws
IOException,SQLException,NullPointerException{
Database2 db2 = new Database2("nomeDB","root","shevagol");
if (db2.connetti())
k=1;
else k=0;
//try{
Connection dbo=db2.getConnection();
Statement st = null;

try {
st = dbo.createStatement();
}
catch (NullPointerException exc) {
exc.printStackTrace();
}

ResultSet rs = null;
try {
rs = st.executeQuery("SELECT Data FROM tbl WHERE nome='1' ");
}
catch (NullPointerException exc) {
exc.printStackTrace();
}

try {
rs.first();
}
catch (NullPointerException exc) {
exc.printStackTrace();
}
try {
Blob blob = rs.getBlob("Data");
byte[] read = blob.getBytes(1, (int) blob.length());
st.close();
String lettura=new String(read);
String[] arraylinee=lettura.split(";");
}
catch (NullPointerException exc) {
exc.printStackTrace();
}

return "Result";
}



Result is a string useful for navigation...
Let's go to jsp page


codice:<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core"
prefix="c" %>


<jsp:useBean id="myBean" class="giu.MyBean" scope="session"/>
<%@ page import="giu.MyBean" %>
<%-- Instantiate class --%>




<html>
<head>
<title></title>
</head>
<body>
<f:view>
<f:verbatim>
<hutputText value="#{MyBean.k}"/>
<table>
<c:forEach items="${session.myBean.arraylinee}" var="linea" >
<tr>
<td>
<cut value="${linea}" />
</td>
</tr>
</c:forEach>
</table>
</f:verbatim>
</f:view>


</body>
</html>



Don't care for MyBean.k, i use it for controlling if db connection
works fine...
In summary i want this jsp page prints my array of string,one for line.
How can i do?
The bean is called MyBean and it's in the package giu.
Can you help me correcting my code directly???
Ah....with my actual application the jsp output is:

1
${linea}

 
Reply With Quote
 
 
 
 
Moiristo
Guest
Posts: n/a
 
      07-11-2006
gbattine wrote:
> In my application an user clicks a button, the application calls bean's
> method and creates this array of string,that's what i want to show in
> my jsp page.


Have you tested whether the bean method is actually called?

>
> 1a Question)
> It's not needed that bean return property?


It is, or your bean is 'malformed'. Some JSF implementations persist on
always having getters and setters, even though you don't always use both.


> <jsp:useBean id="myBean" class="giu.MyBean" scope="session"/>


What's this? Don't use this. JSTL can access managed beans as easy as
JSF, you don't need to use this tag.

> <%@ page import="giu.MyBean" %>


I don't think you need this one either.


> <c:forEach items="${session.myBean.arraylinee}" var="linea" >


So I would say, just use ${myBean.arraylinee}.



Hope this helps,

Moiristo
 
Reply With Quote
 
 
 
 
Timo Stamm
Guest
Posts: n/a
 
      07-11-2006
gbattine schrieb:
> I've developed in my backing bean getter and setter methods..
>
>
> public String[] getarraylinee(){
> return arraylinee;
> }
> public void setarraylinee(String[] arraylinee){
> this.arraylinee=arraylinee;
> }



You have to use camelcase. The first letter following "get" "set" or
"is" must be uppercase.

getArraylinee
setArraylinee
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
useBean in JSP for bean within a bean kumar Java 1 02-13-2004 09:33 PM
[HELP] Bean Newbie: C++ library to Java bean. How? Takeshi Java 0 01-28-2004 11:36 AM
Differnce between Java Bean and Enterprise Java Bean Markku Salminen Java 3 01-21-2004 09:25 AM
can a session bean return a local entity bean object? David Thielen Java 2 09-12-2003 07:45 AM
To bean or not to bean... Benjamin Stewart Java 0 06-30-2003 12:34 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57