Solved

bean.write date format

Posted on 2006-07-19
12
1,593 Views
Last Modified: 2008-01-09
I have a Model class which fetches all the records in Arraylist.
Then I have jsp file with this iteration

<logic:iterate id='browseall' name='posts'>

I set the arraylist to this post iteration.Like this

HListModel pRec= new HListModel(conn);
            ArrayList post_Hash = (ArrayList)pRec.getRecordsForPost();
            request.setAttribute("posts", post_Hash);

Displaying is jsp at present like this

<bean:write name='browseall' property='value(date_created)' filter='false' /></td>
displays 2006-07-19 07:56:56



The date saved as timestamp in the datamodel 2006-07-19 07:56:56

I want to display date in my JSP like Jul 19, '06.

How this could be done. Some code will be appriciated.

Thanks.






0
Comment
Question by:su_harvie
12 Comments
 
LVL 92

Expert Comment

by:objects
Comment Utility
try something like:

<bean:write name='browseall' property='value(date_created)' filter='false' format="MMM dd, 'yy"/>
0
 
LVL 35

Expert Comment

by:girionis
Comment Utility
You can use a formatKey, like

<bean:write name="topic" property='value(date_created)' formatKey="my.own.format.key" />

and in your resourcebundle have something like:

my.own.format.key = MMM dd, 'yy
0
 
LVL 35

Expert Comment

by:girionis
Comment Utility
typo

<bean:write name='browseall' property='value(date_created)' formatKey="my.own.format.key" />
0
 

Author Comment

by:su_harvie
Comment Utility
This does not work for me.

I put this line in jsp
<bean:write name='browseall' property='value(date_created)' filter='false' formatKey="hl.own.format.key"/>

Then defined hl.own.format.key =MMM dd, 'yy

But no change?

Help.
0
 

Author Comment

by:su_harvie
Comment Utility
Another question I have to iterate twice:

Say one the main category and all post into it:

So the main category shows in big and bold:

then all post of that category under that.


Like
        Category1:
                          Item1
                          Item 2
                             so on........
        Category2
                       item 1
                       item2
                       so on.

How to achive this result.


i have this code:

<tiles:put name="content" direct="true" >
<table cellspacing="0" cellpadding="0" border="0">
<!-- Links to category headers -->
      <tr><td colspan="2">
      <logic:iterate id='category' name='posts'>
            <nobr><a href="#category-<bean:write name="category" property="value(cat_id)"/>">
                  <bean:write name="category" property="value(category_name)"/></a></nobr>
                  </td></tr>
                  <logic:iterate id='browseall' name='posts'>
            
                  <tr>
                        <td width="100">
                        <bean:write name='browseall' property='value(date_created)' filter='false' formatKey="hl.own.format.key"/></td>
                        <td width="100"><strong><bean:write name='browseall' property='value(price)' filter='false' /></strong></td>
                        <td width="250"><a href="HL_View_Item.jsp?<bean:write name='browseall' property='value(post_id)' filter='false' />"><bean:write name='browseall' property='value(title)' filter='false' /></a></td>
                  </tr>
                        
            </logic:iterate>
      </logic:iterate>
      </table>
      </tiles:put>

but result is like this:
Housing
Housing  
Sale
Sale
Sale
2006-07-15 04:40:03 12.0 'titleLOCATION'
2006-07-10 12:56:30 193.25 Comic Books
2006-07-10 12:54:16 193.25 Mahogany Dining table - $200
2006-07-10 12:53:05 193.25 Full living room set.
2006-07-10 12:49:02 93.25 1993 Polaris
2006-08-05 16:58:02 10.0 'Personality Im provement Good books'
2006-08-05 16:33:34 10.0 'Personality Im provement Good books'
2006-08-02 20:15:26 0.0 'Stome - pebble'
2006-07-23 12:04:55 0.0 'FREE WASHER (walnut creek)'
2006-07-19 08:57:25 0.0 'FREE WASHER (walnut creek)'
2006-07-10 13:25:45 12.4 FUTON
2006-07-19 08:30:16 1200.0 'tRY TO ENTER MORE THAN 60 CHARACTERS'
2006-07-15 04:55:06 123.0 'titleL of the post is not known at this time, but i will fig'


         How to correct this?
         

0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 35

Expert Comment

by:girionis
Comment Utility
>Then defined hl.own.format.key =MMM dd, 'yy
>
>But no change?

Where do you have your key? In a ResourceBundle? Are you sure you have access to it? If you have access it should work.
0
 

Author Comment

by:su_harvie
Comment Utility
Yes the key was in application resulrce properties file and is accessible beacuse other properties on same page are.
0
 

Author Comment

by:su_harvie
Comment Utility
Now I am doing somthing like this but still not working?

Action class:

ArrayList post_Hash1 = (ArrayList)pRec1.getRecordsForPost(sql1.toString()); //GETTING RECORDS
            String dt_to_display=null;
            Iterator i = post_Hash1.iterator();

while (i.hasNext()) {
                  //for(int x=0;x<i.next();x++){
                  GenericFormBean gb = (GenericFormBean)i.next();
                  System.out.println(gb.getValue("DATE_CREATED"));
                  dt_to_display = pRec1.formatDate(gb.getValue("DATE_CREATED").toString());
                  System.out.println(dt_to_display);
              }
            
             request.setAttribute("posts", post_Hash1);
             request.setAttribute("posts.date_created", dt_to_display);

Value from database:  2006-07-15 04:55:06
replaced to this for formattiing: 2006/07/15 04:55:06

Above code is displaying:
 2006/07/15 04:55:06
Mon, Jan 7, '15 (SEE WRONG VALUE FOR MONTH BEACUSE OF 07)

request.setAttribute("posts.date_created", dt_to_display);
this method not setting any value for in jsp file in right format

<bean:write name='browseall2' property="value(date_created)" filter='true' />

it displays 2006-07-15 04:55:06

How i force the format on display to this date?

Please help?



0
 

Author Comment

by:su_harvie
Comment Utility
Hi experts Now the query is genrating right form to display but not diplaying it:

What could be the error:

Here is query and other code:

select HLPOST.POST_ID, HLPOST.CAT_ID,HLPOST.TITLE,HLPOST.PRICE,to_char(HLPOST.DATE_CREATED,'Dy Mon DD, ''YY'),CATEGORY.CATEGORY_NAME from HARVIELIST.HLPOST, HARVIELIST.CATEGORY where HLPOST.cat_id = CATEGORY.cat_id order by CATEGORY.category_name, HLPOST.date_created  desc

Giving date in right format
Mon Jul 10, '06

Display code:
<logic:present name="posts">
<logic:iterate id='browseall2' name='posts'>
<bean:write name='browseall2' property="value(date_created)" />

Code for setting collection values to request

StringBuffer sql1 = new StringBuffer().append("select HLPOST.POST_ID, HLPOST.CAT_ID,HLPOST.TITLE,");
            sql1.append("HLPOST.PRICE,to_char(HLPOST.DATE_CREATED,'Dy Mon DD, ''YY'),CATEGORY.CATEGORY_NAME ");
            sql1.append("from HARVIELIST.HLPOST, HARVIELIST.CATEGORY ");
            sql1.append("where HLPOST.cat_id = CATEGORY.cat_id ");
            sql1.append("order by CATEGORY.category_name, HLPOST.date_created  desc");
            ArrayList post_Hash1 = (ArrayList)pRec1.getRecordsForPost(sql1.toString());
            request.setAttribute("posts", post_Hash1);

please guide

0
 

Author Comment

by:su_harvie
Comment Utility
Got it:

the query should be:

StringBuffer sql1 = new StringBuffer().append("select HLPOST.POST_ID, HLPOST.CAT_ID,HLPOST.TITLE,");
            sql1.append("HLPOST.PRICE,to_char(HLPOST.DATE_CREATED,'Dy Mon DD, ''YY') date_created ,CATEGORY.CATEGORY_NAME ");
            sql1.append("from HARVIELIST.HLPOST, HARVIELIST.CATEGORY ");
            sql1.append("where HLPOST.cat_id = CATEGORY.cat_id ");
            sql1.append("order by CATEGORY.category_name, HLPOST.date_created  desc");

using alias:
0
 

Accepted Solution

by:
CetusMOD earned 0 total points
Comment Utility
PAQed with points refunded (500)

CetusMOD
Community Support Moderator
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This video teaches viewers about errors in exception handling.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now