[Tomcat, HTTPD, Servlets & JSP] - exception thrown: passing an object from a bean to a JSP
by congrio7
I have a class on /lib, here is:
package auxiliar;
public class Tabla {
public String oid;
public String ip;
public int frecuencia;
public int inicio;
public int fin;
public Tabla (String oid, String ip, int frecuencia, int inicio, int fin) {
this.oid = oid;
this.ip = ip;
this.frecuencia = frecuencia;
this.inicio = inicio;
this.fin = fin;
}
}
And then I have a bean like about this:
public class VerOid {
.......
public ArrayList ver () {
.......
ArrayList salida = new Arraylist();
...
while( rs.next() ) {
salida.add(new Tabla(_oid, _ip, _frecuencia, _inicio, _fin));
......
And at last, I have a JSP like this:
<jsp:useBean id="id1" scope="session" class="bean.VerOid"/>
<%
ArrayList d = id1.ver();
out.println( d.size());
///////////
out.println( ( (Tabla) (d.get(0)) ).oid );
////////
ArrayList ff = new ArrayList();
ff.add(new Tabla ("1.1.","127.",3,4,5));
out.println( ( (Tabla) ff.get(0) ).frecuencia );
%>
d.size no problem
With ff neither.
But out.println( ( (Tabla) (d.get(0)) ).oid ); thrown an exception java.lang.ClassCastException and I don't know why.
I have JDK 1.4.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3988566#3988566
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3988566
19Â years, 5Â months
[JBoss Seam] - Re: @Out and default ScopeType
by dan.j.allen
Gavin et al,
I am still a bit confused about which scope to use for the @Out annotation. Let me provide a brief example and hopeful it demonstrates my misunderstanding.
I have the following stub backing bean:
@Name( "userManager" )
| @Scope(CONVERSATION)
| public class UserManagerBean {
| @In( required = false )
| @Out( required = false, scope = CONVERSATION )
| private User user;
|
| public String create() {
| return "/user/new.jspx";
| }
|
| public String view() {
| return "/user/view.jspx";
| }
| public String save() {
| assert user != null;
| // do whatever to save...
| return view();
| }
|
| // ...other supporting methods, including @Begin and @End methods
| }
|
Assume that the flow is: request create -> enter info -> save -> view and that the conversation is being created around this process by some other methods (meaning I know that I have a working conversation).
I am curious to know why I need ScopeType.CONVERSATION on the @Out annotation. The assertion in the save() method passes, so I know at that point that the property "user" does indeed have a value. However, if I don't set the scope on the @Out annotation, by the time I get to view.jspx, the EL variables that reference "user" (such as #{user.name}) are all empty.
Is it always necessary to use ScopeType.CONVERSATION for the @Out annotation if the component itself is in conversation scope?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3988561#3988561
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3988561
19Â years, 5Â months