function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JNicJNic 

Wrapper class "selected" boolean not selecting (Chatter Provisioning Component)

Hey all,

 

I'm working on building a component that allows a user to provision other users into following a record on chatter.

 

I have a wrapper class with an EntitySubscription obect in it, and a boolean for selection. I then use an apex:inputcheckBox on the vf compnent to enable selection by the user.

 

Problem is that it does not seem to be selecting...All I'm trying to do with the removeSelected() method below is add the index numbers to a list... It doesnt add anything, and the viewstate never shows any booleans as selected.

 

Please help.

 

 

CONTROLLER:

 

public with sharing class chatterUtils {

    //This is a specific entity Id to tie a user to via chatter
    public string parentId {get;set;}

    public string index {get;set;}

    public list<userRow> userRows {
        get {
            if (userRows == null) {
                userRows = new list<userRow>();
            }
            return userRows;
        }
        set;
    }

    public class userRow {
       public EntitySubscription rowEnt {get;set;}
       public boolean rowSelected {get;set;}
       public integer rowIndex {get;set;}
       public userRow(EntitySubscription rEnt, boolean rSel, integer rInd) {
           rowEnt = rEnt;
           rowSelected = rSel;
           rowIndex = rInd;
       }
    }

    public list<EntitySubscription> subs {get;set;}

    //Subscribe the list of users to the entity id
    public void provisionFollowers() {
        list<EntitySubscription> sub = new list<EntitySubscription>();
        for (userRow u : userRows) {
            entitysubscription e = u.rowEnt;
            sub.add(e);
        }
        insert sub;
    }

    public chatterUtils() {
        userRows.add(new userRow(new EntitySubscription(parentId = parentId), false, 0));
    }

    public void add() {
        userRows.add(new userRow(new EntitySubscription(parentId = parentId), false, userRows.size()));
    }

    //Remove the clicked row, and set the following indexs back by one
    public void remove(){
        userRows.remove(integer.valueOf(index));
        for (integer i = integer.valueOf(index); i < userRows.size(); i++){
            userRows[i].rowIndex -= 1;
        }
    }

    public list<integer> selectedIndexes = new list<integer>();
    public pageReference removeSelected(){
        for (integer i = 0; i<userRows.size(); i++){
            if (userRows[i].rowSelected) {
                selectedIndexes.add(i);
            }
        }
        return null;
    }
}

 

 

COMPONENT

 

<apex:component controller="chatterUtils" allowDML="true" >

    <apex:attribute assignTo="{!parentId}" description="The record Id that the user(s) will be provisioned to follow. This must be a chatter enabled object." name="parentId" required="true" type="string"/>

    <!-- jQuery-->
    <apex:includeScript value="{!URLFOR($Resource.BundledResources, 'jQuery/jquery-1.4.2.min.js')}"/>
    <apex:includeScript value="{!URLFOR($Resource.BundledResources, 'jQuery/jquery-ui-1.8.6.custom.min.js')}"/>

    <apex:form >
        <apex:actionFunction action="{!remove}" name="removeIndex" reRender="userRowTable" immediate="true">
            <apex:param assignTo="{!index}" name="index" value=""/>
        </apex:actionFunction>
        <apex:pageBlock >
            <apex:pageBlockButtons >
                <apex:commandButton action="{!add}" value="Add" reRender="userRowTable" immediate="true"/>
                <apex:commandButton action="{!removeSelected}" value="Remove Selected" reRender="userRowTable" immediate="true"/>
            </apex:pageBlockButtons>
            <apex:pageBlockTable value="{!userRows}" var="user" id="userRowTable">
                <apex:column headerValue="Action">
                    <apex:inputCheckbox value="{!user.rowSelected}"/>
                    <apex:commandLink value="Remove" immediate="true" onclick="removeIndex('{!user.rowIndex}')" reRender="none"/>
            </apex:column>
                <apex:column headerValue="User">
                    <apex:inputField value="{!user.rowEnt.subscriberId}" />
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>

</apex:component>

 

 

MarkWaddleMarkWaddle

Hi Jay,

 

Have you tried initializing your selectedIndexes field in the constructor instead of on the same line where the field is declared?

 

Mark

JNicJNic

Tried this... No dice...

 

The input checkbox doesnt seem to do anything - even if I just do a re-render  - it doesnt change selected to true...

 

 

public with sharing class chatterUtils {

    //This is a specific entity Id to tie a user to via chatter
    public string parentId {get;set;}

    public string index {get;set;}

    public list<userRow> userRows {
        get {
            if (userRows == null) {
                userRows = new list<userRow>();
            }
            return userRows;
        }
        
        set;
    }

    public class userRow {
       public EntitySubscription rowEnt {get;set;}
       public boolean rowSelected {get;set;}
       public integer rowIndex {get;set;}
       public userRow(EntitySubscription rEnt, boolean rSel, integer rInd) {
           rowEnt = rEnt;
           rowSelected = rSel;
           rowIndex = rInd;
       }
    }

    public list<EntitySubscription> subs {get;set;}

    //Subscribe the list of users to the entity id
    public void provisionFollowers() {
        list<EntitySubscription> sub = new list<EntitySubscription>();
        for (userRow u : userRows) {
            entitysubscription e = u.rowEnt;
            sub.add(e);
        }
        insert sub;
    }
    
    public chatterUtils() {
        userRows.add(new userRow(new EntitySubscription(parentId = parentId), false, 0));
        selectedIndexes = new list<integer>();
    }

    public void add() {
        userRows.add(new userRow(new EntitySubscription(parentId = parentId), false, userRows.size()));
    }
    
    //Remove the clicked row, and set the following indexs back by one
    public void remove(){
        userRows.remove(integer.valueOf(index));
        for (integer i = integer.valueOf(index); i < userRows.size(); i++){
            userRows[i].rowIndex -= 1;
        }
    }

    public list<integer> selectedIndexes {get;set;}
    public pageReference removeSelected(){
        for (integer i = 0; i<userRows.size(); i++){
            if (userRows[i].rowSelected) {
                selectedIndexes.add(i);
            }
        }
        return null;
    }
}