You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by Néstor Boscán <ne...@tcs.com.ve> on 2005/07/16 01:30:45 UTC

RE: Newbie to Datagrid Taglib

Hi Kumar

The datagrid tag works with the JSTL expression language. The "items" and
"var" attributes works very much like the <c:for /> tag. In the "items"
attribute you pass the Collection or Iterator or Array[] that you want to
use in the datagrid. To do this you must put your object in the request,
page, application or session context of you page. After that you access your
object with the expression language ${name}. I'll give you an example:

<% ArrayList list;

   request.setAttribute ("myList", list); %>

<ui:dataGrid items="${myList}" ... >

So now that you have set your List you use the "var" attribute to tell the
datagrid the name of the variable that it will use to store each object in
the List in each iteration. 

<ui:dataGrid items="${myList}" var="myObject" >

Now you define your columns and define what you want to see in each column
with the <item /> element. You have to use the JSTL expression language to
access attributes, or key-values from your object. For example if myObject
has a firstName attribute you can use it like this:

<ui:dataGrid items="${myList}" var="myObject" >
  <columns>
    <column>
      <item value="${myObject.firstName}"/>
    </column>
  </columns>
</ui:dataGrid>

You can use the JSTL Expression Language to define concatenation or
arithmetic operations:

<ui:dataGrid items="${myList}" var="myObject" >
  <columns>
    <column>
      <item value="${myObject.firstName + ' ' + myObject.lastName}"/>
    </column>
  </columns>
</ui:dataGrid>

In the case where your values are Numbers or Dates you can format them.

<ui:dataGrid items="${myList}" var="myObject" >
  <columns>
    <column>
      <item value="${myObject.birthDate}" format="dd/MM/yy"/>
    </column>
  </columns>
</ui:dataGrid>

You can use the <header/>, <footer/> elements to define headers and footers
for your datagrid.

Hope this helps.

-----Mensaje original-----
De: Kumar Thirunavukarasu [mailto:kumar_thirunavukarasu@freddiemac.com] 
Enviado el: Friday, July 15, 2005 6:31 PM
Para: nestor.boscan@tcs.com.ve
Asunto: RE: Newbie to Datagrid Taglib

Mr.Nestor,

I got past this error but I need some documentation around how you are
mapping the bean object to datagrid tag.  It is not very clear in the docs
provided.  What is var attribute is doing in datagrid.  How the item element
works.  How to use the value attribute in Item element.

Any help in some kind of documentation will be helpful.  Right now my page
is building blank table and producing no data.

<%@page import="java.util.ArrayList" %>
<%@page import="com.freddiemac.pvs.ui.web.form.ParameterViewForm" %> <%@
page import="com.freddiemac.pvs.ui.web.form.Payup" %>


<%@ page info="BasicTemplate" %>
<%@ taglib uri="/WEB-INF/taglib/struts-html.tld" prefix="html" %> <%@ taglib
uri="/WEB-INF/taglib/struts-logic.tld" prefix="logic" %> <%@ taglib
uri="/WEB-INF/taglib/struts-tiles.tld" prefix="tiles" %> <%@ taglib
uri="/WEB-INF/taglib/taglibs-datagrid.tld" prefix="ui" %>



<html:html>
<head>
<html:base/>

</head>

<body>
<html:errors/>
<html:form action="/SystemParameterView">

<%!
   ArrayList payupList = new ArrayList();%>

<%
      payupList.add(new Payup("LLB","LLB PVS","Yes"));
      payupList.add(new Payup("LLB1","LLB PVS1","No"));
      request.setAttribute ("payupList", payupList); %>

<style>
     th a:link      { text-decoration: none; color: black }
     th a:visited   { text-decoration: none; color: black }
     .header1       { border: 1px solid black; border-right: none;
background-color: #EFEBDE; font-family: arial; font-size: 10pt;
font-weight: normal }
     .header2       { border: 1px solid black; background-color: #EFEBDE;
font-family: arial; font-size: 10pt; font-weight: normal }
     .footer1       { border: 1px solid black; border-right: none;
background-color: #EFEBDE; font-family: arial; font-size: 10pt }
     .footer2       { border: 1px solid black; background-color: #EFEBDE;
font-family: arial; font-size: 10pt }
     .item1         { border: 1px solid #EFEBDE; border-right: none;
border-bottom: none; background-color: white; font-family: arial;
font-size: 9pt }
     .item2         { border: 1px solid #EFEBDE; border-bottom: none;
background-color: white; font-family: arial; font-size: 9pt } </style> <%
out.println("TEST"); %> <ui:dataGrid items="${payupList}" var="payup"
name="PayupView"
cellPadding="1" cellSpacing="0">
  <columns>
    <column width="100" order="true">
      <header value="Code" hAlign="center" styleClass="header1"/>
      <item   value="${code}" hAlign="left" styleClass="item1"/>
      <footer value="Total ${total}" hAlign="left" styleClass="footer1"/>
    </column>
    <column width="200" order="true">
      <header value="Description" hAlign="center" styleClass="header1"/>
      <item   value="${desc}" hAlign="left" pattern="$#,##0.00"
styleClass="item1"/>
    </column>
    <column width="200" order="true">
      <header value="Active Flag" hAlign="center" styleClass="header2"/>
      <item   value="${activeFlag}" hAlign="left" pattern="$#,##0.00"
styleClass="item2"/>
    </column>
  </columns>
  <footer show="true"/>
  <order imgAsc="/images/up.gif" imgDesc="/images/down.gif"/> </ui:dataGrid>

</html:form>
</body>
</html:html>






                                                                           
                Kumar                                                      
             Thirunavukarasu/H                                             
             Q/FHLMC                                                    To 
                                       nestor.boscan@tcs.com.ve            
                07/15/2005                                              cc 
             12:38 PM                                                      
                                                                   Subject 
                                       RE: Newbie to Datagrid Taglib       
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           



I saw your explanation about datagrid.  I am trying to use this in my
project as well.  Where will I find some documentation about <ui:dataGrid
items="${payupList}" var="Payup" name="Pay-up View"
cellPadding="1" cellSpacing="0">  this particular element and attributes.

I could not find in jakarta.  I am getting the following error.

 

 

 

 

   in:../jsp/DataMaintenance/dataMaintSystemParamBody.jsp] Element type
"item" must be followed by either      
   attribute specifications, ">" or "/>".' javax.servlet.jsp.JspException:
Element type "item" must be         
   followed by either attribute specifications, ">" or "/>". at

   org.apache.taglibs.datagrid.DataGridTag.doAfterBody(DataGridTag.java:200)
at                                
 
jsp_servlet._jsp._datamaintenance.__datamaintsystemparambody._jspService(__d
atamaintsystemparambody.java:30 
   0) at weblogic.servlet.jsp.JspBase.service(JspBase.java:33) at

 
weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(Servle
tStubImpl.java:971) at          
 
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
:402) at                        
 
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
:446) at                        
 
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
:305) at                        
 
weblogic.servlet.internal.RequestDispatcherImpl.include(RequestDispatcherImp
l.java:607) at                  
 
weblogic.servlet.internal.RequestDispatcherImpl.include(RequestDispatcherImp
l.java:400) at                  
   weblogic.servlet.jsp.PageContextImpl.include(PageContextImpl.java:154) at

   org.apache.struts.tiles.TilesUtilImpl.doInclude(TilesUtilImpl.java:137)
at                                  
   org.apache.struts.tiles.TilesUtil.doInclude(TilesUtil.java:177) at

   org.apache.struts.taglib.tiles.InsertTag.doInclude(InsertTag.java:756) at

 
org.apache.struts.taglib.tiles.InsertTag$InsertHandler.doEndTag(InsertTag.ja
va:881) at                      
   org.apache.struts.taglib.tiles.InsertTag.doEndTag(InsertTag.java:473) at

   jsp_servlet._jsp.__basictemplate._jspService(__basictemplate.java:237) at

   weblogic.servlet.jsp.JspBase.service(JspBase.java:33) at

 
weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(Servle
tStubImpl.java:971) at          
 
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
:402) at                        
 
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
:446) at                        
 
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
:305) at                        
 
weblogic.servlet.internal.RequestDispatcherImpl.include(RequestDispatcherImp
l.java:607) at                  
 
weblogic.servlet.internal.RequestDispatcherImpl.include(RequestDispatcherImp
l.java:400) at                  
   weblogic.servlet.jsp.PageContextImpl.include(PageContextImpl.java:154) at

   org.apache.struts.tiles.TilesUtilImpl.doInclude(TilesUtilImpl.java:137)
at                                  
   org.apache.struts.tiles.TilesUtil.doInclude(TilesUtil.java:177) at

   org.apache.struts.taglib.tiles.InsertTag.doInclude(InsertTag.java:756) at

 
org.apache.struts.taglib.tiles.InsertTag$InsertHandler.doEndTag(InsertTag.ja
va:881) at                      
   org.apache.struts.taglib.tiles.InsertTag.doEndTag(InsertTag.java:473) at

 
jsp_servlet._jsp._datamaintenance.__datamaintsystemparammain._jspService(__d
atamaintsystemparammain.java:23 
   9) at weblogic.servlet.jsp.JspBase.service(JspBase.java:33) at

 
weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(Servle
tStubImpl.java:971) at          
 
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
:402) at                        
 
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
:446) at                        
 
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
:305) at                        
 
weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImp
l.java:301) at                  
 
org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:10
69) at                          
 
org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcesso
r.java:274) at                  
 
org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProces
sor.java:455) at                
 
org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequ
estProcessor.java:320) at       
 
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:279)
at                             
   org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at                                  
   org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525) at

   javax.servlet.http.HttpServlet.service(HttpServlet.java:760) at

   javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at

 
weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(Servle
tStubImpl.java:971) at          
 
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
:402) at                        
 
weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
:305) at                        
 
weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(W
ebAppServletContext.java:6350)  
   at
weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubjec
t.java:317) at               
   weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
at                                
 
weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletCo
ntext.java:3635) at             
 
weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java
:2585) at                       
   weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197) at

   weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)

 

 

 








---------------------------------------------------------------------
To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: taglibs-user-help@jakarta.apache.org