2013-02-11 6 views
7

मेरे पास एक डेटा तालिका है जो कस्टम ऑब्जेक्ट के माध्यम से पुनरावृत्ति करती है और चेकबॉक्स उत्पन्न करती है। दूसरे पृष्ठ पर, मैं यह निर्धारित करना चाहता हूं कि इनमें से कौन से चेकबॉक्स चुने गए हैं।विजुअलफॉर्स में अगले पृष्ठ पर कौन से चेकबॉक्स चयनित किए गए हैं, यह जानने के लिए कैसे?

VisualForce पेज में:

Age <apex:inputText value="{!age}" id="age" /> 
<apex:dataTable value="{!Areas}" var="a"> 
     <apex:column > 
     <apex:inputCheckbox value="{!a.name}" /> <apex:outputText value="{!a.name}" /> 
     </apex:column> 
    </apex:dataTable> 

नियंत्रक में:

public String age {get; set; } 
    public List<Area_Of_Interest__c> getAreas() { 
     areas = [select id, name from Area_Of_Interest__c]; 
     return areas; 
    } 

मेरे दूसरे पृष्ठ पर, मैं मान प्राप्त कर सकता है कि उपयोगकर्ता {!age} का उपयोग करके पाठ बॉक्स "उम्र" में डाल । मैं कैसे पुनर्प्राप्त करूं कि कौन से चेकबॉक्स चेक किए गए हैं?

धन्यवाद।

उत्तर

4

ठीक है, अगर आप इसे जावास्क्रिप्ट से संभालना चाहते हैं, तो पावेल की विधि का उपयोग करें, अन्यथा नियंत्रक के माध्यम से इसे करने के लिए निम्न का उपयोग करें। जो भी आप ट्रैक करना चाहते हैं उसके लिए आपको एक रैपर क्लास बनाना होगा। मुझे यकीन नहीं है कि यह कैसे काम करता है, लेकिन किसी भी तरह यदि आप अपने रैपर वर्ग में "चुने गए" बूलियन वैरिएबल का नाम देते हैं, तो इसे चेकबॉक्स में मैप किया जाता है।नीचे दिए गए कोड है:

अपने दृश्य बल पेज में

तो, कार्य करें:

<apex:dataTable value="{!Foos}" var="f"> 
    <apex:column > 
     <apex:outputLabel value="{!f.foo.name}" /> <apex:inputCheckbox value="{!f.selected}" /> 
    </apex:column> 
</apex:dataTable> 
<apex:commandButton action="{!getPage2}" value="go"/> 

अपने नियंत्रक में, निम्न करें: 1) एक आवरण वर्ग बूलियन "चयनित" के साथ है, जो किसी भी तरह के नक्शे inputCheckbox चयनित करने के लिए:

public class wFoo { 
    public Foo__c foo {get; set} 
    public boolean selected {get; set;} 

    public wFoo(Foo__c foo) { 
     this.foo = foo; 
     selected = false; //If you want all checkboxes initially selected, set this to true 
    } 
} 

2) सूची चर घोषित

public List<wFoo> foos {get; set;} 
public List<Foo__c> selectedFoos {get; set;} 

3) सूची

public List<wFoo> getFoos() { 
    if (foos == null) { 
     foos = new List<wFoo>(); 
     for (Foo__c foo : [select id, name from Foo__c]) { 
      foos.add(new wFoo(foo)); 
     } 
    } 
    return foos; 
} 

4 के लिए एक्सेसर परिभाषित करें) चेकबॉक्स चयनित की प्रक्रिया और एक अन्य पेज

public void processSelectedFoos() { 
    selectedFoos = new List<Foo__c>(); 
    for (wFoo foo : getFoos) { 
     if (foo.selected = true) { 
      selectedFoos.add(foo.foo); // This adds the wrapper wFoo's real Foo__c 
     } 
    } 
} 

5) पर इस्तेमाल के लिए एक सूची में उन्हें जगह करने के लिए विधि को परिभाषित विधि को परिभाषित करें सबमिट पेज पर क्लिक करने पर अगले पृष्ठ पर पेजरफेरेंस वापस करें

public PageReference getPage2() { 
    processSelectedFoos(); 
    return Page.Page2; 
} 
3

मेरी वर्तमान परियोजना में मुझे एक ही समस्या का सामना करना पड़ा था। मैं सुप्रीम प्रयोग किया है: pageBlockTable, लेकिन मुझे लगता है कि कि तुम मेरी कोड का उपयोग कर सकते

<apex:pageBlockTable value="{!Areas}" var="areas"> 
    <apex:column width="25px"> 
     <apex:facet name="header"> 
      <input type="checkbox" onClick="selectAll();" /> 
     </apex:facet> 
     <input type="checkbox" id="{!areas.Id}" onClick="saveSelection();" /> 
    </apex:column> 
... some additional columns 
</apex:pageBlockTable> 

मैं html में इनपुट आईडी के लिए कस्टम वस्तु आईडी रखा था (मैं एक वस्तु के नाम के लिए मेरे कोड में कुछ परिवर्तन किए), और यह लग

<input id="003R000000lCIq6IAG" onclick="saveSelection();" type="checkbox"> 
<input id="003R000000lCIoJIAW" onclick="saveSelection();" type="checkbox"> 

रूप saveSelection() फ़ंक्शन जावास्क्रिप्ट

<script> 
var areaIds = []; 

function saveSelection() { 
    var selectedIds = areaIds.join(''); 
    $j(':checkbox').each(function(){ 
     if (this.checked) { 
      if (selectedIds.indexOf(this.id) === -1) { 
       areaIds.push(this.id); 
       selectedIds = selectedIds + this.id; 
      } 
     } else { 
      if (selectedIds.indexOf(this.id) !== -1) { 
       for (i=0; i < areaIds.length; i++) { 
        if (areaIds[i] === this.id) { 
         areaIds.splice(i, 1); 
         selectedIds = areaIds.join(''); 
        } 
       } 
      } 
     }      
    }); 
} 

पर और के लिए लिखा है बहाल करने के लिए निम्न कोड

इस्तेमाल किया गया था
function restoreSelection() { 
    contIds = areaIds.join(''); 
    i = 0; 
    $j(':checkbox').each(function(){ if(this.id !== ''){ if(contIds.indexOf(this.id) !== -1){this.checked=true;};}}); 

} 

मैं jQuery यहाँ का उपयोग करें, इसका मतलब है कि आप अपने पृष्ठ भी

<apex:includeScript id="JQuery" value="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"/> 
... some code 
<script> 
    window.$j = jQuery.noConflict(); 
    ... some code 
</script> 

js भी पृष्ठांकन बटन से शामिल है के लिए निम्न कोड शामिल करना चाहिए:

<apex:panelGrid columns="7"> 
    <apex:commandButton status="fetchStatus" reRender="results" value="|<" action="{!first}" disabled="{!!hasPrevious}" title="First Page" onClick="saveSelection();" oncomplete=" restoreSelection()"/> 
    <apex:commandButton status="fetchStatus" reRender="results" value="<" action="{!previous}" disabled="{!!hasPrevious}" title="Previous Page" onClick="saveSelection();" oncomplete="restoreSelection()"/> 
    <apex:commandButton status="fetchStatus" reRender="results" value=">" action="{!next}" disabled="{!!hasNext}" title="Next Page" onClick="saveSelection();" oncomplete=" restoreSelection()"/> 
    <apex:commandButton status="fetchStatus" reRender="results" value=">|" action="{!last}" disabled="{!!hasNext}" title="Last Page" onClick="saveSelection();" oncomplete=" restoreSelection()" /> 
    <apex:outputText >{!(pageNumber * size)+1-size}-{!IF((pageNumber * size)>noOfRecords, noOfRecords,(pageNumber * size))} of {!noOfRecords}</apex:outputText> 
    <apex:outputPanel style="color:#4AA02C;font-weight:bold"> 
     <apex:actionStatus id="fetchStatus" startText="Fetching..." stopText=""/> 
    </apex:outputPanel> 
</apex:panelGrid> 

मुझे आशा है कि यह हो सकता है आपकी मदद।

+0

बिल्कुल सही अवधारणा और कार्यान्वयन! धन्यवाद @ पावेल – highfive

संबंधित मुद्दे

 संबंधित मुद्दे