0

I have an id in the bean and mapped in orm.xml to database. For each id I have to lookup description from database and display. If I have enum values R:"RED" G:"GREEN". Struts does type conversion using EnumConverter. I just want to do similar stuff; if id = 123 what is the product description (lookup). Can I use Struts converter by setting action.properties or by extending StrutsTypeConverter to lookup description for an id = 123? Please let me know if there are any other suggestions. In short:- Each id I want to lookup description; where description is not part of the bean.

Product Bean

public class Product{
private Long id;
private String description;

public Long getId() {
    return id;
}
public void setId(Long id) {
    this.id = id;
}
public String getDescription() {
    return description;
}
public void setDescription(String planDescription) {
    this.description = planDescription;
}
}

Manage Bean

public class Manage{
private Long id;
private String Currency;
..and so on

public Long getId() {
    return id;
}
public void setId(Long id) {
    this.id = id;
}

<setters>..<getters>
}

Admin Action uses Manage Bean for all fields on UI

public class ManageAction extends ActionSupport
{
private Collection<Item> allItems;
private Manage manage;

public Collection<Item> getAllItems() {
    return allItems;
}

public void setAllItems(Collection<Item> allItems) {
    this.allItems = allItems;
}
}

.jsp file action = ManageAction

<s:label key="color" value="#color" />
<s:label key="id" value="%{id}" />

Here the id = 123 and I wish value gets translated to text such as "3IN - 4W - Folded" <product description> I can have id in the bean always and look up for description each time from a cache and translate and display. For a enum G:"GREEN" struts conveter gets us G stored in database and GREEN displayed on screen. similarly if it find id=123 and I wish "write a converter" which looks up in the cache (may be a Map of values) and displays description.

Aleksandr M
  • 24,264
  • 12
  • 69
  • 143
user1769790
  • 1,183
  • 3
  • 11
  • 23
  • `The Converter's role is to convert a String to an Object and an Object to a String.` – Aleksandr M May 10 '13 at 18:33
  • @RomanC have added code. – user1769790 May 10 '13 at 19:05
  • @AleksandrM Is there a way that I can make Struts converter do this kind of conversion..?? or if you have any suggestions pls let me know. I cannot add the description into the bean that is accessed by action class. i can just use the id (as translator) – user1769790 May 12 '13 at 04:31

0 Answers0