Username Password
Bookmark and Share

Wobject Cookbook

The Wobject Cookbook is intended for developers as a cookbook guide to writing a custom asset. It includes miscellaneous recipes on how to do various tasks within your custom asset. 


When designing a Wobject, define what attributes you will need for your Wobject in the definition method. These attributes are directly related to the Wobject's asset table. 


When you need to associate a file or secondary data to your Wobject, you'll need to associate Collateral via a secondary table. Use the setCollateral method in to update your Wobject's collateral table.

An example, a user uploads an image or file via the use of your Wobject.

  1. Add the creation and deletion of the table to Wobject's install and uninstall respectively.
  2. Create a form with a file upload form control via your view method in the Wobject.
  3. Process the form (including upload) and call setCollateral to update the Wobject's collateral table.


Add a custom tab

You can add your own custom tab to the admin edit screen by overriding the method getEditTabs or getEditForm. Examples of each method are found within the codebase. In addition, the fields for your custom tab must be defined in the Wobject's definition, with the newly created tab name as the value for 'tab' in the field definition.

The simpliest method is to place the following method in your custom wobject. In this example, we're adding a new tab called 'Things' with a selectList of Things from the database.

sub getEditTabs {
        my $self = shift;
        return $self->SUPER::getEditTabs, (['things', 'Things', 9]);

In your definition method, you'll need to define the fields for the new tab.

        categoryThingId => {
            tab => "things",
            autoGenerate => 1,
            defaultValue => '',
            label => 'Product Category',
            options => $session->db->buildHashRef(
                "SELECT thingId, label FROM Thingy_things",

Upload a File From a Form Post

Creates a new file asset in storage from a form post.  

my $storage = WebGUI::Storage->create($self->session);
my $filename = $storage->addFileFromFormPost('file_param_name_formId', 1);

Create a Wobject w/Custom View Using Applied Style 

Create a custom view with a custom form, using the applied Style template, by calling processTemplate. 

sub view {
my $self = shift;
my $session = $self->session;

#This automatically creates template variables for all of your wobject's properties.
my %var = %{$self->get};
    my $f = WebGUI::HTMLForm->new($self->session,-action=>$self->getUrl)
    ...code. create form using WebGUI::HTMLForm 
    $var{'form.content'} = $f->print;
return $self->processTemplate(\%var, undef, $self->{_viewTemplate});

Create a default template for your Wobject that outputs form.content by adding form.content to your default template in the import() method of your Wobject (see the Wobject Development Tutorial). 

    # add a template
    my $import = WebGUI::Asset->getImportNode($session);
<div><a name="id<tmpl_var assetId>" id="id<tmpl_var assetId>"></a></div>

<tmpl_if session.var.adminOn>
    <p><tmpl_var controls></p>

<tmpl_if displayTitle>
    <h1><tmpl_var title></h1>

<tmpl_if description>
    <p><tmpl_var description></p>

<table class="content" width="100%">
<td valign="top">
   <tmpl_var form.start>
    <tmpl_var form.content>
   <tmpl_var form.end>


                ownerUserId=>'3', # admin
                groupIdEdit=>'3', #admin

        my $versionTag = WebGUI::VersionTag->getWorking($session);
        $versionTag->set({name=>"Install MyWobject
Wobject Template"});


Install/Uninstall Methods

The install/uninstall methods have been revised since the publication of the WebGUI Developers Guide. When installing an asset, use the following to add it to the config (other options are available for the hash):



Keywords: asset Assets collateral Development file tab upload

Search | Most Popular | Recent Changes | Wiki Home
© 2023 Plain Black Corporation | All Rights Reserved