JSTL 需要一个逗号分隔的数组来在 JSP 上显示数据

发布于 2025-01-05 18:48:20 字数 5319 浏览 1 评论 0原文

又是我。我从 bean 列表中显示了结果,但是当我们对数据库包进行一些汇总时遇到了问题。正如您所看到的,卷起的线条显示为内存位置,我相信这就是它的名字。有人建议我可以使用“varstatus”之类的东西并迭代以制作逗号分隔的数组来显示实际数据?

这听起来正确吗?

标题很好......它的数据我指的是

Thanx

在此处输入图像描述

如果图片太小..最后 3 列填充如下:“[Ljava.lang.String;@11396ec”

BEAN:

public class DetResults
{
private List<String> headings;
private List<Class<?>> types;
private List<Object[]> data;

public DetResults() {}

public List<String> getHeadings() { return this.headings; }
public String getHeading(int which) { return this.headings.get(which); }

public List<Class<?>> getTypes() { return this.types; }
public Class<?> getType(int which) { return this.types.get(which); }

public List<Object[]> getData( ) { return this.data; }
public Object[] getDataAtRow( int row ) { return this.data.get(row); }


public void setHeadings( List<String> val ) { this.headings = val; }
public void setHeadings( String[] val ) { this.headings = Arrays.asList(val); }
public void addHeading( String val ) 
{ 
    if( this.headings == null ) this.headings = new ArrayList<String>();
    this.headings.add(val); 
}

public void setTypes( List<Class<?>> val ) { this.types = val; }
public void setTypes( Class<?> val[] ) { this.types = Arrays.asList(val); }
public void addType( Class<?> val ) 
{
    if( this.types == null ) this.types = new ArrayList<Class<?>>();
    this.types.add(val); 
}


public void setData( List<Object[]> val ) { this.data = val; }

// allow NPE to get thrown
public void setDataAtRow( Object[] val, int row ) { this.data.set(row, val); }

public void appendDataRow( Object[] val ) 
{
    if( data == null ) data = new ArrayList<Object[]>(); 
    this.data.add(val); 
}

public int getColumnCount() { return this.headings!=null?this.headings.size():0; }

}

JSP:

<tr>
        <th>
            <span onclick="toggleDiv('resultSet', 'resultImg')" style="cursor: hand;">Results&nbsp;<img name="resultImg" src="../images/minus.gif" /></span>
        </th>
    </tr>
    <tr>
        <td>
            <div id="resultSet" style="display:block; background-color:#ffffff;">

            <!--Begin Search Results -->
            <c:choose>
            <c:when test="${not empty results.columnCount}">

                <ctl:vertScroll height="300" headerStyleClass="data_table_scroll" bodyStyleClass="data_table_scroll" enabled="${user.scrollTables}">
              <!--  <ctl:sortableTblHdrSetup topTotal="false" href="show.whatif_like_item_search"/> -->
                <table align="center" class="data_table vert_scroll_table" >
                    <tr>
                    <c:forEach var="heading" items="${results.headings}">    
                      <th class="narrow">${heading}</th>
                      </c:forEach> 
                      </tr>
                      <c:forEach var="row" items="${results.data}">   
                        <tr>
                        <c:forEach var="cell" items="${row}">   
                        <td>${cell}</td>
                        </c:forEach> 
                        </tr>
                        </c:forEach> 
                </table>
                </ctl:vertScroll>

            </c:when>
            <c:otherwise>
                <!--  SHOW NOTHING -->
            </c:otherwise>
            </c:choose>

            <!--End Search Results -->



            </div>
        </td>
    </tr>

ANSWER:

<table align="center" class="data_table vert_scroll_table" >
                <tr>
                    <c:forEach var="heading" items="${results.headings}">   
                        <th class="narrow">${heading}</th>
                    </c:forEach>
                </tr>
                <c:forEach var="row" items="${results.data}">
                    <tr>
                        <c:forEach var="cell" items="${row}" varStatus="rowStatus">
                            <td style="width:200px;">
                                <c:choose>
                                    <c:when test="${results.types[rowStatus.index].array}">
                                        <c:forEach var="elem" items="${cell}" varStatus="cellStatus">
                                            ${elem}<c:if test="${!cellStatus.last}">,&nbsp;</c:if>
                                        </c:forEach>
                                    </c:when>
                                    <c:otherwise>
                                            ${cell}
                                    </c:otherwise>
                                </c:choose>
                            </td>
                        </c:forEach>
                    </tr>
                </c:forEach>
                </table>

its me again. I got my results to display from the bean list, but ran into a issue when we did some rollups on the database package. As you can see the lines that are rolled up on show as memory locations, I believe is what it's called. I was advised that I can use something like "varstatus" and iterate over to make a comma separated array to display the actual data?

Does this sound right?

The headings are fine...its the data Im referring to

Thanx

enter image description here

If the picture is too small...the last 3 columns are popuated with this: "[Ljava.lang.String;@11396ec"

BEAN:

public class DetResults
{
private List<String> headings;
private List<Class<?>> types;
private List<Object[]> data;

public DetResults() {}

public List<String> getHeadings() { return this.headings; }
public String getHeading(int which) { return this.headings.get(which); }

public List<Class<?>> getTypes() { return this.types; }
public Class<?> getType(int which) { return this.types.get(which); }

public List<Object[]> getData( ) { return this.data; }
public Object[] getDataAtRow( int row ) { return this.data.get(row); }


public void setHeadings( List<String> val ) { this.headings = val; }
public void setHeadings( String[] val ) { this.headings = Arrays.asList(val); }
public void addHeading( String val ) 
{ 
    if( this.headings == null ) this.headings = new ArrayList<String>();
    this.headings.add(val); 
}

public void setTypes( List<Class<?>> val ) { this.types = val; }
public void setTypes( Class<?> val[] ) { this.types = Arrays.asList(val); }
public void addType( Class<?> val ) 
{
    if( this.types == null ) this.types = new ArrayList<Class<?>>();
    this.types.add(val); 
}


public void setData( List<Object[]> val ) { this.data = val; }

// allow NPE to get thrown
public void setDataAtRow( Object[] val, int row ) { this.data.set(row, val); }

public void appendDataRow( Object[] val ) 
{
    if( data == null ) data = new ArrayList<Object[]>(); 
    this.data.add(val); 
}

public int getColumnCount() { return this.headings!=null?this.headings.size():0; }

}

JSP:

<tr>
        <th>
            <span onclick="toggleDiv('resultSet', 'resultImg')" style="cursor: hand;">Results <img name="resultImg" src="../images/minus.gif" /></span>
        </th>
    </tr>
    <tr>
        <td>
            <div id="resultSet" style="display:block; background-color:#ffffff;">

            <!--Begin Search Results -->
            <c:choose>
            <c:when test="${not empty results.columnCount}">

                <ctl:vertScroll height="300" headerStyleClass="data_table_scroll" bodyStyleClass="data_table_scroll" enabled="${user.scrollTables}">
              <!--  <ctl:sortableTblHdrSetup topTotal="false" href="show.whatif_like_item_search"/> -->
                <table align="center" class="data_table vert_scroll_table" >
                    <tr>
                    <c:forEach var="heading" items="${results.headings}">    
                      <th class="narrow">${heading}</th>
                      </c:forEach> 
                      </tr>
                      <c:forEach var="row" items="${results.data}">   
                        <tr>
                        <c:forEach var="cell" items="${row}">   
                        <td>${cell}</td>
                        </c:forEach> 
                        </tr>
                        </c:forEach> 
                </table>
                </ctl:vertScroll>

            </c:when>
            <c:otherwise>
                <!--  SHOW NOTHING -->
            </c:otherwise>
            </c:choose>

            <!--End Search Results -->



            </div>
        </td>
    </tr>

ANSWER:

<table align="center" class="data_table vert_scroll_table" >
                <tr>
                    <c:forEach var="heading" items="${results.headings}">   
                        <th class="narrow">${heading}</th>
                    </c:forEach>
                </tr>
                <c:forEach var="row" items="${results.data}">
                    <tr>
                        <c:forEach var="cell" items="${row}" varStatus="rowStatus">
                            <td style="width:200px;">
                                <c:choose>
                                    <c:when test="${results.types[rowStatus.index].array}">
                                        <c:forEach var="elem" items="${cell}" varStatus="cellStatus">
                                            ${elem}<c:if test="${!cellStatus.last}">, </c:if>
                                        </c:forEach>
                                    </c:when>
                                    <c:otherwise>
                                            ${cell}
                                    </c:otherwise>
                                </c:choose>
                            </td>
                        </c:forEach>
                    </tr>
                </c:forEach>
                </table>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倾城月光淡如水﹏ 2025-01-12 18:48:20

这是基本思想,

集合

List<String> fruits = new ArrayList<String>();
fruits.add("Apple");
fruits.add("Mango");
fruits.add("Grapes");

您在 JSP 上的

<c:forEach items="${fruits}" var="fruit" varStatus="status">
         <c:out value="${fruit}"/>
         <c:if test="${!status.last}">,</c:if>
</c:forEach>

Here is the basic idea,

Your collection

List<String> fruits = new ArrayList<String>();
fruits.add("Apple");
fruits.add("Mango");
fruits.add("Grapes");

On JSP

<c:forEach items="${fruits}" var="fruit" varStatus="status">
         <c:out value="${fruit}"/>
         <c:if test="${!status.last}">,</c:if>
</c:forEach>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文