• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

Model or bean class is not available to Action Class

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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;
^
 
Ranch Hand
Posts: 485
Eclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because vendor class is not having default constructor.
 
Asha Ramprasad
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 485
Eclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
is there any configurations need for these type of classes?
 
Mohana Rao Sv
Ranch Hand
Posts: 485
Eclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Anderson gave himself the promotion. So I gave myself this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic