File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Model or bean class is not available to Action Class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Model or bean class is not available to Action Class" Watch "Model or bean class is not available to Action Class" New topic
Author

Model or bean class is not available to Action Class

Asha Ramprasad
Greenhorn

Joined: Mar 10, 2012
Posts: 11
I have an Action class in com.kog.action --> VendorListAction.java

package com.kog.action;

import com.kog.Vendor;

import com.opensymphony.xwork2.ActionSupport;
import java.util.*;
import java.sql.*;

public class VendorListAction extends ActionSupport{


public String execute() throws Exception
{

Vendor v=new Vendor();



return SUCCESS;
}
}

Also my bean class is in com.kog ---> Vendor.java

package com.kogent;

import com.opensymphony.xwork2.ActionSupport;

public class Vendor{

private String productName;
private String productCategory;
private String vendorName;
private String vendorLocation;
private String contactPerson;
private String emailId;
private int phoneNumber;


Vendor(String productName,String productCategory,String vendorName,String vendorLocation,String contactPerson,String emailId,int phoneNumber)
{
this.productName = productName;
this.productCategory = productCategory;
this.vendorName = vendorName;
this.vendorLocation = vendorLocation;
this.contactPerson = contactPerson;
this.emailId = emailId;
this.phoneNumber = phoneNumber;
}



public String getProductName(){
return productName;
}

public void setProductName(String productName){
this.productName = productName;
}

public String getProductCategory(){
return productCategory;
}

public void setProductCategory(String productCategory){
this.productCategory = productCategory;
}


public String getVendorName(){
return vendorName;
}

public void setVendorName(String vendorName){
this.vendorName = vendorName;
}


public String getVendorLocation(){
return vendorLocation;
}

public void setVendorLocation(String vendorLocation){
this.vendorLocation = vendorLocation;
}


public String getContactPerson(){
return contactPerson;
}

public void setContactPerson(String contactPerson){
this.contactPerson = contactPerson;
}


public String getEmailId(){
return emailId;
}

public void setEmailId(String emailId){
this.emailId = emailId;
}


public int getPhoneNumber(){
return phoneNumber;
}

public void setPhoneNumber(int phoneNumber){
this.phoneNumber = phoneNumber;
}

}

While complile Vendor.java , there is no problem
But Compiling VendorListAction.java , the error is,

VendorListAction.java:9: cannot find symbol
symbol : class Vendor
location: package com.kog
import com.kog.Vendor;
^
VendorListAction.java:14: cannot find symbol
symbol : class Vendor
location: class com.kog.action.VendorListAction
Vendor v;
^
Mohana Rao Sv
Ranch Hand

Joined: Aug 01, 2007
Posts: 485

Because vendor class is not having default constructor.


ocjp 6 — Feeding a person with food is a great thing in this world. Feeding the same person by transferring the knowledge is far more better thing. The reason is the amount of satisfaction which we get through food is of only one minute or two. But the satisfaction which we can get through the knowledge is of life long.
Asha Ramprasad
Greenhorn

Joined: Mar 10, 2012
Posts: 11
but still having the same problem,

Even i used the model driven Action concept.
But i cant access any other class like User,Product inside Action classes.

please give me some idea.
Mohana Rao Sv
Ranch Hand

Joined: Aug 01, 2007
Posts: 485

How you are accessing other class? How you are using modalDriven interceptor? Give us more details, that will help us to help you better.

One type of compile time error generated by java is the ‘Cannot find symbol’ error. It means that a particular class, method or variable that you used could not be found by the compiler. Since java is a case sensitive language, it is possible that the coder misspelled something or that he tried to call a method that did not exist within that class.

Some of the reasons that this error might occur are: -

The coder misspelled the name of the class and it was not recognized by the compiler.
The coder did not import the class name.
Wrong syntax was used for calling the constructor.
The method requested is either protected or private.
An extra parameter was added or was left out.
The parameters are used in the wrong order.
The wrong type of parameter was used. E.g. it wanted a File, but was given a String instead.
Asha Ramprasad
Greenhorn

Joined: Mar 10, 2012
Posts: 11
Mohan Rao SV ,

Thanks for your replies.

Im new to Struts 1 & 2

I thought that Model Driven Interceptor will come automatically with struts-default.xml.
Is it right or not?

My struts.xml file is

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<include file="struts-default.xml"/>
<package name="default" extends="struts-default">


<action name="VendorListAction" class="com.kogent.action.VendorListAction">
<result name="success">/mvendorlist.jsp</result>
<result name="error">/error.jsp</result>
<result name="input">/error.jsp</result>
</action>


<action name="clientAction" class="com.kogent.action.ClientAction">
<result name="success">/client.jsp</result>
<result name="error">/error.jsp</result>
<result name="input">/error.jsp</result>
</action>
</package>
</struts>


This is ,my First attempt to access other class under an action class.

Thanks,
Asha
Asha Ramprasad
Greenhorn

Joined: Mar 10, 2012
Posts: 11
is there any other ways to access DB datas to jsp via an Action class.

But as a struts programmer i have to know why im unable to access Other model or bean class.

Please tell some tips to do that.
Asha Ramprasad
Greenhorn

Joined: Mar 10, 2012
Posts: 11
i download an example from vaannila ,

package vaannila;

import java.util.ArrayList;
import java.util.List;


public class AlbumInfoAction{

private String title;
private Artist artist;
private static List<Song> songs = new ArrayList<Song>();

static {
songs.add(new Song("Thriller","Disco"));
songs.add(new Song("Beat It","Rock"));
songs.add(new Song("Billie Jean","Pop"));
}

public String populate()
{
title = "Thriller";
artist = new Artist("Michael Jackson","King of pop");
return "populate";
}

public String execute()
{
return "success";
}

public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Artist getArtist() {
return artist;
}
public void setArtist(Artist artist) {
this.artist = artist;
}

public List<Song> getSongs() {
return songs;
}

}


package vaannila;

public class Song {

private String title;
private String genre;

Song(String title, String genre)
{
this.title = title;
this.genre = genre;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getGenre() {
return genre;
}
public void setGenre(String genre) {
this.genre = genre;
}
}


But same problem, no use.

Some of the errors are
AlbumInfoAction.java:44: cannot find symbol
symbol : class Song
location: class vaannila.AlbumInfoAction
public List<Song> getSongs() {
^
AlbumInfoAction.java:11: cannot find symbol
symbol : class Song
location: class vaannila.AlbumInfoAction
private static List<Song> songs = new ArrayList<Song>();
^
AlbumInfoAction.java:14: cannot find symbol
symbol : class Song
location: class vaannila.AlbumInfoAction
songs.add(new Song("Thriller","Disco"));
^
Also same problem for Artist class also
Asha Ramprasad
Greenhorn

Joined: Mar 10, 2012
Posts: 11
is there any configurations need for these type of classes?
Mohana Rao Sv
Ranch Hand

Joined: Aug 01, 2007
Posts: 485

Observe your code carefully, you forgot to import Song class located in import vannilla.Song Most of the exceptions are self explanatory. I'm explaining how to do it struts2. Here you are trying to populate some data before the action execution so this should be done using preparable interceptor. http://struts.apache.org/2.0.11/docs/prepare-interceptor.html. Don't use static block, Your service class responsible for accessing data from database let them do their job. You have to call the service classes in your action for accessing data.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Model or bean class is not available to Action Class