Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dynamic Column List?

 
Edward Durai
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I saw this example in displaytag website. It's Working Good. I have doubt, How to fetch the xml values and using displaytags i want to sort and pagination.

my xml like
<shipinfo>
<shipname> Naoo </shipname>
<shipcode> Naoo001 </shipcode>
</shipinfo>

<shipinfo>
<shipname> Titanic </shipname>
<shipcode> Tit001 </shipcode>
</shipinfo>

My expected output is
both records mentioned in the xml file should be displayed and also sorting and pagination also working.

Please give me some Idea.

<%@ taglib uri="http://displaytag.sf.net" prefix="display"%>
<%@ page import="java.util.*"%>
<%List testData = new ArrayList();

Map map1 = new TreeMap();
map1.put("shipname", "Noaa");
map1.put("shipcode", "No001");
testData.add(map1);

Map map2 = new TreeMap();
map2.put("shipname", "Arab Ship");
map2.put("shipcode", "ARAB001");
testData.add(map2);

session.setAttribute("test", testData);

%>
<jsp:scriptlet> request.setAttribute( "testData", testData ); </jsp:scriptlet>

<display:table name="testData" id="test">
<display:column title="Ship Name" property="shipname" sortable="true" />
<display:column title="Ship Code" property="shipcode" sortable="true" />

</display:table>
 
Edward Durai
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
anybody answer the above question please?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65220
95
IntelliJ IDE Java jQuery Mac Mac OS X
 
Richard Green
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. create a servlet to parse your xml file and to put the elements in a list. Put this list in a request attribute and use RequestDespatcher to forward the view to your jsp page

2. In your jsp page. use the display tags to generate the table
 
Edward Durai
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could You give me the sample code or link. It's more helpful for me.

Thanks
 
Richard Green
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
.....
....
List<ShipInfo> ships = getShipInfoFromXMLFile("blah.xml");
String url="/jsp/yourPage.jsp";
ServletContext sc = getServletContext();
RequestDispatcher rd = sc.getRequestDispatcher(url);
req.setAttribute("ships",ships);
rd.forward(req, res);
 
Bk Jacky
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
here is the sample code for xml parsing .Modify it if require






("Nothing is impossible in this world")
Bhupinder Singh
SCJP1.4
Preparing SCWCD

[ August 01, 2006: Message edited by: Bhupinder Singh ]

[ August 01, 2006: Message edited by: Bhupinder Singh ]
[ August 01, 2006: Message edited by: Ben Souther ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bhupinder Singh,

Javaranch tip:
If you are going to post more than a line or two of your code, wrap that
code in a set of UBB Code tags.
Doing so will help to preserve your code's indenting, making it easier to read.
If it is easier to read, more people will actaully read it and you will
stand a better chance of getting help with your question.
See UseCodeTags for more
help with UBB code tags.

I've added them to your last post.
 
Edward Durai
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
.java file contains
====================

Query query = session.createQuery("select af.id,af.shipname,af.shipcode from Auditfinding af ");
usrlist=query.list();
===============================
.jsp page
===============================


java.util.List testData = auditfindingCtrl.getAuditFindings4();
session.setAttribute("test", testData);
<display:table list="<%=testData%>" >
</display:table>

My output is like(USing display tags)
==================

4 items found, displaying 1 to 2.[First/Prev] 1, 2 [Next/Last]
[Ljava.lang.Object;@27538
[Ljava.lang.Object;@15dc721

Why the record is display like this. ANy query problem?

If i use
Query query = session.createQuery("from Auditfinding af ");

This query is working good in displaytags. And i got Good result.

How to solve the above problem?

Second question.

if i put
<display:column title="id" property="id" sortable="true" />
in between <display:table>, i got error like

Exception: [.LookupUtil] Error looking up property "id" in object type "[Ljava.lang.Object;". Cause: Unknown property 'id'

Thanks
A.edward durai





 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic