【问题标题】:Liferay6.2 : DisplayTag in Struts2 - "Nothing to display"Liferay6.2:Struts2 中的 DisplayTag - “无显示”
【发布时间】:2015-11-05 17:07:05
【问题描述】:


这是我的问题:
我正在使用带有 Struts2 的 Liferay 6.2

我想使用 DisplayTag 进行分页,但表格没有出现,Liferay 向我显示这条消息“Nothing found to display”。

我需要在 HTML 表格中显示 3 个学生:

我将所有代码(如下)放在一个简单而经典的“动态 Web 项目”中,使用 Tomcat7,可以看到我的 3 个学生。
但是在这里,使用 Liferay,我收到了消息“Nothing to display.”

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


谢谢!

【问题讨论】:

    标签: java jsp struts2 liferay displaytag


    【解决方案1】:

    我终于找到了答案:
    列表“Students”不在“请求”中,并且“”中的属性 class 和 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>
    

    【讨论】:

    • mmno,不是这样,这是一种解决方法...只是页面中的用户 requestURI 和 id 以及#attr。从 displaytag 访问请求数据:simplecodestuffs.com/…
    猜你喜欢
    • 1970-01-01
    • 2011-03-15
    • 1970-01-01
    • 2010-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多