方式一:
function f_add()
{
//f_openWindow('custom/cusinformation!input.action', '添加用户', 600, 450);
top.f_addTab("addcustom", '增加客户信息', 'custom/cusinformation!input.action');[d1]
}
跳转到input空方法——》到input页面
Action:
private CusInformation entity;
public String getModelJson() throws Exception {
try {
String content = null;
entity = cusInfoManager.getCusInfomation(id);
content = super.reverseObjJsonData(entity);
Struts2Utils.renderText(content);
} catch (Exception e) {
logger.error("获取客户json数据时出错", e);
}
return NONE;
}
public String input(){
return INPUT;}
Service:
Dao:
Input页面jsp
<script type="text/javascript">
var CurID = 1;
var Validator = null;
var phoneJson='${PHONEJSON}';
var addressJson='${ADDRESSJSON}';
var classifyUrl = "${ctx}/custom/cusclassify!showClassTree.action";
var isView = "${param['isView']}";
$(function ()
{
$.metadata.setType("attr", "validate");
if(isView=='true'){
var mainform=$("#form1");
f_formRead($.ligerui.find($.ligerui.controls.ComboBox));
f_formRead($.ligerui.find($.ligerui.controls.DateEditor));
f_formRead($.ligerui.find($.ligerui.controls.select));
$("input,select,textarea",mainform).attr("readonly", "readonly");
}
//初始化 客户类型
var roleListJson="${allRoleJson}";
roleListJson=eval("("+roleListJson+")");
roleManager=$("#custype").ligerComboBox({
data:roleListJson,
180,
selectBoxWidth: 180,
isMultiSelect: false,
valueFieldID:"roleids"
});
roleManager.setValue('${checkroleids}');
roleManager.updateStyle();
//初始化分类值
initclass();
$("#form1").ligerForm();
$("#name").focus();
});
function getCusType(){
if($("#roleids").val()==""){
$("#typeid").val(0);
}else{
$("#typeid").val($("#roleids").val());
}
}
function f_success()
{
$.ligerDialog.closeWaitting();
$.ligerDialog.success("保存成功","",function(button,domobject,buttonindex){
top.frames["customlist"].f_reload();
f_cancel();
});
}
function f_error(message)
{
$(document).ready(function(){
$.ligerDialog.error(message);
});
}
function f_post(){
var options = {
target:'',
url:'cusinformation!save.action',
type:'POST',
success: function(data,textStatus){
var result=eval(data);
if(result<1){
$.ligerDialog.closeWaitting();
$.ligerDialog.error("保存失败");
}else if(result>0){
f_success();
}
},
error:function(req, testStatus, errorThrown){
$.ligerDialog.closeWaitting();
$.ligerDialog.error("保存失败");
}
};
$('#form1').ajaxSubmit(options);
}
function f_save()
{
if(!Validator.form()) return;
$("form").ligerForm();
//组织电话信息
f_savephone();
//组织地址信息
f_saveAddress();
$.ligerDialog.waitting("正在保存中...");
setTimeout(function(){
f_post();
},10);
}
/*
* 关闭窗口
*/
function f_cancel() {
LG.closeCurrentTab(null);
}
[d2] </script>
<body style="padding:10px">
<div id="tabcontainer" style="margin: 3px;margin-bottom:30px;">
<form id="form1" action="cusinformation!save.action" method="post" class=l-form>
<input type="hidden" name="id" value="${id}"/>
<input type="hidden" id="typeid" name="typeid" value=""/>
<input type="hidden" id="checkedclassids" name="checkedclassids" value="${checkedclassids}"/>
<input type="hidden" id="checkedclassnames" name="checkedclassnames" value="${checkedclassnames }"/>
<input type="hidden" id="phonejson" name="phonejson" value=""/>
<input type="hidden" id="addressjson" name="addressjson" value=""/>
<DIVclass="l-group l-group-hasicon"><IMGsrc="${ctx}/js/ligerUI/skins/icons/communication.gif"><SPAN>基础信息</SPAN><s:if test="id!=null"> 客户id:${id}</s:if></DIV>
<table cellpadding="0" cellspacing="0" class="l-table-edit" >
<tr>
<td width="400px">
<table>
<tr>
<td align="left" class="l-table-edit-td" width="100px">客户名称:</td>
<td align="left" class="l-table-edit-td"><input name="name" type="text" id="name" ltype="text" validate="{required:true,minlength:2,maxlength:50}" value="${name}"/></td>
<td align="left"><font color="red">*</font></td>
</tr>
</table>
</td>
<td width="400px">
<table>
<tr>
<td align="left" class="l-table-edit-td" width="100px">客户类型:</td>
<td align="left" class="l-table-edit-td">
<input type="text" name="custype" id="custype" ltype="text" validate="{required:true}" onchange="getCusType()"/>[d3]
</td>
<td align="left"><font color="red">*</font></td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="400px">
<table>
<tr>
<td align="left" class="l-table-edit-td" width="100px">性别:</td>
<td align="left" class="l-table-edit-td">
<select name="gender" id="gender" ltype="select">
<option value="0" <c:if test="${gender==0}">selected</c:if>>女</option>
<option value="1" <c:if test="${gender==1}">selected</c:if>>男</option>
</select>
</td>
<td align="left"></td>
</tr>
</table>
</form>
</div>
<script type="text/javascript">
var mainform = $("#form1");
if(isView){
LG.setFormViewBtn(f_cancel);
}else{
LG.setFormDefaultBtn(f_cancel, f_save);
}
</script>
[d4] </body>
方式二:f_openwindow
主页面Jsp:
function f_add()
{
f_openWindow('custom/custag!input.action', '添加客户标签', 600, 450);[d5]
}
function f_openWindow(url, title, width, height)
{
var dialogOptions = { width, height: height, title: title, url: url, buttons: [
{ text: '保存', onclick: function (item, dialog)
{
dialog.frame.f_save();[d6] [d7]
}
},
{ text: '关闭', onclick: function (item, dialog)
{
dialog.close();
}
}
], isResize: true, timeParmName: 'a'
};
activeDialog = parent.jQuery.ligerDialog.open(dialogOptions);
}
Action:
@Override
public String input() throws Exception {
// TODO Auto-generated method stub
return INPUT;
}
Service:
Dao:
子页面jsp,input页面
<script type="text/javascript">
var CurID = 1;
var Validator = null;
$(function ()
{
$.metadata.setType("attr", "validate");
$("#form1").ligerForm();
deafultValidate($("#form1"));
Validator = $("#form1").validate();
$("#defined_buttonUpload").click();
$("#name").focus();
});
function f_success[d8] [d9] ()
{
$.ligerDialog.closeWaitting[d10] ();
//setTimeout(function(){
$.ligerDialog.success("保存成功[d11] [d12] ","",function(button,domobject,buttonindex){
parent.frames["custaglist"].f_reload[d13] ();
parent.frames["custaglist"].f_closeWindow();[d14]
});
//},10);
}
function f_error(message)
{
$(document).ready(function(){
$.ligerDialog.error(message);
});
}
function f_post[d15] (){
var options = {
target:'',
url:'custag!save.action',
type:'POST',
success: function(data,textStatus){
if(data=='false'){
$.ligerDialog.closeWaitting();
$.ligerDialog.error("保存失败");
}[d16] [d17] else if(data=='true'){
f_success();
}
}
};
$('#form1').ajaxSubmit(options);[d18]
//$.ligerDialog.closeWaitting();
}
function f_save()
{
if(!Validator.form()) return;
$("form").ligerForm();
$.ligerDialog.waitting("正在保存中...");
setTimeout(function(){
f_post();
},10);
}
</script>
<input type="hidden" name="id" value="${id}"/>[d19]
Input子窗体调用的方法:
Action:
@Override
@SysLogAnnotation(moduleId=1003,entityId="tagid")
public String save() throws Exception {
// TODO Auto-generated method stub
try {
OperatorDetails userDetails = SpringSecurityUtils.getCurrentUser([d20] ) ;
if(id==null){
entity.setCreator(userDetails.getSysuser().getLoginname());
entity.setCreatetime(new Date());[d21]
}
entity.setUpdater(userDetails.getSysuser().getLoginname());
entity.setLastmodify(new Date());
cusTagManager.save(entity);
Struts2Utils.renderText("true");[d22]
} catch (Exception e) {
Struts2Utils.renderText("false");
logger.error("保存客户标签出错", e);
throw e;
}
return NONE;
}
Service:
public void save(CusTag entity){
cusTagDao.save(entity);
}
Dao:
方式二:不允许重复添加,用户输入的时候就判断名字是否重复
分析:
Jsp:
父页面:
{ text: '添加', click:f_add,id:"add" , img:""+ctx+"/js/images/add.png"},
function f_add()
{
f_openWindow('news/newsissueclassify!input.action?classify=0&parentid=0', '添加新闻线索分类', 450, 200);
}
子页面:
<tr>
<td class="l-table-edit-td">分类名称:</td>
<td class="l-table-edit-td">
<input type="text" ltype="text" name="name" size="40" id="name" value="${name}" validate="{required:true,minlength:1,maxlength:25, remote:{url:'newsissueclassify!checkNewsClassifyName.action',data:{oldname:function(){return '${name}';},currentclassify:function(){return '${classify }';}}},messages:{required:'请输入分类名称',remote:'该分类已经存在!'}}" ligerui="{180}"/></td[d23] >
<td align="left"><font color="red">*</font></td>
</tr>
Action:
@Override
public String input() throws Exception {
return INPUT;
}
/**
* 检查分类名称是否已存在
*
* @return
*/
public String checkNewsClassifyName() {
try {
String name = Struts2Utils.getParameter("name[d24] ");
if (name != null) {
name = new String(name.getBytes("ISO-8859-1"), "UTF-8");
}
String oldName = Struts2Utils.getParameter("oldname[d25] ");
if (oldName != null) {
oldName = new String(oldName.getBytes("ISO-8859-1"), "UTF-8");
}
classify = Struts2Utils.getParameter("currentclassify");
if (this.manager.isNameUnique(name, oldName, classify)) {
Struts2Utils.renderText("true");
} else {
Struts2Utils.renderText("false");
}
} catch (Exception e) {
logger.error("检查分类名称是否重名时出错", e);
}
return NONE;
}
Service:
public boolean isNameUnique[d26] (String newName, String oldName, String classify) {
String hql="";
boolean isNameUnique=false[d27] ;
if(oldName!=null&&oldName.equals(newName)){
isNameUnique = true;
}else{
hql+="select n from NewsIssueClassify n where n.classify="+Integer.parseInt(classify);[d28]
if(newName!=null){
hql+=" and n.name=?";
}
if(dao.find(hql, newName).size()==0){
isNameUnique = true;
}
}
return isNameUnique;
}
Dao:
[d1]方式一:
弹tab
[d2]Tab的关闭方式
[d3]动态从数据库取客户类型
[d4]Tab页面取消和确定按钮
[d5]url,title width,height
[d10]第一步
[d12]第二步
[d13]第三步f_reload方法来自父窗体。
frames["custaglist"]指的是父窗体的panel面板
[d14]不明白?
[d15]添加子页面,用ajax题目
[d17]回调函数,
对提交后的结果做判断,如果返回false则关闭当前对话框,并且提示error
[d19]用隐藏域保存添加的id
[d20]获得当前登录用户
[d21]设置为当前时间
[d22]返回给回调函数的message信息,做以提示
[d23]用验证的方式,当用户输入分类名称的时候就可以判定是否重复,如果重复就直接提示:该分类已经存在。
[d24]现在输入的新分类名称
[d25]原来的分类名称
[d26]检查名字是否唯一
[d28]第二次检查
根据新分类名,用hql语句在数据库中查,