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.