You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Sebastiaan van Erk <se...@sebster.com> on 2005/11/03 22:31:35 UTC

More complex types in @Meta/@InjectMeta annotations

Hi,

Just wondering if it was possible to accomplish this somehow:

@Meta("my-array={ string1, string2 }")
public abstract class TestPage extends BasePage {

	@InjectMeta("my-array")
	public abstract String[] getMyArray();

	...
}

At the moment it complains that it cannot coerce to a String[] because 
it does not have an appropriate ValueConverter. Since the logic for 
parsing arrays from strings like that is surely lying around somewhere, 
shouldn't this be relatively simple to add?

Greetings,
Sebastiaan van Erk

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


Re: More complex types in Meta/ InjectMeta annotations

Posted by Sebastiaan van Erk <se...@sebster.com>.
Hi,

Thanks for your reply!

Currently I did implement it in the second way you explained, but I 
wasn't too happy with it...

I like your other suggestion, that way I can move the code cleanly to a 
reusable utility class and my Page class won't have any clutter nor will 
it have to change when Tapestry itself get this kind of feature (or at 
worst the format of the annotation will have to change).

Finally, I know that Tapestry can parse arrays though (it does so with 
the parameters of the DirectLink class), so I'd rather not duplicate 
this code myself (new bugs, etc.), and use that... I was wondering if it 
is possible to use that without having to write a wrapper class (just 
using XML)...

Greetings,
Sebastiaan

Kent Tong wrote:
> Sebastiaan van Erk <sebster <at> sebster.com> writes:
> 
> 
>>Hi,
>>
>>Just wondering if it was possible to accomplish this somehow:
>>
>> <at> Meta("my-array={ string1, string2 }")
>>public abstract class TestPage extends BasePage {
>>
>>	 <at> InjectMeta("my-array")
>>	public abstract String[] getMyArray();
>>
>>	...
>>}
>>
>>At the moment it complains that it cannot coerce to a String[] because 
>>it does not have an appropriate ValueConverter. Since the logic for 
>>parsing arrays from strings like that is surely lying around somewhere, 
>>shouldn't this be relatively simple to add?
> 
> 
> You can add a contribution like:
> 
>  <contribution configuration-id="ListConverters">
>    <converter 
>      class="java.lang.String" 
>      object="instance:StringToListConverter" />
>  </contribution>
> 
> Then define a class StringToListConverter implementing TypeConverter to
> convert a comman separated string into a List. Of course, you should
> expect a List instead of an array:
> 
> public abstract class TestPage extends BasePage {
>   @InjectMeta("my-list")
>   public abstract List getMyList();
> }
>  
> Do you consider this simple? If not, you may just do it like this:
> 
> public abstract class TestPage extends BasePage {
>   @InjectMeta("my-array")
>   public abstract String getMyArrayAsString();
> 
>   public List getMyArray() {
>     //call getMyArrayAsString() and convert it to a list.
>   }
> }
> 
> --
> 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
> 

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


Re: More complex types in Meta/ InjectMeta annotations

Posted by Kent Tong <ke...@cpttm.org.mo>.
Sebastiaan van Erk <sebster <at> sebster.com> writes:

> 
> Hi,
> 
> Just wondering if it was possible to accomplish this somehow:
> 
>  <at> Meta("my-array={ string1, string2 }")
> public abstract class TestPage extends BasePage {
> 
> 	 <at> InjectMeta("my-array")
> 	public abstract String[] getMyArray();
> 
> 	...
> }
> 
> At the moment it complains that it cannot coerce to a String[] because 
> it does not have an appropriate ValueConverter. Since the logic for 
> parsing arrays from strings like that is surely lying around somewhere, 
> shouldn't this be relatively simple to add?

You can add a contribution like:

 <contribution configuration-id="ListConverters">
   <converter 
     class="java.lang.String" 
     object="instance:StringToListConverter" />
 </contribution>

Then define a class StringToListConverter implementing TypeConverter to
convert a comman separated string into a List. Of course, you should
expect a List instead of an array:

public abstract class TestPage extends BasePage {
  @InjectMeta("my-list")
  public abstract List getMyList();
}
 
Do you consider this simple? If not, you may just do it like this:

public abstract class TestPage extends BasePage {
  @InjectMeta("my-array")
  public abstract String getMyArrayAsString();

  public List getMyArray() {
    //call getMyArrayAsString() and convert it to a list.
  }
}

--
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