bean.write date format

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.






su_harvieAsked:
Who is Participating?
 
CetusMODConnect With a Mentor Commented:
PAQed with points refunded (500)

CetusMOD
Community Support Moderator
0
 
objectsCommented:
try something like:

<bean:write name='browseall' property='value(date_created)' filter='false' format="MMM dd, 'yy"/>
0
 
girionisCommented:
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
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
girionisCommented:
typo

<bean:write name='browseall' property='value(date_created)' formatKey="my.own.format.key" />
0
 
su_harvieAuthor Commented:
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
 
su_harvieAuthor Commented:
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
 
girionisCommented:
>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
 
su_harvieAuthor Commented:
Yes the key was in application resulrce properties file and is accessible beacuse other properties on same page are.
0
 
su_harvieAuthor Commented:
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
 
su_harvieAuthor Commented:
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
 
su_harvieAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.