inputCheckbox 和 commandLink/commandButton 不能一起工作!!
情况1:
试试代码。
这个中的 visualforce 动作不起作用。
<apex:commandLink action="{!SelectTicket}" reRender="outputPanel">
<apex:inputCheckbox value="{!ordsOptions[o]}"/>
<apex:param name="selected" value="{!o.id}" assignTo="{!selected}"/>
</apex:commandLink>
没有
value="{!ordsOptions[o]}"在输入复选框中。几乎相同的代码工作正常。
<apex:commandLink action="{!SelectTicket}" reRender="outputPanel">
<apex:inputCheckbox/>
<apex:param name="selected" value="{!o.id}" assignTo="{!selected}"/>
</apex:commandLink>
案例二:
在另一列中添加 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>
如果没有 inputCheckbox 和 commandLink,它就可以正常工作:
<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>
全部代码
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 />
<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>
<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>
班级:
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() {
for(Custom_Object__c tmp : ords) if(tmp.Id == selected) ordsOptions.put(tmp.Id, true); else ordsOptions.put(tmp.Id, false);
return null;
}
public PageReference rSfdc() {
PageReference rp = new PageReference('http://www.salesforce.com');
rp.setRedirect(true);
return rp;
}
}