2015-11-05 66 views
0


這裏是我的問題:
我使用的Liferay 6.2,與Struts2的

我想用DisplayTag爲分頁,但沒有按表沒有出現,並且Liferay向我顯示此消息「沒有任何發現顯示。」
Liferay6.2:DisplayTag在Struts2 - 「沒有顯示」

我需要顯示3名學生在一個HTML表:

我把所有的代碼(波紋管)的一個簡單而經典的「動態Web項目」與Tomcat7,我可以看到我的3名學生。
但在這裏,與Liferay的,我已經得到了消息 「沒有顯示。」

web.xml中:

<web-app [...]> 
    <display-name>HelloStruts</display-name> 
    <display-name>Struts 2 Web Application</display-name> 
    <filter> 
     <filter-name>struts2</filter-name> 
     <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> 
    </filter> 
    <filter-mapping> 
     <filter-name>struts2</filter-name> 
     <url-pattern>/*</url-pattern> 
    </filter-mapping> 
</web-app> 



struts.xml中:

<struts> 
    <constant name="struts.devMode" value="true" /> 
    <package namespace="/view" extends="struts-portlet-default" name="view"> 
     <action name="viewDisplayTags" class="com.displaytags.StudentAction" method="fetchStudentList"> 
      <result name="success">/html/displaytags/viewDisplayTags.jsp</result> 
     </action> 
    </package> 
</struts> 



StudentAction.java:

public class StudentAction extends ActionSupport { 
    private List<StudentBean> students = new ArrayList<StudentBean>(); 

    public String fetchStudentList() { 
     students.add(new StudentBean("o7bb002", "Ajay")); 
     students.add(new StudentBean("o7bc055", "Mohiadeen")); 
     students.add(new StudentBean("o7bc074", "Sriram Ganesh")); 

     return SUCCESS; 
    } 

    public List<StudentBean> getStudents() { 
     return students; 
    } 

    public void setStudents(List<StudentBean> students)  { 
     this.students = students; 
    } 
} 

StudentBean.java

public class StudentBean { 

    private String rollNo; 
    private String studentName; 

    public StudentBean(String rollNo, String studentName) { 
     this.rollNo = rollNo; 
     this.studentName = studentName; 
    } 

    public String getRollNo() { 
     return rollNo; 
    } 

    public void setRollNo(String rollNo) { 
     this.rollNo = rollNo; 
    } 

    public String getStudentName() { 
     return studentName; 
    } 

    public void setStudentName(String studentName) { 
     this.studentName = studentName; 
    } 
} 

viewDisplayTags.jsp

<%@taglib prefix="s" uri="/struts-tags" %> 
<%@ include file="/html/init.jsp" %> 
<%@ include file="headerDisplayTags.jspf" %> 

<%@ taglib prefix="display" uri="http://displaytag.sf.net"%> 

<s:hidden name="studentsHiddenList" value="%{students}" /> 

<display:table name="students"> 
    <display:column property="rollNo" title="Roll No" sortable="true"></display:column> 
    <display:column property="studentName" title="Student Name" sortable="true" ></display:column> 
</display:table> 


這是奇怪的,因爲與「隱藏」(在「viewDisplayTags.jsp」),我可以看到我的3名學生的內容......學生列表是從Java類傳遞到JSP


謝謝!

回答

0

我終於找到了答案:
清單「學生」沒有在「請求」,並在「屬性requestURI」設置不正確


StudentAction.java:

public class StudentAction extends ActionSupport { 
    private List<StudentBean> students = new ArrayList<StudentBean>(); 

    public String fetchStudentList() { 
     students.add(new StudentBean("o7bb002", "Ajay")); 
     students.add(new StudentBean("o7bc055", "Mohiadeen")); 
     students.add(new StudentBean("o7bc074", "Sriram Ganesh")); 

     Map request = (Map) ActionContext.getContext().get("request"); 
     request.put("students",students); 

     return SUCCESS; 
    } 

    public List<StudentBean> getStudents() { 
     return students; 
    } 

    public void setStudents(List<StudentBean> students) { 
     this.students = students; 
    } 
} 

viewDisplayTags.jsp

<%@taglib prefix="s" uri="/struts-tags" %> 
<%@ include file="/html/init.jsp" %> 
<%@ include file="headerDisplayTags.jspf" %> 

<%@ taglib prefix="display" uri="http://displaytag.sf.net"%> 

<s:hidden name="studentsHiddenList" value="%{students}" /> 

<display:table name="students" class="StudentAction" requestURI="/viewDisplayTags.jsp"> 
    <display:column property="rollNo" title="Roll No" sortable="true"></display:column> 
    <display:column property="studentName" title="Student Name" sortable="true" ></display:column> 
</display:table> 
+0

MMNO,這並不是說,這是一種解決方法...只是用戶requestURI和id的頁面和#attr。從displaytag訪問請求數據:http://www.simplecodestuffs.com/struts-2-tag-not-working-inside-a-display-tag-solution/ –