function setDefaultDate()
{
var now=new Date();
var year=now.getYear();
var month=now.getMonth();
var day=now.getDate();
var hours=now.getHours();
var minutes=now.getMinutes();
var seconds=now.getSeconds();
oDate1 = document.forms[0].elements["item.svrCreateDate"];
if (oDate1.value=="")
{
oDate1.value = year+"-"+month+"-"+(day-1);
}
oDate2 = document.forms[0].elements["item.svrCreateDate2"];
if (oDate2.value=="")
{
oDate2.value = (year+1)+"-"+month+"-"+day;
}
}补充一下 初始化会调用这个
{
var now=new Date();
var year=now.getYear();
var month=now.getMonth();
var day=now.getDate();
var hours=now.getHours();
var minutes=now.getMinutes();
var seconds=now.getSeconds();
oDate1 = document.forms[0].elements["item.svrCreateDate"];
if (oDate1.value=="")
{
oDate1.value = year+"-"+month+"-"+(day-1);
}
oDate2 = document.forms[0].elements["item.svrCreateDate2"];
if (oDate2.value=="")
{
oDate2.value = (year+1)+"-"+month+"-"+day;
}
}补充一下 初始化会调用这个
为什么不直接用时间标签?
1.
private Date svrCreateDate2
这个是查询用的?但是在映射文件里并没有啊2.从前台怎么传Date型数据过来,不是只能是String或者boolean吗?3.你把什么改成String型了?
正确,
jsp中的表单传送的都是string,你可以写个data类在后台转换,
转个别人写的类,
public class DateUtility {
public DateUtility() {
}
static public String format(java.util.Date date,String pattern) {
SimpleDateFormat df = new SimpleDateFormat(pattern,Locale.UK);
return df.format(date);
}
static public Date getDate(String str) {
SimpleDateFormat df = null;
if(str.length()==10) {
df = new SimpleDateFormat("yyyy-MM-dd",Locale.UK);
}
else if(str.length()==16) {
df = new SimpleDateFormat("yyyy-MM-dd HH:mm",Locale.UK);
}
else if(str.length()==19) {
df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",Locale.UK);
}
else {
df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS",Locale.UK);
}
Date date = df.parse(str,new ParsePosition(0));
//if(date==null) date = new java.util.Date();
return date;
}
static public Date getDate(String str,String pattern) {
SimpleDateFormat df = new SimpleDateFormat(pattern,Locale.UK);
Date date = df.parse(str,new ParsePosition(0));
return date;
}
static public String toTimestampFormat(String str) {
return new Timestamp(getDate(str).getTime()).toString();
}
public static Timestamp getTimestamp(String str) {
if(str==null) return null;
else return new Timestamp(getDate(str).getTime());
}
public static Timestamp getTimestamp(String str,String pattern) {
if(str==null) return null;
else return new Timestamp(getDate(str,pattern).getTime());
} public static Timestamp getTimestamp(java.util.Date date) {
if(date==null) return null;
else return new Timestamp(date.getTime());
}
public static java.sql.Date getSqlDate(java.util.Date date) {
if(date==null) return null;
else return new java.sql.Date(date.getTime());
}
public static java.sql.Date getSqlDate(String str) {
if(str==null) return null;
else return new java.sql.Date(getDate(str).getTime());
}
public static java.sql.Date getSqlDate(String str,String pattern) {
if(str==null) return null;
else return new java.sql.Date(getDate(str,pattern).getTime());
}
}
,这时我一般建一个search的包,里面放各种搜索对象,然后用request的各个属性去初始化这个对象的值,
在action中再根据这个对象去构造hql
private Date svrCreateDate2;// 用作查询条件 建议把这个类型改为String类型试试你的调用方法的参数类型是否一致?
你检查一下
有什么解决方法吗?
页面中就可以传递String boolean?
String转化为Date就会出现异常,就好是写个自定义的转换器,再注入,
就行了,我遇到过,要写的转换器我这里有,要的话,加我QQ:253792300
是spring的Date转换器,写好了还要注入的
不然,都不认识的!
<%@ page language="java" pageEncoding="GBK" import="com.yy.pojo.SysUser" %>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%@ taglib uri="/WEB-INF/jb-common.tld" prefix="jb"%>
<script src="validate.js"></script>
<script src="icommon.js"></script><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html lang="true">
<head>
<title>客户服务管理</title>
<link rel="stylesheet" type="text/css" href="styles.css">
<script>
function doDel(id){
if ( window.confirm("确定删除?") ){
window.location.href = "?o=doDel&id=" + id;
}
}
function setDefaultDate()
{
var now=new Date();
var year=now.getYear();
var month=now.getMonth();
var day=now.getDate();
var hours=now.getHours();
var minutes=now.getMinutes();
var seconds=now.getSeconds();
oDate1 = document.forms[0].elements["item.temp"];
if (oDate1.value=="")
{
oDate1.value = year+"-"+month+"-"+(day-1);
}
oDate2 = document.forms[0].elements["item.svrCreateDate2"];
if (oDate2.value=="")
{
oDate2.value = (year+1)+"-"+month+"-"+day;
}
}
function doSearch()
{
setDefaultDate();
doSubmit('${param.o }');
}
function setLabel(oSrc,tTargetLabelName,tTargetIdName)
{
var oLabelCtl = document.forms[0].elements[tTargetLabelName];
var oIdCtl = document.forms[0].elements[tTargetIdName];
oLabelCtl.value = oSrc.options[oSrc.selectedIndex].text;
oIdCtl.value = oSrc.options[oSrc.selectedIndex].value;
}
function doDispatch(svrId)
{
if (!document.forms[0].elements["svrDueId"].value)
{
alert("请选择分配给的人员");
return ;
}
alert(svrId);
setDefaultDate();
document.forms[0].elements['svrId'].value = svrId;
doSubmit('doDispatch');
}
</script>
</head>
<body>
<html:form action="service">
<html:hidden property="o" value="toList" />
<input type="hidden" name="svrId" />
<input type="hidden" name="svrDueId" />
<input type="hidden" name="svrDueTo" />
<div class="page_title">客户服务管理</div>
<div class="button_bar">
<button class="common_button" onclick="help('');">帮助</button>
<button class="common_button"
onclick="window.location.href='?o=toAdd';">新建</button>
<button class="common_button" onclick="javascript:doSearch();">查询</button>
</div>
<table class="query_form_table" border="0" cellPadding="3"
cellSpacing="0">
<tr>
<th>服务类型</th>
<td><html:text property="item.svrType" /></td>
<th>概要</th>
<td><html:text property="item.svrTitle" /></td>
</tr>
<tr>
<th>客户</th>
<td><html:text property="item.svrCustName" /></td>
<th>创建时间<br />(日期格式:2008-02-22)</th>
<td><html:text property="item.temp" size="10" />-<html:text property="item.svrCreateDate2" size="10" /></td>
</tr>
</table>
<!-- 列表数据 -->
<br />
<table class="data_list_table" border="0" cellPadding="3"
cellSpacing="0">
<tr>
<th onclick="order_by('svrId');">编号</th>
<th onclick="order_by('svrType');">服务类型</th>
<th onclick="order_by('svrTitle');">概要</th>
<th onclick="order_by('svrCustName');">客户</th>
<th onclick="order_by('svrCreateBy');">创建人</th>
<th onclick="order_by('svrCreateDate');">创建时间</th>
<th onclick="order_by('svrDueTo');">分配给</th>
<th>操作</th>
</tr>
<logic:iterate id="item" name="serviceForm" property="pageResult.list"
type="com.yy.pojo.CstService">
<tr>
<td class="list_data_number">${item.svrId } </td>
<td class="list_data_text">${item.svrType } </td>
<td class="list_data_ltext">${item.svrTitle } </td> <td class="list_data_text">${item.svrCustName } </td> <td class="list_data_text">${item.svrCreateBy } </td>
<td class="list_data_text"><bean:write name="item"
property="svrCreateDate" format="yyyy年MM月dd日" /> </td> <td class="list_data_text">
<!-- <select property="xx" onchange="setLabel(this,'svrDueTo','svrDueId');">
<option value="0">未指定</option>
userOptions%>
</select> -->
<html:select property="item.svrType" onchange="setLabel(this,'svrDueTo','svrDueId');">
<html:option value="">未指定</html:option>
<html:optionsCollection name="USERS_OPTIONS" label="usrName" value="usrId"/>
</html:select>
<button onclick="doDispatch('${item.svrId }');">分配</button>
</td>
<td class="list_data_op"><img
onclick="doDel('${item.svrId }');" title="删除"
src="images/bt_del.gif" class="op_button" /></td>
</tr>
</logic:iterate>
<logic:empty name="serviceForm" property="pageResult.list">
<tr>
<td class="data_cell" colspan="20"
style="text-align:center;height:40px;">没有记录</td>
</tr>
</logic:empty>
<tr>
<td colspan="20" style="padding:0 1px;">
<div class="pager"><jb:pager form="serviceForm" /></div>
</td>
</tr>
</table></html:form>
</body>
</html:html>这是我页面所写的
<bean
class="org.springframework.beans.factory.config.CustomEditorConfigurer">
<property name="customEditors">
<map>
<entry key="com.baobaotao.editor.Car">
<bean class="com.baobaotao.editor.CustomCarEditor" />
</entry>
</map>
</property>
</bean>