2012-04-11 22 views
0

私のstruts2 Webアプリケーションにページネーションを適用したいと思います。ユーザーがログインすると、ホームページにリダイレクトされます。このページでは、displayタグを使用してすべてのユーザーをページ区切りに表示します。ページ切り替えのためのStruts2のDisplayTag

私は研究を行い、最終的にこれを私のstruts2に統合しましたが、ログイン後にコードを実行すると、メッセージNothing found to displayが表示されます。

私がstruts1.3で同じことをしたところ、this siteからそれが動作しています。 私はlibフォルダに次のJARファイルをコピーした:私はまた私のweb-infフォルダにdisplaytag.tldstruts-2.17.dtdをコピーした

commons-logging.jar 
commons-lang.jar 
commons-collections.jar 
commons-beanutils.jar 
displaytag-1.2.jar 

私profile.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%> 
<!DOCTYPE html> 
<%@taglib uri="http://displaytag.sf.net" prefix="display" %> 
<%@taglib uri="/struts-tags" prefix="s" %> 
<html> 
    <head> 
    </head> 
<body> 
    <div id="wrapper"> 
     <div id="steps"> 
      <fieldset class="step"> 
       <legend>Profile 
        </legend> 
       <display:table id="data" name="list" requestURI="/display.action" pagesize="1" > 
        <display:column sortable="true"> 
         <p> 
          <label for="username">User Name</label> 
          <input id="username" name="username" value="<s:property value="firstName" />" disabled="disabled"/> 
         </p> 
         <p> 
          <label for="email">Father Name</label> 
          <input id="email" name="email" value="<s:property value="lastName"/>" disabled="disabled" /> 
         </p> 
         <p> 
          <label for="password">Age</label> 
          <input name="password" value="<s:property value="dob"/>" disabled="disabled"/> 
         </p> 
         <p> 
          <label for="address">Address</label> 
          <input name="address" value="<s:property value="emailID"/>" disabled="disabled"/> 
         </p> 
       </fieldset> 
        </div> 
       </display:column> 
      </display:table> 
     </div> 
    </div> 
</body> 
</html> 

Struts.xml

<action name="display" class="com.java.action.SearchAction"> 
     <result name="success">/profile.jsp</result> 
     <result name="errror">/error.jsp</result> 
</action> 

SearchAction.java

private ArrayList<UserBean> list=new ArrayList<UserBean>(); 
//setter getter 
public String execute() 
{ 
    UserBean rt=new UserBean(); 
    SearchDB user=new SearchDB(); 
    this.setList(user.search(gender,age_min,age_max,religion,caste,photo_display)); 
    return SUCCESS; 
} 

UserBean.java

0:以下

は私のコードです

public class UserBean { 

private String emailID; 
private String userName; 
private String gender; 
private String dob; 
private String firstName; 
private String lastName; 
private int Id; 
//setter and getter 
} 

SearchDB.java

//code to get records. their is no problem here because it is taking records out from db fine. 

私はわからないが、私の推測では、requestURIdisplaytagのname属性上記のリンクの例では、彼らはname="sessionScope.UserForm.userList"を使用しているためです。誰かが私が間違っていたことを教えてくれませんか?

+0

あなたのJSPの始めにtaglibディレクティブに興味があります。私はstruts1への参照とこのstruts2のタグ付けについて非常に混乱しています。 – Quaternion

+0

taglibディレクティブで質問を更新する@Quaternion – user1184777

+0

私は表示タグを使用しないので、推測します。私の推測では、表示タグは通常のELを使用していますが、Struts2はOGNLを使用しています。だから、表示テーブルの "name"属性が "list"をスタックの一番上に押していないので、s2タグは彼らが何を使っているのか分からない...次の二つのことを試してみる:s2の代わりに " firstName "write" list.firstName "(何かが表示されたら、私が言ったことが真であることを知っている)、すべてのプロパティタグを" $ {fieldName} "に置き換えてみてください(angle bracketはありません!コースの名前]と何かが起こるかどうかを参照してください) – Quaternion

答えて

0

あなたはおそらくすでにそれを解決しますが、とにかく...そうのようなOGNLをお試しください:

<input id="username" name="username" value="%{data.firstName}" disabled="disabled"/> 

それは直接ユーザーのプロパティのゲッターを使用しています。ところで、私はあなたの無効にされたタグが不明です。おそらくreadonlyを代わりに使うべきです。あなたは、表示タグ等のためのレコードの合計数を設定している

0

、ページとページと、すべての最初のレコードごとのレコードを設定し、アクションクラスから

<display:table id="data" name="lstEntities" 
         sort="external" uid="row" htmlId="rowid" class="tborder" 
         style="width:100%" excludedParams="*" 
         pagesize="${pageCriteria.recordsPerPage}" partialList="true" 
         size="${pageCriteria.totalRecords}" export="false" 
         requestURI="XXX.action"> 





    public class PaginationCriteria implements Cloneable, CommonConstants, 
      Serializable { 

     /** 
     * Holds the Unie value of Class. 
     */ 
     private static final long serialVersionUID = 8047568459658871831L; 

     /** 
     * Stores cache Mode. 
     */ 
     private boolean cached; 

     /** 
     * Stores current page number in the user screen. 
     */ 
     private int currentPage; 

     /** 
     * Holds the Name of the attribute in Entity to be unique. 
     */ 
     private String distinctRootEntityName; 

     /** 
     * Stores the information about no of entities to be fetched. 
     */ 
     private boolean fetchAll; 

     /** 
     * Stores the information about no. of records to be fetched. 
     */ 
     private int recordsPerPage; 

     /** 
     * Stores the secondary sort column of the entity. 
     */ 
     private String secondarySortBy; 

     /** 
     * Stores the Sort column of the entity. 
     */ 
     private String sortBy; 

     /** 
     * Stores the sort order of the entity. 
     */ 
     private boolean sortDescending; 

     /** 
     * Stores total no. of records. 
     */ 
     private int totalRecords; 

//Getters and setters of this properties 

} 

。クエリの実行では、実行の合計数を設定します。このドメインオブジェクトをActionクラスに配置します。アクションCLASで

は、ページネーション情報を設定するには、以下の方法を使用し、

/** 
    * Fills the Sort column, order, page number to be retrieved. 
    * 
    * @param tableId - 
    *  Display tag table Id to retrieve the Sort column, order, page 
    *  number 
    * @param defaultOrderCoulmn - 
    *  If no parameter passed for sorting default order column will be 
    *  applied. 
    */ 
    protected void fillPaginationInfo(final String tableId, 
      final String defaultOrderCoulmn, final String secondarySortColumn) { 
     BaseAction.LOGGER.debug(BaseAction.LOG_PREFIX 
       + "calling fillPaginationInfo param: tableId :" + tableId 
       + "\ndefaultOrderCoulmn:" + defaultOrderCoulmn); 
     this.getPageCriteria().setCurrentPage(
       this.getPageNumber(this.getHttpRequest(), tableId)); 
     String orderBy = this.getSortColumn(this.getHttpRequest(), tableId); 
     this.getPageCriteria().setSortBy(
       orderBy == null || orderBy.equals("null") ? defaultOrderCoulmn 
         : orderBy); 
     this.getPageCriteria().setSortDescending(
       this.getSortOrderDesc(this.getHttpRequest(), tableId)); 
     if (secondarySortColumn != null) 
      this.getPageCriteria().setSecondarySortBy(secondarySortColumn); 
     BaseAction.LOGGER.debug(BaseAction.LOG_PREFIX 
       + "done fillPaginationInfo"); 
    } 

は、それが役立ちますでしょう願っています。他の情報が必要な場合はお知らせください。

関連する問題