You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Adam Zimowski <zi...@gmail.com> on 2007/07/09 22:54:28 UTC

T5: How to retrieve message from default Errors.properties

Hi,

In my page class I'd like to retrieve the original value for
default-banner ("You must correct the following errors before you may
continue.") which is stored in Errors.properties in tapestry-core.jar.
I'd like to have this String accessible to my page class as a
property. Is there a field annotation for this or should I just use
standard property file read mechanism to get at that?

Thanks

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: T5: How to retrieve message from default Errors.properties

Posted by Donyee <xy...@gmail.com>.
@Inject
private Messages _errorMessages;
Try this!

2007/7/11, Adam Zimowski <zi...@gmail.com>:
> Thanks, but I've seen that. It's not what I've been trying to do.
> Rather than overriding the message I simply want my application to
> read Errors.properties just like tapestry does it.
>
> On 7/11/07, Donyee <xy...@gmail.com> wrote:
> > You can find it here!
> > http://wiki.apache.org/tapestry/Tapestry5HowToOverrideTheDefaultErrorMessageBanner
> >
> > 2007/7/11, Adam Zimowski <zi...@gmail.com>:
> > > Okay, I still don't know a "Tap5" way of doing this, so this works,
> > > although that's an ugly hack:
> > >
> > > Template:
> > >
> > > <t:errors banner="banner"/>
> > >
> > > Page Class:
> > >
> > > public String getBanner() {
> > >         if(_unknownError) {
> > >                 return "Unknown Error";
> > >         }
> > >         else {
> > >                 return getDefaultBanner();
> > >         }
> > > }
> > >
> > > private String getDefaultBanner() {
> > >         try {
> > >                 Properties props = new Properties();
> > >                 InputStream in =
> > > getClass().getResourceAsStream("/org/apache/tapestry/corelib/components/Errors.properties");
> > >                 props.load(in);
> > >                 String banner = props.getProperty("default-banner");
> > >                 in.close();
> > >                 return banner;
> > >         }
> > >         catch(Exception e) {
> > >                 return e.getMessage();
> > >         }
> > > }
> > >
> > > However, wouldn't this be much simpler? (It doesn't work though).
> > >
> > > @Inject
> > > @Path("classpath:org/apache/tapestry/corelib/components/Errors.properties")
> > > private Messages _errorMessages;
> > >
> > > public String getBanner() {
> > >         if(_unknownError) {
> > >                 return "Unknown Error";
> > >         }
> > >         else {
> > >                 return _errorMessages.get("default-banner");
> > >         }
> > > }
> > >
> > > I know that documentation for @Path annotation states it can only be
> > > used in conjunction with Assets. But wouldn't this be a good case as
> > > well? What am I missing?
> > >
> > > On 7/9/07, Adam Zimowski <zi...@gmail.com> wrote:
> > > > Hi,
> > > >
> > > > In my page class I'd like to retrieve the original value for
> > > > default-banner ("You must correct the following errors before you may
> > > > continue.") which is stored in Errors.properties in tapestry-core.jar.
> > > > I'd like to have this String accessible to my page class as a
> > > > property. Is there a field annotation for this or should I just use
> > > > standard property file read mechanism to get at that?
> > > >
> > > > Thanks
> > > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > > For additional commands, e-mail: users-help@tapestry.apache.org
> > >
> > >
> >
> >
> > --
> > ----徐 依伟
> >
>


-- 
----徐 依伟

Re: T5: How to retrieve message from default Errors.properties

Posted by Adam Zimowski <zi...@gmail.com>.
Thanks, but I've seen that. It's not what I've been trying to do.
Rather than overriding the message I simply want my application to
read Errors.properties just like tapestry does it.

On 7/11/07, Donyee <xy...@gmail.com> wrote:
> You can find it here!
> http://wiki.apache.org/tapestry/Tapestry5HowToOverrideTheDefaultErrorMessageBanner
>
> 2007/7/11, Adam Zimowski <zi...@gmail.com>:
> > Okay, I still don't know a "Tap5" way of doing this, so this works,
> > although that's an ugly hack:
> >
> > Template:
> >
> > <t:errors banner="banner"/>
> >
> > Page Class:
> >
> > public String getBanner() {
> >         if(_unknownError) {
> >                 return "Unknown Error";
> >         }
> >         else {
> >                 return getDefaultBanner();
> >         }
> > }
> >
> > private String getDefaultBanner() {
> >         try {
> >                 Properties props = new Properties();
> >                 InputStream in =
> > getClass().getResourceAsStream("/org/apache/tapestry/corelib/components/Errors.properties");
> >                 props.load(in);
> >                 String banner = props.getProperty("default-banner");
> >                 in.close();
> >                 return banner;
> >         }
> >         catch(Exception e) {
> >                 return e.getMessage();
> >         }
> > }
> >
> > However, wouldn't this be much simpler? (It doesn't work though).
> >
> > @Inject
> > @Path("classpath:org/apache/tapestry/corelib/components/Errors.properties")
> > private Messages _errorMessages;
> >
> > public String getBanner() {
> >         if(_unknownError) {
> >                 return "Unknown Error";
> >         }
> >         else {
> >                 return _errorMessages.get("default-banner");
> >         }
> > }
> >
> > I know that documentation for @Path annotation states it can only be
> > used in conjunction with Assets. But wouldn't this be a good case as
> > well? What am I missing?
> >
> > On 7/9/07, Adam Zimowski <zi...@gmail.com> wrote:
> > > Hi,
> > >
> > > In my page class I'd like to retrieve the original value for
> > > default-banner ("You must correct the following errors before you may
> > > continue.") which is stored in Errors.properties in tapestry-core.jar.
> > > I'd like to have this String accessible to my page class as a
> > > property. Is there a field annotation for this or should I just use
> > > standard property file read mechanism to get at that?
> > >
> > > Thanks
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
>
>
> --
> ----徐 依伟
>

Re: T5: How to retrieve message from default Errors.properties

Posted by Donyee <xy...@gmail.com>.
You can find it here!
http://wiki.apache.org/tapestry/Tapestry5HowToOverrideTheDefaultErrorMessageBanner

2007/7/11, Adam Zimowski <zi...@gmail.com>:
> Okay, I still don't know a "Tap5" way of doing this, so this works,
> although that's an ugly hack:
>
> Template:
>
> <t:errors banner="banner"/>
>
> Page Class:
>
> public String getBanner() {
>         if(_unknownError) {
>                 return "Unknown Error";
>         }
>         else {
>                 return getDefaultBanner();
>         }
> }
>
> private String getDefaultBanner() {
>         try {
>                 Properties props = new Properties();
>                 InputStream in =
> getClass().getResourceAsStream("/org/apache/tapestry/corelib/components/Errors.properties");
>                 props.load(in);
>                 String banner = props.getProperty("default-banner");
>                 in.close();
>                 return banner;
>         }
>         catch(Exception e) {
>                 return e.getMessage();
>         }
> }
>
> However, wouldn't this be much simpler? (It doesn't work though).
>
> @Inject
> @Path("classpath:org/apache/tapestry/corelib/components/Errors.properties")
> private Messages _errorMessages;
>
> public String getBanner() {
>         if(_unknownError) {
>                 return "Unknown Error";
>         }
>         else {
>                 return _errorMessages.get("default-banner");
>         }
> }
>
> I know that documentation for @Path annotation states it can only be
> used in conjunction with Assets. But wouldn't this be a good case as
> well? What am I missing?
>
> On 7/9/07, Adam Zimowski <zi...@gmail.com> wrote:
> > Hi,
> >
> > In my page class I'd like to retrieve the original value for
> > default-banner ("You must correct the following errors before you may
> > continue.") which is stored in Errors.properties in tapestry-core.jar.
> > I'd like to have this String accessible to my page class as a
> > property. Is there a field annotation for this or should I just use
> > standard property file read mechanism to get at that?
> >
> > Thanks
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
----徐 依伟

Re: T5: How to retrieve message from default Errors.properties

Posted by Adam Zimowski <zi...@gmail.com>.
Okay, I still don't know a "Tap5" way of doing this, so this works,
although that's an ugly hack:

Template:

<t:errors banner="banner"/>

Page Class:

public String getBanner() {
	if(_unknownError) {
		return "Unknown Error";
	}
	else {
		return getDefaultBanner();
	}
}

private String getDefaultBanner() {
	try {
		Properties props = new Properties();
		InputStream in =
getClass().getResourceAsStream("/org/apache/tapestry/corelib/components/Errors.properties");
		props.load(in);
		String banner = props.getProperty("default-banner");
		in.close();
		return banner;
	}
	catch(Exception e) {
		return e.getMessage();
	}
}

However, wouldn't this be much simpler? (It doesn't work though).

@Inject
@Path("classpath:org/apache/tapestry/corelib/components/Errors.properties")
private Messages _errorMessages;

public String getBanner() {
	if(_unknownError) {
		return "Unknown Error";
	}
	else {
		return _errorMessages.get("default-banner");
	}
}

I know that documentation for @Path annotation states it can only be
used in conjunction with Assets. But wouldn't this be a good case as
well? What am I missing?

On 7/9/07, Adam Zimowski <zi...@gmail.com> wrote:
> Hi,
>
> In my page class I'd like to retrieve the original value for
> default-banner ("You must correct the following errors before you may
> continue.") which is stored in Errors.properties in tapestry-core.jar.
> I'd like to have this String accessible to my page class as a
> property. Is there a field annotation for this or should I just use
> standard property file read mechanism to get at that?
>
> Thanks
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org