?
Solved

bean.write date format

Posted on 2006-07-19
12
Medium Priority
?
1,702 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
12 Comments
 
LVL 92

Expert Comment

by:objects
ID: 17142436
try something like:

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

Expert Comment

by:girionis
ID: 17144275
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
ID: 17144276
typo

<bean:write name='browseall' property='value(date_created)' formatKey="my.own.format.key" />
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:su_harvie
ID: 17147003
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
ID: 17147049
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
 
LVL 35

Expert Comment

by:girionis
ID: 17152001
>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
ID: 17161117
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
ID: 17170806
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
ID: 17192884
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
ID: 17192914
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
ID: 17395716
PAQed with points refunded (500)

CetusMOD
Community Support Moderator
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month13 days, 12 hours left to enroll

800 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