JSTL 需要一个逗号分隔的数组来在 JSP 上显示数据
又是我。我从 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 <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>
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
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是基本思想,
集合
您在 JSP 上的
Here is the basic idea,
Your collection
On JSP