instance of bean

hi how do you create instance of bean in action. i am getting error when i try to do it. can you please suggest.thanks jayashree
[156 byte] By [my.doubtsa] at [2007-11-26 17:44:39]
# 1
MyBean bean=new MyBean()..:)regardsShanu
mshanua at 2007-7-9 0:12:49 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
post ur code which throws exception...
mshanua at 2007-7-9 0:12:49 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
my bean name is onebean and i'm trying to create the instance in action. you said mybean is the name of the bean. i tried it but its not working
my.doubtsa at 2007-7-9 0:12:49 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
why its not working ?what the error/exception r u getting ?can u post the code .have u tried this.......BeanName obj = (BeanName) form // here form is a parameter passed in Action execute method.
java_usera at 2007-7-9 0:12:49 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

the coding is this

package com.mycompany.messages.action;

import java.io.IOException;

public class samaction

{

sambean bea = new sambean();

public String getSuc(){

System.out.println("hi");

return "success";

}

}

2 error are

cannot resolve symbol sambean and the bean declaration is

sambean.java

package com.mycompany.messages.bean;

import java.util.*;

import javax.servlet.ServletContext;

import javax.faces.context.FacesContext;

public class sambean{

private String sam;

public javax.faces.model.SelectItem[] getSam(){

javax.faces.model.SelectItem[] sam = {

new javax.faces.model.SelectItem(new Integer(1),"Peas"),

new javax.faces.model.SelectItem(new Integer(2),"Cheese")

};

return sam;

}

public void setSam(String sam){

this.sam=sam;

}

}

this is combo.jsp

<%@ page contentType="text/html" %>

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>

<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

<f:view>

<h:form id="myform">

<h:selectOneMenu id="combo">

<f:selectItems value="#{sambean.sam}"/>

</h:selectOneMenu>

<h:commandButton id="button" value="click" action="#{samaction.getSuc}"/>

</h:form>

</f:view>

this commo.jsp

<%@ page contentType="text/html" %>

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>

<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

<f:view>

<h:form id="myform">

<h:outputText id="combo" value="#{sambean.sam}"/>

</h:form>

</f:view>

the faces config is

<%@ page contentType="text/html" %>

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>

<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

<f:view>

<h:form id="myform">

<h:outputText id="combo" value="#{sambean.sam}"/>

</h:form>

</f:view>

the web.xml file is

<?xml version="1.0" encoding="ISO-8859-1"?>

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee

http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"

version="2.4">

<!-- Faces Servlet -->

<servlet>

<servlet-name>FacesServlet</servlet-name>

<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>

<load-on-startup>1</load-on-startup>

</servlet>

<servlet-mapping>

<servlet-name>FacesServlet</servlet-name>

<url-pattern>*.faces</url-pattern>

</servlet-mapping>

</web-app>

even not able to navigate. please assist

my.doubtsa at 2007-7-9 0:12:49 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
What is this bean exactly u are tryin to convince? is it form bean? is it busns bean? or any other bean? :))
mshanua at 2007-7-9 0:12:49 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
GO back to basic school.............import your sambean in that class yaar......shanu
mshanua at 2007-7-9 0:12:49 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8
its form bean here in this context
my.doubtsa at 2007-7-9 0:12:49 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9
its the form bean in my context
my.doubtsa at 2007-7-9 0:12:49 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 10
its saying the same. it says the package does not exist. i tried all those.i'll not put forth questions without tryingthanks,jai
my.doubtsa at 2007-7-9 0:12:49 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 11

package com.mycompany.messages.action;

import com.mycompany.messages.bean.*;

import java.io.IOException;

public class samaction

{

sambean bea = new sambean();

public String getSuc(){

System.out.println("hi");

return "success";

}

}

try with this.....jayaji.

mshanua at 2007-7-9 0:12:49 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 12

thanks shanuji,

package com.mycompany.messages.action;

import java.io.IOException;

import com.mycompany.message.bean.sambean;

public class samaction

{

//BeanName obj = (BeanName) form // here form is a parameter passed in Action execute method.

sambean bea = new sambean();

public String getSuc(){

System.out.println("hi");

return "success";

}

}

i tried that too it says the package does't exist.

my.doubtsa at 2007-7-9 0:12:49 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 13
helloo jiiii...are u using any IDEs or just compiling from command prompt?
mshanua at 2007-7-9 0:12:49 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 14
i'm using command prompt
my.doubtsa at 2007-7-9 0:12:49 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 15
then def its a class path problem...
mshanua at 2007-7-21 17:12:17 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 16
ok then what is the remedy yar
my.doubtsa at 2007-7-21 17:12:17 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 17
Abracabra.......set the classpath correctly...give a details description where u have put the java files..the folder structure..from where u are compiling etc...Be sophisticated....start using IDEs.....Shanu
mshanua at 2007-7-21 17:12:17 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 18
i have set the path with all the required libraries. since i'm working with edit plus and deploying it in tomcat server 5.0
my.doubtsa at 2007-7-21 17:12:17 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 19
send the complete picture of your env to mshanu@hotmail.com...
mshanua at 2007-7-21 17:12:17 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...