Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

bean:write - format key

 
Matt Connors
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using bean:write in my jsp to output a date and it is not working. No matter what I do the Date gets output in the default Date.toString() format. If I remove the format key from the Application Resources file the behavior does not change. I verified that Struts (1.2) is using this Application Resources file by removing a bean:message an watching the application throw an exception.

Any idea what might be the problem?

JSP CODE

<td>
<bean:write name="DUTask" property="dueDate" formatKey="format.date"/>
</td>


APPLICATION RESOURCE FILE

format.date=yy/MM/dd
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Matt Connors:
I verified that Struts (1.2) is using this Application Resources file by removing a bean:message an watching the application throw an exception.


Do you mean that you removed the key from ApplicationResources that a particular bean:message was referencing?
 
Matt Connors
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is that I cannot get bean:write to format a Date object for me. No matter what I do the Date continues to get displayed in the default Date.toString() format.

My first idea was to prove the Application Resources file is being accessed. I did that by removing a format key for a bean:message and when I ran the application and an exception was thrown. So I proved that the Application Resources file is being used.

Unfortunately I still can't get bean:write to use a format key for my Date object.

Is there a specification somewhere that indicates what the valid format for a Date object format key is?

Any suggestions on how to further diagnose the problem?

Thanks,
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try <bean:message key="date.format"/> and see if your JSP prints out the yy/MM/dd

Struts uses Java's SimpleDataFormat, so yy/MM/dd is valid.
 
Matt Connors
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Marc. Your suggestion ultimately lead me to the answer.

The problem was that one of the developers had change the struts-config.xml file and gave the message resources file a key value. The <message-resources...> entry became :

<message-resources key="regMessages" parameter="com.csi.mos.ApplicationResources"/>

All I had to due was specify 'bundle="regMessages"' in my bean:write tag.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic