You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Taha Hafeez <ta...@gmail.com> on 2010/11/01 04:33:17 UTC

Overriding BeanBlockSource

I am trying to override default editing components as I want to remove the
labels.. but contributeBeanBlockSource() is called in a random order (at
times before and at times after the TapestryModules's
contributeBeanBlockSource()). . I used @Order("after:*") but it is still
random.

Someone already had the same issue(
http://www.mail-archive.com/users@tapestry.apache.org/msg29783.html). Has
this been resolved or I am doing something wrong...

Taha

Re: Overriding BeanBlockSource

Posted by "Juan E. Maya" <ma...@gmail.com>.
Hello Taha,

what you can do is to contribute a new DataTypeAnalyzer and then
contribute its bean block source. The DataTypeAnalyzer is a
orderedlist so you can control their order.

For example if you would like to override the date selector used by
tapestry u should have something like this in your module:

public static void
contributeDataTypeAnalyzer(OrderedConfiguration<DataTypeAnalyzer>
configuration) {
   configuration.add(DateTypeAnalyzer.DATE_TYPE, new
DateTypeAnalyzer(), "before:*");
}

public void contributeBeanBlockSource(Configuration<BeanBlockContribution>
configuration) {
    configuration.add(new
BeanBlockContribution(DateTypeAnalyzer.DATE_TYPE, "BrandingBlocks",
"dateBlock", true));
}


The DateTypeAnalyzer is something like:
public class DateTypeAnalyzer implements DataTypeAnalyzer {

	public static final String DATE_TYPE = "nebulaDate";

	@Override
	public String identifyDataType(PropertyAdapter adapter) {
		Class<?> propertyType = adapter.getType();
		if (Date.class.equals(propertyType)){
			return DATE_TYPE;
		}
		
		return null;
	}
}

finally you define the block. for example:
<t:block t:id="dateBlock">
  		<t:label for="dateSelector"/>
  		<select t:id="dateSelector" t:firstYear="firstYear"
t:lastYear="lastYear" t:value="prop:context.propertyValue"
t:label="prop:context.label" t:validate="prop:dateValidator"
t:translator="prop:dateTranslator" >
  		</select>
  </t:block>


I hope it helps :)




On Mon, Nov 1, 2010 at 4:33 AM, Taha Hafeez <ta...@gmail.com> wrote:
> I am trying to override default editing components as I want to remove the
> labels.. but contributeBeanBlockSource() is called in a random order (at
> times before and at times after the TapestryModules's
> contributeBeanBlockSource()). . I used @Order("after:*") but it is still
> random.
>
> Someone already had the same issue(
> http://www.mail-archive.com/users@tapestry.apache.org/msg29783.html). Has
> this been resolved or I am doing something wrong...
>
> Taha
>

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


Re: Overriding BeanBlockSource

Posted by Taha Hafeez <ta...@gmail.com>.
It worked...

//-------------------------------------
//As i had to override all, I created a generic class
//---------------------------------------
import org.apache.tapestry5.services.DataTypeAnalyzer;
import org.apache.tapestry5.ioc.services.PropertyAdapter;

public class GenericTypeAnalyzer implements DataTypeAnalyzer {
   private final String dataType;
   private final Class<?> dataClass;

   public GenericTypeAnalyzer(String dataType, Class<?> dataClass){
      this.dataType = dataType;
      this.dataClass = dataClass;
   }

   public String getType(){
      return dataType;
   }

   public Class<?> getDataClass(){
      return dataClass;
   }

   @Override
   public String identifyDataType(PropertyAdapter propertyAdapter){
      Class<?> propertyType = propertyAdapter.getType();
      if(dataClass.isAssignableFrom(propertyType)){
         return dataType;
      }
      return null;
   }
}


Then in AppModule I did this
    public static void
contributeDataTypeAnalyzer(OrderedConfiguration<DataTypeAnalyzer>
configuration){
       configuration.add(TypeConstants.TEXT_TYPE,
             new GenericTypeAnalyzer(TypeConstants.TEXT_TYPE, String.class),
"before:*");
       configuration.add(TypeConstants.NUMBER_TYPE,
             new GenericTypeAnalyzer(TypeConstants.NUMBER_TYPE,
Number.class), "before:*");
       configuration.add(TypeConstants.DATE_TYPE,
             new GenericTypeAnalyzer(TypeConstants.DATE_TYPE, String.class),
"before:*");
       configuration.add(TypeConstants.PASSWORD_TYPE,
             new GenericTypeAnalyzer(TypeConstants.PASSWORD_TYPE,
String.class), "before:*");
       configuration.add(TypeConstants.ENUM_TYPE,
             new GenericTypeAnalyzer(TypeConstants.ENUM_TYPE, Enum.class),
"before:*");
       configuration.add(TypeConstants.BOOLEAN_TYPE,
             new GenericTypeAnalyzer(TypeConstants.BOOLEAN_TYPE,
Boolean.class), "before:*");
       configuration.add(TypeConstants.CALENDAR_TYPE,
             new GenericTypeAnalyzer(TypeConstants.CALENDAR_TYPE,
Calendar.class), "before:*");
    }

    public static void
contributeBeanBlockSource(Configuration<BeanBlockContribution>
configuration){
       addEditBlock(configuration, TypeConstants.TEXT_TYPE);
       addEditBlock(configuration, TypeConstants.NUMBER_TYPE);
       addEditBlock(configuration, TypeConstants.DATE_TYPE);
       addEditBlock(configuration, TypeConstants.ENUM_TYPE);
       addEditBlock(configuration, TypeConstants.BOOLEAN_TYPE);
       addEditBlock(configuration, TypeConstants.PASSWORD_TYPE);
       addEditBlock(configuration, TypeConstants.CALENDAR_TYPE);
       addEditBlock(configuration, TypeConstants.LONG_TEXT_TYPE);
    }

    private static void addEditBlock(Configuration<BeanBlockContribution>
configuration, String dataType){
       configuration.add(new BeanBlockContribution(dataType,
"PropertyEditBlocksWithoutLabel", dataType.substring(1), true));
   }


Thanks a lot
Taha


On Mon, Nov 1, 2010 at 4:22 PM, Thiago H. de Paula Figueiredo <
thiagohp@gmail.com> wrote:

> On Mon, 01 Nov 2010 01:33:17 -0200, Taha Hafeez <ta...@gmail.com>
> wrote:
>
>  I am trying to override default editing components as I want to remove the
>> labels.. but contributeBeanBlockSource() is called in a random order (at
>> times before and at times after the TapestryModules's
>> contributeBeanBlockSource()). . I used @Order("after:*") but it is still
>> random.
>>
>
> @Order is used to specify the order decorators and advised are apllied, not
> in which order the contributed objects are included. Just do what Juan
> suggested (adding a DataTypeAnalyzer before every other) and it will work.
> :)
>
> --
> Thiago H. de Paula Figueiredo
> Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
> and instructor
> Owner, Ars Machina Tecnologia da Informação Ltda.
> http://www.arsmachina.com.br
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: Overriding BeanBlockSource

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Mon, 01 Nov 2010 01:33:17 -0200, Taha Hafeez <ta...@gmail.com>  
wrote:

> I am trying to override default editing components as I want to remove  
> the labels.. but contributeBeanBlockSource() is called in a random order  
> (at
> times before and at times after the TapestryModules's
> contributeBeanBlockSource()). . I used @Order("after:*") but it is still
> random.

@Order is used to specify the order decorators and advised are apllied,  
not in which order the contributed objects are included. Just do what Juan  
suggested (adding a DataTypeAnalyzer before every other) and it will work.  
:)

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

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