G
gbattine
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}
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}