Search code examples
struts2tilesdisplaytag

Displaytag table paging with tiles


Im using displaytable with tiles. Problem is in my crud application, when I search something its loading data into display table, and when I click on 2nd page its load data to 2nd page as I give requestURI="searchorgs". All works fine upto that, Then I call Edit template and after submitting edited data it should load data to table. Its also work fine but when I click 2nd page Its goes to search page as I mention in requestURI="searchorgs". I need to keep in same page with out moving to search page. Same table is insert in to add,edit,search jsp pages in tiles.xml. I dont want to define 3 separate tables for this. Application I struts2 tiles integration one.

action class search method :

public String search() {
organisationSearch = new OrganisationSearch();

organisationSearch.setAoName(aoName);

orglist = orgBo.searchOrg(organisationSearch);

return "search";

}

Struts xml :

  <action name="*orgs" class="com.ast.action.admin.OraganisationAction"
            method="{1}">

            <result name="add" type="tiles">orgAddTemplate</result>

            <result name="search" type="tiles">orgTemplate</result>
            <result name="delete" type="tiles">orgTemplate</result>

            <result name="edit" type="tiles">orgEditTemplate</result>
            <r
        </action>

table :

 <s:form theme="simple" id="delete" action="deleteorgs">
    <display:table id="studentTable" name="orglist" pagesize="5" cellpadding="5px;" id="row" cellspacing="5px;"
        style="margin-left:50px;margin-top:20px;" requestURI="searchorgs">
        <display:column style="width:5px;">
            <s:checkbox name="chkBox" id="check%{#attr.row_rowNum - 1}" value="%{#attr.row.chkBox}" fieldValue="%{#attr.row.aoId}" />
        </display:column>
        <display:column title="Action" style="width:10px;" value="Edit" href="vieweditorgs" paramId="aoId" paramProperty="aoId" />
        <display:column title="View" style="width:10px;" value="View" href="vieworgs" paramId="aoId" paramProperty="aoId" />
        <display:column title="Dlt" style="width:10px;" value="Dlt" href="singledeleteorgs" paramId="aoId" paramProperty="aoId" />
        <display:column property="aoId" title="ID" />
        <display:column property="aoName" title="Name" />

    </display:table>

Solution

  • You need to define action in requesturi programmatically.

    Please see this

    dispalay tag table pass value to requestURI

    In action class

     private String myActionName;
    
     public String search() {
          organisationSearch = new OrganisationSearch();
    
          organisationSearch.setAoName(aoName);
    
          orglist = orgBo.searchOrg(organisationSearch);
          //set action name
          myActionName="action1.action";
          return "search";
    
     }
     //other methods
     public void setMyActionName(String myActionName) {
        this.myActionName = myActionName;
      }
    
    public String getMyActionName() {
        return myActionName;
    }
    

    In jsp file

     <display:table id="u" name="userlist"  pagesize="10"   requestURI="${myActionName}" >
      ...
     </display:table>
    

    If I misunderstood your question, Please let me know.