You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Andreas Bulling <sp...@phoenix.hadiko.de> on 2006/03/18 18:23:39 UTC

Access localized messages in non-page/non-component class

Hi all,

just a short question after having tried to use several "infrastructure"
injections without success so far:

I have a class called "ModelSource" which returns several IPropertySelection
models to be used in forms. One of these is a userModel which shall
contain _localized_ entries defined in the application.properties file.
The problem is: How can I access these localized entries in the
non-page/non-component class "ModelSource"?
getMessages().getMessage("user_type_0") doesnt work for sure :(

Thanks!
  Andreas

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


Re: Access localized messages in non-page/non-component class

Posted by Andreas Bulling <sp...@phoenix.hadiko.de>.
|   <binding name="model" value="modelSource.getUserModel(messages)"/>

It works, now. I didn't see the "get" in front of UserModel,
sorry for not reading your post as carefully as needed ;)

Thanks for your help!
  Andreas

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


Re: Access localized messages in non-page/non-component class

Posted by Andreas Bulling <sp...@phoenix.hadiko.de>.
On 22. Mär 2006 - 01:12:03, Kent Tong wrote:
| Everything ognl expression has a "context object". For example, if you
| write "modelSource" in your .page file, the context object is the
| page object so "modelSource" means calling getModelSource() on the
| page object. To access this context object in the ognl expression,
| use "#root".
| 
| This mechanism is provided by ognl. The actual page object is of
| course provided by tapestry.

Thanks for this clarification/explanation! ;)

Andreas

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


Re: Access localized messages in non-page/non-component class

Posted by Kent Tong <ke...@cpttm.org.mo>.
Andreas Bulling <spam <at> phoenix.hadiko.de> writes:

> | http://www.ognl.org/2.6.7/Documentation/html/LanguageGuide/varref.html
> 
> OK, and #root is provied by Tapestry?

Everything ognl expression has a "context object". For example, if you
write "modelSource" in your .page file, the context object is the
page object so "modelSource" means calling getModelSource() on the
page object. To access this context object in the ognl expression,
use "#root".

This mechanism is provided by ognl. The actual page object is of
course provided by tapestry.

--
Author of a book for learning Tapestry (www.agileskills2.org/EWDT)


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


Re: Access localized messages in non-page/non-component class

Posted by Andreas Bulling <sp...@phoenix.hadiko.de>.
| http://www.ognl.org/2.6.7/Documentation/html/LanguageGuide/varref.html

OK, and #root is provied by Tapestry?

| Probably you don't have the getter or setter. Anyway, why not just 
| pass the Messages collection to ModelSource?
| 
|   <binding name="model" value="modelSource.getUserModel(messages)"/>
| 
|   IPropertySelectionModel getUserModel(Messages messages) {
|     ...
|   }

Well, I both had the setter/getter methods...
But anyway this doesn't work either :(

---
Unable to read OGNL expression '<parsed OGNL expression>'
of $Register_21@a49259[Register]: Method "userModel" failed for
object <OuterProxy for plattform.ModelSource(plattform.services.ModelSource)>
---

Do I have to add something to hivemodule.xml to make this work?

Sincerly,
  Andreas

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


Re: Access localized messages in non-page/non-component class

Posted by Kent Tong <ke...@cpttm.org.mo>.
Andreas Bulling <spam <at> phoenix.hadiko.de> writes:

> Well, what's the magic behind this [#root] thing/where can I find
> a reference mentioning it? 

http://www.ognl.org/2.6.7/Documentation/html/LanguageGuide/varref.html

> I tried that but I get the error message:
> 
> Unable to read OGNL expression '<parsed OGNL expression>' of $Register_50 <at>
183bd71[Register]: $ModelSource_10a1d12b405.userModel

Probably you don't have the getter or setter. Anyway, why not just 
pass the Messages collection to ModelSource?

  <binding name="model" value="modelSource.getUserModel(messages)"/>

  IPropertySelectionModel getUserModel(Messages messages) {
    ...
  }

--
Author of a book for learning Tapestry (http://www.agileskills2.org/EWDT)


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


Re: Access localized messages in non-page/non-component class

Posted by Andreas Bulling <sp...@phoenix.hadiko.de>.
| Try:
| 
|      <binding name="model" value="modelSource.userModel[#root]"/>
| 
| where #root means your page object. Make sure you have both getter and
| setter for the userModel.

Well, what's the magic behind this [#root] thing/where can I find
a reference mentioning it? I tried that but I get the error
message:

Unable to read OGNL expression '<parsed OGNL expression>' of $Register_50@183bd71[Register]: $ModelSource_10a1d12b405.userModel

Sincerly,
  Andreas

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


Re: Access localized messages in non-page/non-component class

Posted by Kent Tong <ke...@cpttm.org.mo>.
Andreas Bulling <spam <at> phoenix.hadiko.de> writes:

> Well, but the problem is, that the propertySelectionModel is
> referenced directly in the .page file like this:
> 
> <component id="inputType" type="PropertySelection">
> 	<binding name="value" value="attributes.userType"/>
>         <binding name="model" value="modelSource.userModel"/>
> </component>

Try:

     <binding name="model" value="modelSource.userModel[#root]"/>

where #root means your page object. Make sure you have both getter and
setter for the userModel.

--
Author of a book for learning Tapestry (www.agileskills2.org/EWDT)


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


Re: Access localized messages in non-page/non-component class

Posted by Andreas Bulling <sp...@phoenix.hadiko.de>.
Hi Kent,

thanks for your answer!
 
| I think the best way is to pass the component to it when you need
| to get a userModel:
| 
| class ModelSource {
|   IPropertySelectionModel getUserModel(IComponent component) {
|      ...
|      component.getMessages().getMessage("user_type_0");
|      ...
|   }
| }

Well, but the problem is, that the propertySelectionModel is
referenced directly in the .page file like this:

<component id="inputType" type="PropertySelection">
	<binding name="value" value="attributes.userType"/>
        <binding name="model" value="modelSource.userModel"/>
</component>

modelSource in injected with the annotation

@InjectObject("service:plattform.ModelSource")
public abstract ModelSource getModelSource();

How can I pass the component to the getUserModel()
method in this case?

Sncerly,
  Andreas

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


Re: Access localized messages in non-page/non-component class

Posted by Kent Tong <ke...@cpttm.org.mo>.
Andreas Bulling <spam <at> phoenix.hadiko.de> writes:

> I have a class called "ModelSource" which returns several IPropertySelection
> models to be used in forms. One of these is a userModel which shall
> contain _localized_ entries defined in the application.properties file.
> The problem is: How can I access these localized entries in the
> non-page/non-component class "ModelSource"?
> getMessages().getMessage("user_type_0") doesnt work for sure :(

I think the best way is to pass the component to it when you need
to get a userModel:

class ModelSource {
  IPropertySelectionModel getUserModel(IComponent component) {
     ...
     component.getMessages().getMessage("user_type_0");
     ...
  }
}

--
Author of a book for learning Tapestry (www.agileskills2.org/EWDT)


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