Here's the situation: We want to have a Search page that takes in an ordered list of Attribute objects, and based on their 'type' (text input, dropdown, checkbox) generates and displays it in the appropriate manner. We'd also need to process the values for these fields in order to filter results. I'm at a loss for how we can accomplish this, any ideas/solutions? This is for a java webapp backed by struts2.
views:
28answers:
1
A:
Yes, it's possible. I'm not familiar with struts, but I guess it can't be that hard. Some pseudo-java-code to get you started:
private void init() {
for(Attribute a : attributes) {
SomeWebComponent c = createComponent(a);
components.put(a, c);
}
renderComponents(components.values());
}
private SomeWebComponent createComponent(Attribute a) {
if(a.getType().equals("text") return createTextInput();
else if(a.getType().equals("list") return createListInput(a.getItems());
...
}
private void performSearch() {
for(Attribute a : attributes) {
SomeWebComponent c = components.get(a);;
searchValues.put(a, c.getValue());
}
doSearch(searchValues);
}
Avall
2010-10-15 17:02:20