File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes bean:write - format key Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "bean:write - format key" Watch "bean:write - format key" New topic
Author

bean:write - format key

Matt Connors
Greenhorn

Joined: Sep 08, 2004
Posts: 23
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

Joined: Feb 05, 2003
Posts: 4727

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?


A good workman is known by his tools.
Matt Connors
Greenhorn

Joined: Sep 08, 2004
Posts: 23
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

Joined: Feb 05, 2003
Posts: 4727

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

Joined: Sep 08, 2004
Posts: 23
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.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: bean:write - format key
 
Similar Threads
why+beans+are+used?
Not getting contents of formbean's collection...
Javascript Calendar problem
using ajax and struts iterate tags
need to invoke EL expression.