论坛首页 编程语言技术论坛

组合搜索 的翻页功能,大家怎么处理的?

浏览 5558 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2006-10-24  
一个常见的组合搜索功能。
假设:Search页——>显示搜索Form
     Result页——>显示结果,有翻页功能

我实现的方法比较笨,在Result页使用了一个隐藏Form。

不知道大家有什么简单的方法?
   发表时间:2006-10-24  
隐藏的form是用来干吗的?
0 请登录后投票
   发表时间:2006-10-24  
没说清楚,

通过Hidden Form传递搜索项参数,因为result页只显示结果。

0 请登录后投票
   发表时间:2006-10-24  
可以看看我的 railsgacl 中关中 Acl List 的功能

我在里面写了一个 分页的 helper
0 请登录后投票
   发表时间:2006-10-24  
谢谢,我想知道参数怎么传递给分页的链接

Form (search page)——> params (results page)

怎么直接把params传递给分页的链接呢?
0 请登录后投票
   发表时间:2006-10-24  
个人不喜欢用hidden form翻页
虽然后面没什么参数,但是上网的人大部分都习惯把自己喜欢的页面直接复制地址栏的url给别人看
这样翻页,参数等都不存在了,失去share的意思(当然,内部系统除外)

表单用get方式提交(虽然有url长度限制,不过一般情况下谁也不会闲的没事翻页传递非常长的参数吧),params都在url里.

如果想偷懒,可以写个小函数,自动'继承'url的所有参数,把page部分替换成上一页下一页的数字就可以了.

我很懒,写的js(这样就是对搜索引擎友好度差了点).也可以写成服务器端的函数调用好了.
0 请登录后投票
   发表时间:2006-10-24  
kama 写道
一个常见的组合搜索功能。
假设:Search页——>显示搜索Form
     Result页——>显示结果,有翻页功能

我实现的方法比较笨,在Result页使用了一个隐藏Form。

不知道大家有什么简单的方法?


Me too.
0 请登录后投票
   发表时间:2006-10-24  
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper

  def page_leaf(now_page, max_page, options = {}, page_size = nil, line_size = 10)
    if options.is_a?(String)
      "Page Error!"
    else
      str = ['<div class="fenye_Div">']
      line_size = line_size+1 if line_size%2 == 0
      if now_page > 1
          options['page'] = 1
          str << (link_to '&laquo; 第一页', options)
          str << ' ... '
          options['page'] = now_page - 1
          str << (link_to '上一页', options)
      else
        str << '&laquo; 第一页 ... 上一页'
      end
      if ( max_page - now_page < (line_size/2 + 1) && max_page - now_page >= 0 && max_page > line_size)
        for i in max_page-4..max_page
          if (i==now_page)
            str << "<span>[#{i}]</span>"
          else
            options['page'] = i
            str << (link_to "#{i}", options)
          end
        end
      elsif (now_page < (line_size/2 + 1))
        jj = 0
        if (max_page >= line_size)
          jj = line_size
        else
          jj = max_page
        end
        for i in 1..jj
          if (i==now_page)
            str << "<span>[#{i}]</span>"
          else
            options['page'] = i
            str << (link_to "#{i}", options)
          end
        end
      elsif (max_page <= line_size)
        for i in 1..max_page
          if (i==now_page)
            str << "<span>[#{i}]</span>"
          else
            options['page'] = i
            str << (link_to "#{i}", options)
          end
        end
      else
        for i in 1..max_page
          if ((i>now_page-(line_size/2 + 1)) && (i<now_page+(line_size/2 + 1)))
            if (i==now_page)
              str << "<span>[#{i}]</span>"
            else
              options['page'] = i
              str << (link_to "#{i}", options)
            end
          end
        end
      end
      if (now_page < max_page)
        options['page'] = now_page+1
        str << (link_to '下一页', options)
      else
        str << '下一页'
      end
      if (max_page > 1 && max_page != now_page)
        options['page'] = max_page
        str << (link_to '最后页 &raquo;', options)
      else
        str << ' ... 最后页 &raquo;'
      end
      str << '</div>'
      str.join('&nbsp;')
    end
  end

end

调用:
<%= page_leaf @page, @max_page, :id => @group.id, :type => @type %>

<%= page_leaf @page, @max_page, :filter_aco_section => @params[:filter_aco_section]||'', :filter_aco => @params[:filter_aco]||'', :filter_aro_section => @params[:filter_aro_section]||'', :filter_aro => @params[:filter_aro]||'', :filter_aro_group => @params[:filter_aro_group]||'', :filter_axo_section => @params[:filter_axo_section]||'', :filter_axo => @params[:filter_axo]||'', :filter_axo_group => @params[:filter_axo_group]||'', :filter_acl_section => @params[:filter_acl_section]||'', :filter_return_value => @params[:filter_return_value]||'', :filter_allow => @params[:filter_allow]||'', :filter_enabled => @params[:filter_enabled]||'', :submit => @params[:submit]||'' %>
0 请登录后投票
   发表时间:2006-10-24  
看看tapestry中的
package com.live.spaces.dengyin2000.gtts.tapestry.pages.usermanagerment;



import java.util.HashMap;

import java.util.Iterator;

import java.util.Map;



import org.apache.commons.lang.StringUtils;

import org.apache.tapestry.annotations.InjectPage;

import org.apache.tapestry.annotations.Persist;

import org.apache.tapestry.contrib.table.model.IBasicTableModel;

import org.apache.tapestry.contrib.table.model.ITableColumn;

import org.apache.tapestry.event.PageBeginRenderListener;

import org.apache.tapestry.event.PageEvent;



import com.live.spaces.dengyin2000.gtts.domains.User;

import com.live.spaces.dengyin2000.gtts.exceptions.AdminCantDeleteException;

import com.live.spaces.dengyin2000.gtts.tapestry.GttsBasePage;



/**

 * @author Denny - deng.yin@gmail.com

 * @since 2006-10-21

 */

public abstract class UserManagement extends GttsBasePage implements PageBeginRenderListener{

	@Persist

	public abstract User getQueryUser();

	public abstract void setQueryUser(User user);

	

	@InjectPage("usermanagerment/EditUserPage")

	public abstract EditUserPage getEditUserPage();

	

	public void doQuery(){

		

	}

	

	public void pageBeginRender(PageEvent event) {

		if (getQueryUser() == null){

			User queryUser = new User();

			queryUser.setActivated(true);

			setQueryUser(queryUser);

		}

	}

	

	public IBasicTableModel getUsersModel(){

		return new IBasicTableModel(){

			private int count = -1;

			public Iterator getCurrentPageRows(int nFirst, int nPageSize, ITableColumn objSortColumn, boolean bSortOrder) {

				Map<String, Object> params = new HashMap<String, Object>();

				String hql = "from User u where 1=1 ";

				if (StringUtils.isNotBlank(getQueryUser().getLoginName())){

					hql = hql + " and u.loginName like '%:loginName%' ";

					params.put("loginName", getQueryUser().getLoginName());

				}

				if (StringUtils.isNotBlank(getQueryUser().getRealName())){

					hql = hql + " and u.realName like '%:realName%'";

					params.put("realName", getQueryUser().getRealName());

				}

				if (StringUtils.isNotBlank(getQueryUser().getEmail())){

					hql = hql + " and u.email like '%:email%'";

					params.put("email", getQueryUser().getEmail());

				}

				hql = hql + " and u.activated = :activated ";

				params.put("activated", getQueryUser().isActivated());

				

				hql = hql + " order by u.createTime desc";

				return getUserService().findDataForPagination(hql, params, nFirst, nPageSize).iterator();



			}



			public int getRowCount() {

				if (count == -1){

					Map<String, Object> params = new HashMap<String, Object>();

					String hql = "from User u where 1=1 ";

					if (StringUtils.isNotBlank(getQueryUser().getLoginName())){

						hql = hql + " and u.loginName like '%:loginName%' ";

						params.put("loginName", getQueryUser().getLoginName());

					}

					if (StringUtils.isNotBlank(getQueryUser().getRealName())){

						hql = hql + " and u.realName like '%:realName%'";

						params.put("realName", getQueryUser().getRealName());

					}

					if (StringUtils.isNotBlank(getQueryUser().getEmail())){

						hql = hql + " and u.email like '%:email%'";

						params.put("email", getQueryUser().getEmail());

					}

					hql = hql + " and u.activated = :activated ";

					params.put("activated", getQueryUser().isActivated());

					return count =getUserService().getDataCountForPagination(hql, params);

				}else{

					return count;

				}

			}

			

		};

	}

	

	public void doDelete(int userId){

		try {

			getUserService().deleteUser(userId);

		} catch (AdminCantDeleteException e) {

			setError(e.getMessage());

			return ;

		}

		setMessage("删除成功!");

	}

	

	public void doEdit(int userId){

		getEditUserPage().setUserId(userId);

		getRequestCycle().activate(getEditUserPage());

	}

	

}


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>物流管理系统</title>
<script type="text/javascript" src="../js/containInIndexPage.js"></script>
<link rel="stylesheet" href="../css/css.css" type="text/css" media="screen"/>
<script Language="JavaScript">

</script>
</head>
<body jwcid="@Border" topmargin=0>
<form jwcid="@Form" clientValidationEnabled="true" focus="true" listener="listener:doQuery" onsubmit="return check_input(this)">
  <table width="98%" border="0" cellpadding="0" cellspacing="0" align="center" class=TableBorder>
    <tr height="22" valign="middle" align="center"> 
      <th width="15%" height="25"><span jwcid="@FieldLabel" field="component:loginName">用户名</span></th>
      <th width="15%"><span jwcid="@FieldLabel" field="component:realName">真实姓名</span></th>
      <th width="20%"><span jwcid="@FieldLabel" field="component:email">邮箱</span> </th>
      <th width="15%"><span jwcid="@FieldLabel" field="component:activated">是否激活帐号</span></th>
      <th width="20%">&nbsp;</th>
    </tr>
    <tr height="22" valign="middle" align="center">
       <td><input TYPE="text" jwcid="loginName@TextField" value="ognl:queryUser.loginName" displayName="用户名" size="20" maxlength="20"/></td>
       <td><input TYPE="text" jwcid="realName@TextField" value="ognl:queryUser.realName" displayName="真实姓名" size="20" maxlength="20" /></td>
       <td><input TYPE="text" jwcid="email@TextField" value="ognl:queryUser.email" displayName="邮箱" size="20" maxlength="20" /></td>
       <td><check TYPE="text" jwcid="activated@Checkbox" value="ognl:queryUser.activated" displayName="是否激活帐号" size="20" maxlength="20" /></td>
       <td><INPUT name="Submit" type="submit" value="查询"> &nbsp;&nbsp;     
		<INPUT name="Submit2" type="reset" value="清除"></td>
    </tr>
   </table>   
</form>
<table jwcid="table@contrib:TableView" source="ognl:usersModel" pageSize="3"
 	columns="literal:!loginName:loginName, !realName:realName, !email:email, !activated:activated, !createTime:createTime, !lastUpdateTime:lastUpdateTime, !operation" 
 	 width="98%" border="0" cellpadding="2" cellspacing="0" align="center" class=TableBorder>
  <tr height="22" valign="middle" align="center"> 
    <th height="25" colspan="7">用户查询结果</th>
  </tr>
  <tr> 
    <td width="15%" height="25" class=forumrow><div align="center">用户ID</div></td>
    <td width="15%" class=forumrow><div align="center">用户姓名</div></td>
    <td width="20%" class=forumrow> <div align="center">电子邮箱</div></td>
    <td width="10%" class=forumrow> <div align="center">是否激活</div></td>
    <td width="15%" class=forumrow><div align="center">创建时间</div></td>
    <td width="15%" class=forumrow> <div align="center">最后登入时间</div></td>
    <td width="20%" class=forumrow> <div align="center">操作</div></td>
  </tr>
  <tr> 
   <td style="display: none" class=forumrow jwcid="@contrib:TableColumns"></td>
   <td></td>
  </tr>
  <tr jwcid="tableRows@contrib:TableRows">
	<td jwcid="@contrib:TableValues" height="25" align="center"/>
	<td height="25" align="center" jwcid="operationColumnValue@Block">
		<a jwcid="@DirectLink" parameters="ognl:components.tableRows.tableRow.id" listener="listener:doDelete" >删除</a>
		<a jwcid="@DirectLink" parameters="ognl:components.tableRows.tableRow.id" listener="listener:doEdit" >修改</a>		
	</td>
   </tr>
   <tr>
   	<th align="right" colspan="7">
   		<span jwcid="@contrib:TablePages"></span>
   	</th>
   </tr>
</table>   
</body>
</html>
0 请登录后投票
论坛首页 编程语言技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics