Skip navigation
All Places > Blackboard Developer Community > Blog > 2017 > March > 17

Now we have a working Building Block lets add some more information to the course tool as a form.

 

CourseToolConfig.java

 

//Create a LIST filled with Group Objects using the Course ID.

 

  private static List<Group> GroupObjects(String course_id) throws PersistenceException{
        GroupDbLoader groupDbLoader = GroupDbLoader.Default.getInstance();
        List<Group> groups = groupDbLoader.loadAvailableByCourseId((Id.generateId(new DataType(blackboard.data.course.Course.class), course_id)));

        List<Group> G1 = new LinkedList<>();

            for (Group group : groups){
                
                //Get group titles. Add to Linked list g1.
                G1.add(group);
                System.out.println("Group Size"+group.getGroupMemberships().size());
    
                
            }
            
            return G1;
        
    }

 

 

Now we need to add some Getter's and Setter's for the List we will pass to the JSP page.

 

 

private List<Group> groupTitles; 
public List<Group> getGroupTitles() {return groupTitles; }
public void setGroupTitles(List<Group> groupTitles) { this.groupTitles = groupTitles; }

 

 

In our Default Handler   @DefaultHandler   public Resolution displayPage() we can populate this list

 

groupTitles = GroupObjects(course_id);

 

To display this in the JSP we use the actionBean.groupTitles List and then can call out the getTitle and getGroupMemberships().size() from the Group Object in the List

 

<bbNG:form action="coursetool" method="post">

        <bbNG:dataCollection>

            <bbNG:step title="Groups">

         

                        <bbNG:inventoryList description="Group Names"  className="Group" collection="${actionBean.groupTitles}" objectVar="title" emptyMsg="No data to display">

                        <bbNG:listElement  name="Group" label="Group" isRowHeader="true">${title.getTitle()}</bbNG:listElement>

                        <bbNG:listElement  name="Group Enrollments" label="Group Enrollments"  isRowHeader="false">${title.getGroupMemberships().size()}</bbNG:listElement>

                        <bbNG:listCheckboxElement  title="Title" name="${title.getTitle()}" id="ID" value="Y"></bbNG:listCheckboxElement>

                </bbNG:inventoryList>

 

                        <input type="hidden" name="course_id" value="${actionBean.course_id}" />

                     

                     

                 

            <bbNG:stepInstructions text="    ${message}  <BR>

               Course Title =  ${actionBean.course_title} <BR>

               Course Pk1 =  ${actionBean.course_id}  <BR>

               User Name  = ${actionBean.username}

               "/>

            </bbNG:step>

        <bbNG:stepSubmit  cancelUrl="Cancle" />

        </bbNG:dataCollection>

    </bbNG:form>

In part one we build a basic course tool.  In this part we will use the config utility to set dome value for our B2.  These can be used for things like Global user/pass.

 

The B2 stub uses ATD's Configuration Utilities Library to provide configuration services to the building block. This building block handles the saving, loading and caching of a configuration bean.

 

 

The Configuration.java contain the list of Getters and Setters for this page. More can be added of modified.

 

package com.devday.config;

import net.sourceforge.stripes.validation.Validate;

/**
 * Created by wiley on 19/11/14.
 */
public class Configuration {

    private String settingOne;
    private int settingTwo;

    public String getSettingOne() {
        return settingOne;
    }

    public void setSettingOne(String settingOne) {
        this.settingOne = settingOne;
    }

    public int getSettingTwo() {
        return settingTwo;
    }

    public void setSettingTwo(int settingTwo) {
        this.settingTwo = settingTwo;
    }
}

 

 

Stripes config.action

 

@LoginRequired
@EntitlementRestrictions(entitlements = "bbs.yourb2name.admin.MODIFY", errorPage = "/error.jsp")
@UrlBinding("/config")
public class ConfigAction implements ActionBean {

    private BlackboardActionBeanContext context;

    @ValidateNestedProperties({@Validate(field = "settingOne", required = true),
            @Validate(field = "settingTwo", required = true, minvalue = 0, maxvalue = 100)})
    private Configuration config;

    @SpringBean
    private ConfigurationService<Configuration> configService;

    @Before(stages = LifecycleStage.BindingAndValidation)
    public void loadConfiguration() {
        config = configService.loadConfiguration();
    }


    @DefaultHandler
    @DontValidate
    public Resolution displayConfigPage() {
        return new ForwardResolution("/WEB-INF/jsp/config.jsp");
    }

    public Resolution saveConfiguration() {
        configService.persistConfiguration(config);
        return new RedirectResolution(PlugInUtil.getPlugInManagerURL(), false);
    }

    @Override
    public ActionBeanContext getContext() {
        return context;
    }

    @Override
    public void setContext(ActionBeanContext context) {
        this.context = (BlackboardActionBeanContext)context;
    }

    public Configuration getConfig() {
        return config;
    }

    public void setConfig(Configuration config) {
        this.config = config;
    }
}

 

 

Note the Form Validation, if you make a change to the methods for example making the int a String you will need to update this validation to match the type.

 

@ValidateNestedProperties({@Validate(field = "settingOne", required = true),     @Validate(field = "settingTwo", required = true, minvalue = 0, maxvalue = 100)})

 

Default Values:

 

If you want to pre-populate these configs with default values then edit the defultconfig.xml under src/main/resources

 

<com.devday.config.Configuration>
  <settingOne>A default string value</settingOne>
  <settingTwo>42</settingTwo>
</com.devday.config.Configuration>

 

Config JSP.

 

This uses a simple Form to collect the data and pass via the Stripes Action

 

 

 

<stripes:form beanclass="com.devday.stripes.ConfigAction">

        <stripes:param name="saveConfiguration"/>

 

        <bbNG:dataCollection>

            <bbNG:step title="${toolSettingsStepTitle}" instructions="${toolSettingsStepInstructions}">

                <bbNG:dataElement isRequired="true" label="${settingOneLabel}">

                    <stripes:text name="config.settingOne"></stripes:text>

                    <stripes:errors field="config.settingOne"></stripes:errors>

                </bbNG:dataElement>

                <bbNG:dataElement isRequired="true" label="${settingTwoLabel}">

                    <stripes:text name="config.settingTwo"></stripes:text>

                    <stripes:errors field="config.settingTwo"></stripes:errors>

                </bbNG:dataElement>

            </bbNG:step>

            <bbNG:stepSubmit></bbNG:stepSubmit>

        </bbNG:dataCollection>

    </stripes:form>