Requirements: The system front-end JSP uses the Easyui DataGrid to show some task information, a status message in the task information that shows the value is a number,
You need to display the status as descriptive information based on the mappings that are saved in the background.
The original JSP front-end display:
Solution, use the Create JSON data in the background, then pass it to the foreground JSP page, and use Eval to parse it to get a description of the value corresponding to the following operation:
1. Creating JSON data (Java)
//Task List Public Static FinalString task_pending = "0"; //command processing succeeded Public Static FinalString task_command_success = "1"; //command processing failed Public Static FinalString task_command_failed = "2"; //Download processed successfully Public Static FinalString task_down_success = "3"; //Download processing failed Public Static FinalString task_down_failed = "4"; //message sent successfully Public Static FinalString task_mail_success = "5"; //message failed to send Public Static FinalString task_mail_failed = "6"; //Processing Success Public Static FinalString Task_complete = "99"; Public StaticString Getstatusjson () {jsonobject Statusjson=NewJsonobject (); Statusjson.put (task_pending,"Awaiting treatment"); Statusjson.put (task_command_success,"Script execution succeeded"); Statusjson.put (task_command_failed,"Script execution Failed"); Statusjson.put (task_down_success,"File Download succeeded"); Statusjson.put (task_down_failed,"File download Failed"); Statusjson.put (task_mail_success,"Mail sent successfully"); Statusjson.put (task_mail_failed,"Message sent Failed"); Statusjson.put (Task_complete,Complete); returnstatusjson.tostring (); }
2. Transfer value (Java)
String Statusjson = Constants.getstatusjson (); Resultmap.put ("Statusjson", Statusjson);
3. Use JS to get the value (JS) in the front-end JSP
// Get the status description based on the incoming status code function Getstatusdesc (key) { var obj = eval ("(" + ' ${statusjson} ' + ")"); return Obj[key];}
4. Calling function using the formatter of the DataGrid
1 { 2Field: ' Status ', 3Title: ' State ', 4HAlign: ' Left ',5Align: ' left ',6Width: ' 100 ',7Formatterfunction(value,row,index) {8 vardesc =Getstatusdesc (value);9 returndesc;Ten } One},
View Code
The final results are as follows:
Something: The first is in the background using map as the value, JS in the resolution map is more complex, and later to use JSON more convenient.
How Java background configuration information is passed to the front-end JSP page