浏览 1639 次
锁定老帖子 主题:dwr笔记
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2009-07-24
最后修改:2009-07-24
在Input中输入一个值,当该input丢失焦点后,把该值作为参数通过dwr传到spring中调用对应的方法,返回一个pojo后,在页面对应的input中进行属性填充 public Equipment getEquipmentByCode(String code) { String hql = "from Equipment where typecode = ?"; Equipment equipment = null; List list = this.findByOutQuery(hql, code); if (list.isEmpty()){ return null; }else { equipment = (Equipment)list.get(0); } return equipment;//返回一个po对象,需要里面的name,model等属性 } spring: <beans default-autowire="byName"> <bean id="equipmentService" parent="baseTxProxy"> <property name="target"> <bean class="com.eway.equipment.service.EquipmentServiceImpl"/> </property> </bean> </beans> dwr: <convert match="com.eway.equipment.pojo.Equipment" converter="bean"/>//把该po进行转换 <create creator="spring" javascript="EquipmentService"> <param name="beanName" value="equipmentService"/> <include method="getEquipmentByCode"/>//对应上面spring的这个方法 </create> jsp: <script type='text/javascript' src='/dwr/interface/EquipmentService.js'></script> function getRepairInfo() { var code = $("repair.code").value; EquipmentService.getEquipmentByCode(code,fillInfo);//通过dwr调用后台业务,并调用回调函数 } <script type="text/javascript" language="java"> function fillInfo(equipment){//回调函数,填充值 if(equipment==null){ DWRUtil.setValue("info",'<ww:property value="getText('nocode')"/>'); }else{ DWRUtil.setValue("repair.name",equipment.name); DWRUtil.setValue("repair.model",equipment.model); DWRUtil.setValue("repair.conf",equipment.configureinfo); DWRUtil.setValue("info",''); } } <tr> <td width="12%" align="center" class="common_td_lable"><ww:property value="getText('repair.code')"/></td> <td width="30%" valign="middle" class="common_td_text"> <ww:textfield name="repair.code" maxlength="50" theme="simple" onblur="getRepairInfo();"/>//丢失焦点后触发事件 <small><span id="info"> </span></small> </td> <td width="12%" align="center" class="common_td_lable"><ww:property value="getText('repair.name')"/></td> <td width="30%" valign="middle" class="common_td_text"> <ww:textfield name="repair.name" maxlength="50" theme="simple"/></td> </tr> <tr> <td width="12%" align="center" class="common_td_lable"><ww:property value="getText('repair.model')"/></td> <td width="30%" valign="middle" class="common_td_text"> <ww:textfield name="repair.model" maxlength="50" theme="simple"/></td> <td width="12%" align="center" class="common_td_lable"><ww:property value="getText('repair.conf')"/></td> <td width="30%" valign="middle" class="common_td_text"> <ww:textfield name="repair.conf" maxlength="50" theme="simple"/></td> </tr> <filter> <filter-name>OpenSessionInViewFilter</filter-name> <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> </filter> 时,加入另外一个mapping即搞定 <filter-mapping> <filter-name>OpenSessionInViewFilter</filter-name> <url-pattern>/dwr/*</url-pattern> </filter-mapping> 大概意思是如果是dwr请求hibernate查询,那么不用默认的lazy属性!! 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |