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
SuperdomeSuperdome 

Strange Bug of the apex:inputCheckbox

Try the codes.

 

With value=.... in the apex:inputCheckbox, all of the commandLink and commandButton doesn't work.

 

Even the commandButton in the case, it is not related to the inputCheckbox at all. But it is just unable to open the pageReference url as it should be.

 

Without value=.... the commandLink and commandButton just works fine.

 

Is it bug ?

 

VF:

 

<apex:page controller="SelectRadio" sidebar="false">
    <apex:outputPanel id="outputPanel">
    <apex:form >
        <apex:dataTable border="4" value="{!ords}" var="o">
            <apex:column >
                <apex:commandLink action="{!SelectTicket}" reRender="outputPanel">
                    <apex:inputCheckbox value="{!ordsOptions[o]}"/>
                    <apex:param name="selected" value="{!o.id}" assignTo="{!selected}"/>
                </apex:commandLink>
            </apex:column>
            <apex:column value="{!o.Id}"/>
            <apex:column value="{!o.Name}"/>
        </apex:dataTable>
        <apex:commandButton action="{!rSfdc}" value="按鍵"/>
    </apex:form>
    <hr/>
    <h1>Debug</h1>
        <p>ordsOptions = {!ordsOptions}</p>
        <p>ordsOptionName = {!ordsOptionName}</p>
        <p>selected = {!selected}</p>
    </apex:outputPanel>
</apex:page>

 Class:

public with sharing class SelectRadio {

    public List<String> vars {get;set;}
    public List<Custom_Object__c> ords {get; set;}
    public Map<Id,Boolean> ordsOptions {get; set;}
    public Map<Id,String> ordsOptionName {get; set;}
    public Id selected {get;set;}
    
    public SelectRadio(){
        ordsOptions = new Map<Id,Boolean>();
        ordsOptionName = new Map<Id,String>();
        ords = [ SELECT Id, Name FROM Custom_Object__c ORDER BY Name ];
        for (Custom_Object__c tmp : ords) {
            ordsOptions.put(tmp.Id, false);
            ordsOptionName.put(tmp.Id, tmp.Name);
        }
    }

    public pageReference SelectTicket() {
        return null;
    }

    public PageReference rSfdc() {
        PageReference rp = new PageReference('http://www.salesforce.com');
        rp.setRedirect(true);
        return rp;
    }
}

 

SuperdomeSuperdome

The same case, and new findings.....

 

It looks really like a bug.

 

It doesn't work at all when add the inputCheckbox in another column.

 

        <apex:dataTable border="4" value="{!ords}" var="o">
            <apex:column >
                <apex:commandLink action="{!SelectTicket}" reRender="outputPanel">
                    <apex:inputCheckbox />
                    <apex:param name="selected" value="{!o.id}" assignTo="{!selected}"/>
                </apex:commandLink>
            </apex:column>
            <apex:column ><apex:inputCheckbox value="{!ordsOptions[o]}"/></apex:column>
            <apex:column ><apex:outputText value="{!ordsOptions[o]}"/></apex:column>
            <apex:column value="{!o.Id}"/>
            <apex:column value="{!o.Name}"/>
        </apex:dataTable>

 

The almost same code just works fine, and it can work if and only if DON'T USE inputCheckbox

 

        <apex:dataTable border="4" value="{!ords}" var="o">
            <apex:column >
                <apex:commandLink action="{!SelectTicket}" reRender="outputPanel">
                    <apex:inputCheckbox />
                    <apex:param name="selected" value="{!o.id}" assignTo="{!selected}"/>
                </apex:commandLink>
            </apex:column>
<!--            <apex:column ><apex:inputCheckbox value="{!ordsOptions[o]}"/></apex:column> -->
            <apex:column ><apex:outputText value="{!ordsOptions[o]}"/></apex:column>
            <apex:column value="{!o.Id}"/>
            <apex:column value="{!o.Name}"/>
        </apex:dataTable>

 

SuperdomeSuperdome

Finally, I found myself the answer.

 

It's not a bug at all !!

 

It can be used as the function of selectRadio and more flexible than the selectRadio.

 

The sample pattern is easily to use with apex:dataTable and apex:repeat.

 

The workable pattern code:

 

vf:

<apex:page controller="SelectRadio" sidebar="false">
    <apex:outputPanel id="outputPanel">
    <apex:form >

        <apex:dataTable border="4" value="{!Ids}" var="o">
            <apex:column >
                <apex:commandLink action="{!selectThisOne}" reRender="outputPanel">
                    <apex:inputCheckbox value="{!ordsOptions[o]}"/>
                    <apex:param name="selected" value="{!o}"/>
                </apex:commandLink>
            </apex:column>
            <apex:column value="{!o}"/>
            <apex:column value="{!ordsOptionName[o]}"/>
            
        </apex:dataTable>
        <apex:commandButton value="按鍵"/>
 
    </apex:form>

        <p>ordsOptions = {!ordsOptions}</p>
        <p>ordsOptionName = {!ordsOptionName}</p>
        <p>selected = {!selected}</p>
    </apex:outputPanel>
</apex:page>

 class:

public with sharing class SelectRadio {

    public List<String> Ids {get;set;}
    public List<Custom_Object__c> ords {get; set;}
    public Map<Id,Boolean> ordsOptions {get; set;}
    public Map<Id,String> ordsOptionName {get; set;}
    public String str {get;set;}
    public Id selected {get;set;}
    
    public SelectRadio(){
        ordsOptions = new Map<Id,Boolean>();
        ordsOptionName = new Map<Id,String>();
        Ids = new List<String>();
        ords = [ SELECT Id, Name FROM Custom_Object__c ORDER BY Name ];
        for (Custom_Object__c tmp : ords) {
            Ids.add(tmp.Id);
            ordsOptions.put(tmp.Id, false);
            ordsOptionName.put(tmp.Id, tmp.Name);
        }
    }
    
    public PageReference selectThisOne(){
        selected = ApexPages.CurrentPage().getParameters().get('selected');
        for (String tmp : Ids) {
            if(tmp == selected) ordsOptions.put(tmp, true); else ordsOptions.put(tmp, false);
        }
        return null;
    }
}