0

I am using a wrapper class to combine an sObject with a checkbox, then iterating over the wrappers in my list. The first column displays the checkbox, then a repeat tag iterates over a list of strings derived from the object fieldNames, allowing the table to render columns according to the object's fieldSet.

the 'fieldSetList' is a list of field Names and I'm using a dynamic APEX process so that the client can reconfigure their table by changing the value and their order in the field set on the custom object.

The table displays correctly, however I want to be able to sort the table by clicking on the column. To do this, I have tried to add an onclick call to an ActionFunction ('sortCLTable') to the column and sending the repeat tag's interation variable ('f') as a parameter: 'onclick="sortCLTable(f)"'

The ActionFunction's parameter should set the sortValue property in the controller, and run the sorttable method, but alas it does not. The table columns have no response whatsoever.

<apex:page ...>
<apex:form>
    <apex:outputPanel id="thePanel">

        <apex:pageBlockTable value="{!CLWraps}" var="CLWrap">
                    <apex:column headervalue="Select" >
                        <apex:inputCheckbox value="{!CLWrap.selectbox}"/>
                    </apex:column>
                    <apex:repeat value="{!fieldSetList}" var="f" >
                        <apex:column value="{!CWrap.CL[f]}" onclick="sortCLTable(f)"/>
                    </apex:repeat>

             </apex:pageBlockTable>
    </apex:outputPanel>
    <apex:actionFunction action="{!sortTable}" name="sortCLTable" reRender="thePanel">
                <apex:param name="firstParam" assignTo="{!sortValue}" value="" />
     </apex:actionFunction>
</apex:form>
</apex:page>

CONTROLLER contains:

public string sortValue {get; set;}

public pageReference sortTable(){
    resetQueryWithSortValue(sortValue);
    return null;
}

Although the 'f' is working to set the column header (as its referencing a sObject field). it doesn't appear to be passing as a parameter to the apex:Param value associated with the function, or to the controller's corresponding property. I think I've written the page tags correctly...

Using ActionSupport instead appears to mess up the repeat function such that the column names no longer appear - not sure why...

I can add more code if needed, but figured this would describe the problem. Any help is much appreciated.

Thanks

VeMan

1

If this example is to be trusted, then perhaps the only problem is this line:

<apex:column value="{!CWrap.CL[f]}" onclick="sortCLTable(f)"/>

If you use your browser's "Inspect Element" you will see that the "f" has not been substituted, because only expressions inside {! } are substituted by Visualforce.

What you need instead is this:

<apex:column value="{!CWrap.CL[f]}" onclick="sortCLTable('{!f}')"/>

which will output a JavaScript string of the field name as the argument to the generated JavaScript function.

| improve this answer | |
  • Thanks for the reply. I tried that, but no luck... Very strange really, since I know I have succeeded in getting my column headers to sort before, even when using a list of wrapper objects. Seems like 'f' has been defined as the variable which is an item in the fieldSetList string list which is driving the repeat tag. And, the 'f' remains valid as a list item in the column tag's value definition, but not as the parameter being sent to the actionFunction. That seems wierd. What am I missing? – VeMan Nov 5 '14 at 12:36
  • @VeMan Moving the apex:actionFunction inside the apex:repeat would be my first suggestion. Worth a try - but I'm not sure if/how the generated JavaScript is handled when there are multiple copies. – Keith C Nov 5 '14 at 13:09
  • Unfortunately, from the devguide: Note: Beginning with API version 23 you can't place <apex:actionFunction> inside an iteration component — <apex:pageBlockTable>, <apex:repeat>, and so on. Put the <apex:actionFunction> after the iteration component, and inside the iteration put a normal JavaScript function that calls it. – VeMan Nov 5 '14 at 18:27
  • @VeMan That sounds reasonable enough - you'll give it a go yes? – Keith C Nov 5 '14 at 18:36
-1

when i click on checkbox contact they display editable field enter code here

apex class public class ActionFunction {

public Contact con {get;set;}
public List <WrapperContact> WrapperCon{get;set;}

public Integer total_rows = [select count() from contact];
public Integer Limit_num = 10;
public Integer Offset_num = 0;

//..........................Constructor............................................................

public ActionFunction(){
    con = new Contact();
    WrapperCon = new List<WrapperContact>();

    for(Contact wc : [select firstname,lastname, email,phone from contact limit 10]){
        WrapperContact w= new WrapperContact();
        w.ischecked=false;
        w.cont=wc;
        WrapperCon.add(w);     
    }

}

/----Action method--/

public void isChecked(){ 
    for(WrapperContact rowCheck : WrapperCon){
        if(rowCheck.isChecked == false){
            rowCheck.editContact=false;
        }else{
            rowCheck.editContact=true;              
        } 
    }
}

/--WRAPPER CLASS-------/

public class WrapperContact{
    public Boolean isChecked{get;set;}
    public Contact cont{get;set;}
    public Boolean editContact{get; set;}
}

}

vf page

    <apex:outputPanel id="inP">
        <apex:outputPanel rendered="true">

        </apex:outputPanel>
    </apex:outputPanel>  

    <apex:commandButton value="edit" onclick="editcontact; return false;"/>

<script>
    function isChecked(editContact){
        var con = parseInt(cont);
        isChecked(cont);
    }
</script>

                    <apex:column headerValue="Edit" >
                    <apex:inputCheckbox value="{!w.ischecked}" id="inp"/>
                </apex:column>


                <apex:column value="{!w.cont.FirstName}" />
                <apex:column value="{!w.cont.LastName}" />
                <apex:column value="{!w.cont.phone}" />
                <apex:column value="{!w.cont.email}" />

            </apex:pageBlockTable>
        </apex:pageBlockSection>

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.