Here's the situation: We want to have a Sea开发者_JS百科rch 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.
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);
}
精彩评论