aspose file tools*
The moose likes Struts and the fly likes I want to use indexed properties Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "I want to use indexed properties" Watch "I want to use indexed properties" New topic
Author

I want to use indexed properties

surendar prabu
Ranch Hand

Joined: Jul 24, 2006
Posts: 102
Please tell whether my bean and actionform are correct. the code is given below

code:

Bean code

public class BookBean {

private String author;
private String title;
private String available;
private int id;

public BookBean(int id,String author,String title,String available)
{
this.id=id;
this.author=author;
this.title=title;
this.available=available;
}

public void setId(int id)
{
this.id=id;
}

public int getId()
{
return id;
}

public void setAuthor(String author)
{
this.author=author;
}

public String getAuthor(){
return author;
}

public void setTitle(String title){
this.title=title;
}

public String getTitle()
{
return title;
}

public void setAvailable(String available)
{
this.available=available;
}

public String getAvailable()
{
return available;
}

public BookBean() {
}
}

ActionForm
public class BookForm extends org.apache.struts.action.ActionForm {

private List bookBean;

public void setBookBean(List bookBean)
{
this.bookBean=bookBean;
}
public List getBookBean(){
return bookBean;
}

public BookBean getBookBean(int index) {
return (BookBean)bookBean.get(index);
}
public void setBookBean(int index, BookBean bean) {
this.bookBean.set(index, bean);
}

/**
*
*/
public BookForm() {
super();
}
}

Please tell me whether all the getter, setter methods are correct and returning the correct type. i am confused with the indexed getter and setter methods.


SCJP 1.4
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Looks good. Here are a couple of suggestions.

The Commons Bean Utilities that are used by Struts don't always handle overloaded methods correctly. (Bug 28358) This bug is supposedly fixed in later releases, but I still don't trust it. I'd Make sure that your indexed getter and setter have a different name than the non-indexed ones. In this example, I'd suggest changing the name of the non-indexed accessors to getBookBeans and setBookBeans while leaving the indexed accessors as getBookBean and setBookBean.

If you plan to use this bean in request scope, I'd suggest you carefully read this link and follow the instructions for giving your List "lazy initialization" capability.
[ August 18, 2006: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
surendar prabu
Ranch Hand

Joined: Jul 24, 2006
Posts: 102
Thanks Merill.

Once i have presented the response to the client, i will edit those indexed properties and make the next request.

my action will populate the bean as
BookForm bm=(BookForm)form;

now i want to retrieve those values. I will do this by
bm.getBookBeans(int index);

But how will i know the value for index? Is that i should set the index using bm.setBookBeans(int index,BookBean bean) when i provide the previous response.Who will set the index? in which page?

regards,
surendar prabu
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I want to use indexed properties