Removing Seconds, Minutes and Hours from a WDK Date-Time DocbaseAttribute Value Control

So, you are building a wdk application using docbaseobjects. Good 🙂 But now you want more control on how your datetime attribute is rendered. That what I wanted anyway. So after doing some googling I found a javascript that actually hides the fields after they are rendered.  This seemed so ugly to me that I decided to create a custom DateValueTag implementation.

 

How is this accomplished?

I created my own DocbaseAttributeValueTag extension. See below

package my.package;
import java.io.IOException;
import java.util.ArrayList;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.JspWriter;
import com.documentum.fc.common.IDfProperties;
import com.documentum.web.common.WrapperRuntimeException;
import com.documentum.web.form.control.DateInput;
import com.documentum.web.form.control.DateInputTag;
import com.documentum.web.form.control.DateTime;
import com.documentum.web.formext.Trace;
import com.documentum.web.formext.control.docbase.DocbaseAttributeCache;
import com.documentum.web.formext.control.docbase.DocbaseAttributeValue;
import com.documentum.web.formext.control.docbase.DocbaseAttributeValueTag;
/**
 */
public class ShortDateTag
    extends DocbaseAttributeValueTag
{
    protected void renderSingleAttribute( String strFormattedValue, String strValue, boolean bReadonly,
                                          boolean bHasCompleteList, JspWriter out )
        throws IOException, JspTagException
    {
        if ( bReadonly )
        {
            super.renderSingleAttribute( strFormattedValue, strValue, bReadonly, bHasCompleteList, out );
        }
        else
        {
            // render custom date control here
            renderCustomDateTime( strValue, out );
        }
    }
    private void renderCustomDateTime( String strValue, JspWriter out )
    {
        DocbaseAttributeValue value = (DocbaseAttributeValue) getControl();
        String strClass = value.getCssClass();
        String strStyle = value.getCssStyle();
        String strSize = "32";
        DateInputTag tag = new DateInputTag();
        tag.setPageContext( pageContext );
        tag.setParent( this );
        tag.setName( value.getElementName( "value" ) );
        tag.setId( getId() );
        tag.setTooltip( value.getToolTip() );
        if ( strClass != null )
        {
            tag.setCssclass( strClass );
        }
        if ( strSize != null )
        {
            tag.setWidth( strSize );
        }
        if ( strStyle != null )
        {
            tag.setStyle( strStyle );
        }
        DateInput dateTimeObj = (DateInput) tag.getControl();
        if ( !value.isEnabled() )
        {
            dateTimeObj.setEnabled( false );
        }
        else
        {
            dateTimeObj.setEnabled( true );
        }
        java.util.Date date = DateTime.toDate( strValue );
        if ( date != null )
        {
            dateTimeObj.setValue( date );
        }
        dateTimeObj.setIsRemovable( false );
        renderSetEvents( null, value.getVaDependenciesProperties(), out );
        DocbaseAttributeCache
            .updateAttributeAndDependentList( value.getAttribute(), dateTimeObj.getElementName(), null );
        try
        {
            tag.doStartTag();
            tag.doEndTag();
        }
        catch ( JspTagException e )
        {
            throw new WrapperRuntimeException( e );
        }
    }
    /**
     * see com.documentum.web.formext.control.docbase.DocbaseAttributeValueTag
     */
    private void renderSetEvents( String strControlName, IDfProperties dependenciesList, JspWriter out )
    {
        DocbaseAttributeValue value = (DocbaseAttributeValue) getControl();
        ArrayList lisControls = DocbaseAttributeCache.getPostServerEventControls( value.getAttribute(), strControlName,
                                                                                  dependenciesList );
        StringBuffer buf = new StringBuffer( 256 );
        if ( lisControls.size() > 0 )
        {
            buf.append( "<script>" );
            buf.append( "setPostServerEventControls(\"" );
            for ( int i = 0; i < lisControls.size(); i++ )
            {
                if ( i > 0 )
                {
                    buf.append( ",\"" );
                }
                buf.append( (String) lisControls.get( i ) );
                buf.append( "\"" );
            }
            buf.append( ");" );
            buf.append( "</script>" );

        }
    }
}

Now you only have to get the WDK to use the new tag. This is accomplished in a xml file. I created a docbaseattributes.xml and added the lines:

<config version='1.0'>
   <scope type="my_document_type">
      <docbaseobjectconfiguration id='attributes'>
         <names>
            <!-- apply to attribute -->
            <attribute name='senddate'>
               <valuetagclass>my.package.ShortDateTag</valuetagclass>
            </attribute> 
 

That’s it!

Advertisements

4 Responses to “Removing Seconds, Minutes and Hours from a WDK Date-Time DocbaseAttribute Value Control”

  1. aborkar Says:

    Thanks for this one. There is a component on the emc developer site but that one uses JavaScript I guess. This one is much cleaner.

  2. APryamikov Says:

    RobAu, hi!

    Nice article! It helped me with creating custom tag very much.

  3. fenil Says:

    Thanks a lot … this was of great help ….
    I do have a question … after implementing this class, my custom date attribute which was required became not – required.
    I tried setting setRequired(true) at different locations, overriding the setControlProperties method but nothing seems to work.

    If you have any idea about this, please let me know.

  4. Nitesh Says:

    This was very helpful, how do we achieve the same for Repeating Attributes, we have some Date Attributes which are repeating.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: