一、在页面上用复选框进行复选,然后把信息写入到XML文件中。二、进行页面展示时候读取xml文件。三、使用反射机制调用类中的get方法四、页面上用标签输出动态表头。五、双重循环在页面上输出动态列。 写XML的struts2处理类:
public class DynamicTbAction extends MySuperAction { public String List(){
return "dynamicTbList";
}
public String set(){
UserVO userVO = (UserVO)session.get("loginUser");
String path = request.getRealPath("/")+"sysconfig\\DynamicTable";
path = path.replace("\\", "/")+"/" + userVO.getUsername()+".xml";
String[] attributes = request.getParameterValues("publicAttribute");
if(attributes.length!= 0){
Element rootElement = new Element("tables");
Element tableElt = new Element("table");
Element tabInx = new Element("publicAttribute");
tableElt.addContent(tabInx);
for (int i = 0; i < attributes.length; i++) {
String attr = attributes[i];
String[] attrs = attr.split(",");
Element attrElement = new Element("column");
attrElement.setAttribute("name", attrs[0]);
attrElement.setAttribute("value", attrs[1]);
tabInx.addContent(attrElement);
}
rootElement.addContent(tableElt);
Document doc = new Document(rootElement);
XMLOutputter out = new XMLOutputter();
String xmlStr = out.outputString(doc);
System.out.println(xmlStr);
System.out.println(path);
try {
out.output(doc, new FileOutputStream(path));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
return List();
}
} struts2处理到页面的列表: public String List(){
UserVO userVO = (UserVO)session.get("loginUser");
String path = request.getRealPath("/")+"sysconfig\\DynamicTable";
path = path.replace("\\", "/")+"/" + userVO.getUsername()+".xml";
List
List
Pagination pagination = systemconfigHelper.queryPageAttribute("from PublicAttributePO", page, 5, "select count(*) from PublicAttributePO");
List
List entityList = new ArrayList();
for (Iterator iterator = list.iterator(); iterator.hasNext();) {
PublicAttributeVO publicAttributeVO = (PublicAttributeVO) iterator
.next();
if ("0".equals(publicAttributeVO.getStatus())) {
publicAttributeVO.setStatus("失效");
} else {
publicAttributeVO.setStatus("有效");
}
List
你可以描述的更清楚一点. 没有太明白你的意思. 你是不是想在某个页面选中某一项, 然后再打开另一个页面就自动选中刚才的那一项吗?如果是这样. 直接到另一个页面的时候带个参数就可以了吧..