You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Chris Merrill <ch...@webperformance.com> on 2010/08/23 05:15:05 UTC

implementing a custom resource loader

I need to implement our own resource loader in order to re-use our existing
infrastructure for resolving localized strings.  I've implemented IStringResourceLoader
and have that working, but I've found I need a bit of a hack to get it to do what
I need.

In two scenarios:
  <wicket:message key="Merge_Customers"/>
and
  new Button("submit_button", new StringResourceModel("Move_License", this, null))...
the resource is requested in my IStringResourceLoader.loadStringResource() by the specified
names ("Merge_Customers" and "Move_License").  This is exactly what I expected and is working
great.

However, in another area where I specify the resource in the onValidate() method of a
StringValidtor, like this:
     error(stringIValidatable, "CustomerNameNotFound");
IStringResourceLoader.loadStringResource() is called with
  name="target_customer_name.CustomerNameNotFound"
instead of
  name="CustomerNameNotFound"
(where "target_customer_name" is the name of the field).


Is this the intended behavior?

If yes, how do I know when Wicket will be adding something to the resource key I specify
and when it will not?  We want to specify a resource key in source or markup and have the
resource requested using that exact key.

TIA!
Chris



-- 
------------------------------------------------------------------------ -
Chris Merrill                           |  Web Performance, Inc.
chris@webperformance.com                |  http://webperformance.com
919-433-1762                            |  919-845-7601

Web Performance: Website Load Testing Software & Services
------------------------------------------------------------------------ -

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


Re: implementing a custom resource loader

Posted by Chris Merrill <ch...@webperformance.com>.
On 8/23/2010 1:32 PM, Igor Vaynberg wrote:
> wicket will already handle the logging and missing resources, see
> iresourcesettings#setThrowExceptionOnMissingResource(false)

Beautiful!  That is just what I needed.  I should have guessed that Wicket
already had this covered.


Thanks!
Chris


p.s. have I mentioned how much I LOVE WICKET ??   :>

-- 
------------------------------------------------------------------------ -
Chris Merrill                           |  Web Performance, Inc.
chris@webperformance.com                |  http://webperformance.com
919-433-1762                            |  919-845-7601

Web Performance: Website Load Testing Software & Services
------------------------------------------------------------------------ -

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


Re: implementing a custom resource loader

Posted by Igor Vaynberg <ig...@gmail.com>.
wicket will already handle the logging and missing resources, see
iresourcesettings#setThrowExceptionOnMissingResource(false)

-igor

On Mon, Aug 23, 2010 at 10:28 AM, Chris Merrill
<ch...@webperformance.com> wrote:
> On 8/23/2010 12:59 PM, Igor Vaynberg wrote:
>> and the CustomerNameNotFound is never tried? it should be tried after
>> the <formid>.CustomerNameNotFound key
>
> Yes, it does!
>
> I violated one of the rules of IResourceLoader - I didn't return null if
> something was not found.  I wrapped our existing framework, which returns a
> version of the key, such as "##string-key##", and logs the missing key.
>
> Once I changed my code to check the existence of the key and return null, it
> eventually did ask by expected key name.
>
>
> Two of the reasons our framework always returns something useful is to (1)
> prevent catastrophic NPEs and (2) get a list of missing resources in our
> diagnostic logs.  It looks like Wicket already handles missing resources
> by providing the last key it tried, so I don't think #1 is needed in
> the context of our new app.  But #2 would still be nice.
>
> I'm currently adding our resource loader in app.init():
>  getResourceSettings().addStringResourceLoader(0, new MyResourceLoader());
> under the assumption that I want my resource loader to be first in the
> chain.
>
> If I want to get missing resources in a log file, would I instead do something
> like this:
>  getResourceSettings().addStringResourceLoader(0, new MyResourceLoader());
>  getResourceSettings().addStringResourceLoader(new MyLoggingResourceLoader());
> with the intention of putting a "last resort" resource loader at the end
> of the chain to log anything that could not be found?
>
> TIA!
> Chris
>
>
>
>> -igor
>>
>> On Mon, Aug 23, 2010 at 9:47 AM, Chris Merrill <ch...@webperformance.com> wrote:
>>> On 8/23/2010 11:21 AM, Igor Vaynberg wrote:
>>>> show us your validator
>>>
>>>
>>> TextField<String> target_name_field = new TextField<String>("target_customer_name", _target_name);
>>> target_name_field.setRequired(true);
>>> target_name_field.add(new StringValidator()
>>>    {
>>>    @Override
>>>    protected void onValidate(IValidatable<String> stringIValidatable)
>>>        {
>>>        Customer customer = _manager.getCustomer(stringIValidatable.getValue());
>>>        if (customer == null)
>>>            error(stringIValidatable, "CustomerNameNotFound");
>>>        }
>>>    });
>>> form.add(target_name_field);
>>>
>>>
>>>
>>> --
>>> ------------------------------------------------------------------------ -
>>> Chris Merrill                           |  Web Performance, Inc.
>>> chris@webperformance.com                |  http://webperformance.com
>>> 919-433-1762                            |  919-845-7601
>>>
>>> Web Performance: Website Load Testing Software & Services
>>> ------------------------------------------------------------------------ -
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
>
> --
> ------------------------------------------------------------------------ -
> Chris Merrill                           |  Web Performance, Inc.
> chris@webperformance.com                |  http://webperformance.com
> 919-433-1762                            |  919-845-7601
>
> Web Performance: Website Load Testing Software & Services
> ------------------------------------------------------------------------ -
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

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


Re: implementing a custom resource loader

Posted by Chris Merrill <ch...@webperformance.com>.
On 8/23/2010 12:59 PM, Igor Vaynberg wrote:
> and the CustomerNameNotFound is never tried? it should be tried after
> the <formid>.CustomerNameNotFound key

Yes, it does!

I violated one of the rules of IResourceLoader - I didn't return null if
something was not found.  I wrapped our existing framework, which returns a
version of the key, such as "##string-key##", and logs the missing key.

Once I changed my code to check the existence of the key and return null, it
eventually did ask by expected key name.


Two of the reasons our framework always returns something useful is to (1)
prevent catastrophic NPEs and (2) get a list of missing resources in our
diagnostic logs.  It looks like Wicket already handles missing resources
by providing the last key it tried, so I don't think #1 is needed in
the context of our new app.  But #2 would still be nice.

I'm currently adding our resource loader in app.init():
  getResourceSettings().addStringResourceLoader(0, new MyResourceLoader());
under the assumption that I want my resource loader to be first in the
chain.

If I want to get missing resources in a log file, would I instead do something
like this:
  getResourceSettings().addStringResourceLoader(0, new MyResourceLoader());
  getResourceSettings().addStringResourceLoader(new MyLoggingResourceLoader());
with the intention of putting a "last resort" resource loader at the end
of the chain to log anything that could not be found?

TIA!
Chris



> -igor
> 
> On Mon, Aug 23, 2010 at 9:47 AM, Chris Merrill <ch...@webperformance.com> wrote:
>> On 8/23/2010 11:21 AM, Igor Vaynberg wrote:
>>> show us your validator
>>
>>
>> TextField<String> target_name_field = new TextField<String>("target_customer_name", _target_name);
>> target_name_field.setRequired(true);
>> target_name_field.add(new StringValidator()
>>    {
>>    @Override
>>    protected void onValidate(IValidatable<String> stringIValidatable)
>>        {
>>        Customer customer = _manager.getCustomer(stringIValidatable.getValue());
>>        if (customer == null)
>>            error(stringIValidatable, "CustomerNameNotFound");
>>        }
>>    });
>> form.add(target_name_field);
>>
>>
>>
>> --
>> ------------------------------------------------------------------------ -
>> Chris Merrill                           |  Web Performance, Inc.
>> chris@webperformance.com                |  http://webperformance.com
>> 919-433-1762                            |  919-845-7601
>>
>> Web Performance: Website Load Testing Software & Services
>> ------------------------------------------------------------------------ -
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 
> 


-- 
------------------------------------------------------------------------ -
Chris Merrill                           |  Web Performance, Inc.
chris@webperformance.com                |  http://webperformance.com
919-433-1762                            |  919-845-7601

Web Performance: Website Load Testing Software & Services
------------------------------------------------------------------------ -

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


Re: implementing a custom resource loader

Posted by Igor Vaynberg <ig...@gmail.com>.
and the CustomerNameNotFound is never tried? it should be tried after
the <formid>.CustomerNameNotFound key

-igor

On Mon, Aug 23, 2010 at 9:47 AM, Chris Merrill <ch...@webperformance.com> wrote:
> On 8/23/2010 11:21 AM, Igor Vaynberg wrote:
>> show us your validator
>
>
> TextField<String> target_name_field = new TextField<String>("target_customer_name", _target_name);
> target_name_field.setRequired(true);
> target_name_field.add(new StringValidator()
>    {
>    @Override
>    protected void onValidate(IValidatable<String> stringIValidatable)
>        {
>        Customer customer = _manager.getCustomer(stringIValidatable.getValue());
>        if (customer == null)
>            error(stringIValidatable, "CustomerNameNotFound");
>        }
>    });
> form.add(target_name_field);
>
>
>
> --
> ------------------------------------------------------------------------ -
> Chris Merrill                           |  Web Performance, Inc.
> chris@webperformance.com                |  http://webperformance.com
> 919-433-1762                            |  919-845-7601
>
> Web Performance: Website Load Testing Software & Services
> ------------------------------------------------------------------------ -
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

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


Re: implementing a custom resource loader

Posted by Chris Merrill <ch...@webperformance.com>.
On 8/23/2010 11:21 AM, Igor Vaynberg wrote:
> show us your validator


TextField<String> target_name_field = new TextField<String>("target_customer_name", _target_name);
target_name_field.setRequired(true);
target_name_field.add(new StringValidator()
    {
    @Override
    protected void onValidate(IValidatable<String> stringIValidatable)
        {
        Customer customer = _manager.getCustomer(stringIValidatable.getValue());
        if (customer == null)
            error(stringIValidatable, "CustomerNameNotFound");
        }
    });
form.add(target_name_field);



-- 
------------------------------------------------------------------------ -
Chris Merrill                           |  Web Performance, Inc.
chris@webperformance.com                |  http://webperformance.com
919-433-1762                            |  919-845-7601

Web Performance: Website Load Testing Software & Services
------------------------------------------------------------------------ -

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


Re: implementing a custom resource loader

Posted by Igor Vaynberg <ig...@gmail.com>.
show us your validator

-igor

On Sun, Aug 22, 2010 at 8:15 PM, Chris Merrill <ch...@webperformance.com> wrote:
> I need to implement our own resource loader in order to re-use our existing
> infrastructure for resolving localized strings.  I've implemented IStringResourceLoader
> and have that working, but I've found I need a bit of a hack to get it to do what
> I need.
>
> In two scenarios:
>  <wicket:message key="Merge_Customers"/>
> and
>  new Button("submit_button", new StringResourceModel("Move_License", this, null))...
> the resource is requested in my IStringResourceLoader.loadStringResource() by the specified
> names ("Merge_Customers" and "Move_License").  This is exactly what I expected and is working
> great.
>
> However, in another area where I specify the resource in the onValidate() method of a
> StringValidtor, like this:
>     error(stringIValidatable, "CustomerNameNotFound");
> IStringResourceLoader.loadStringResource() is called with
>  name="target_customer_name.CustomerNameNotFound"
> instead of
>  name="CustomerNameNotFound"
> (where "target_customer_name" is the name of the field).
>
>
> Is this the intended behavior?
>
> If yes, how do I know when Wicket will be adding something to the resource key I specify
> and when it will not?  We want to specify a resource key in source or markup and have the
> resource requested using that exact key.
>
> TIA!
> Chris
>
>
>
> --
> ------------------------------------------------------------------------ -
> Chris Merrill                           |  Web Performance, Inc.
> chris@webperformance.com                |  http://webperformance.com
> 919-433-1762                            |  919-845-7601
>
> Web Performance: Website Load Testing Software & Services
> ------------------------------------------------------------------------ -
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

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