Thanks, Thiago...but (how) can one use this in a page class?  

Looks like the method defaultLabel is not static, nor does the 
ComponentDefaultProviderImpl (an internal class) have a constructor, so cannot 
do either 


1.  ComponentDefaultProvider.defaultLabel(Resource 
side_question_what_would_this_be), or 

 
2.  @Inject
     private ComponentDefaultProvider labelGetter;

And even is that were (made) possible, there would be same question on Resource 
- how create that from variable name? 


Sounds like all the capability is there in the framework, just have to re-use 
it somehow...



On Monday, June 9, 2014 4:09 AM, Thiago H de Paula Figueiredo 
<thiag...@gmail.com> wrote:
 


On Mon, 09 Jun 2014 05:50:33 -0300, Net Dawg <net.d...@yahoo.com.invalid>  

wrote:

> Has anyone used org.apache.tapestry5.corelib.components.Label within  
> page class?  I looked at the code for Lable and see method like  
> beginRender, afterRender...nothing obvious...

Label doesn't have any logic for defining the rendered label. Actually, it  
takes it from the associated form field component (if (bodyIsBlank)  
writer.write(field.getLabel()); in afterRender()). AbstractField, the  
superclass of all Tapestry-provided form field components, has a label  
parameter. Its default value is defined by  
ComponentDefaultProvidoer.defaultLabel(), called inside  
AbstractField.defaultLabel(). So, in the end, here's the actual logic  
behind field labels:

     public String defaultLabel(ComponentResources resources)
     {
         Defense.notNull(resources, "resources");

         String componentId = resources.getId();
         String key = componentId + "-label";

         Messages containerMessages =  
resources.getContainerResources().getMessages();

         if (containerMessages.contains(key)) return  
containerMessages.get(key);

         return TapestryInternalUtils.toUserPresentable(componentId);
     }

Where the resources parameter is the ComponentResources instance of the  
field. Summary: it looks up an [field-id]-label message from the messages  
file. If found, it's used unchanged. Otherwise, it uses a method  
(TapestryInternalUtils.toUserPresentable()) to extract a good user-facing  
label from the field name, supposing it follows the Java standards for  
field names.

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

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

Reply via email to