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
mahishamahisha 

How to display

My Controller :

public class clsmap{
public String s{public get;public set;}
public clsmap()
{
Map<String,String> strmap=new Map<String,String>{'a'=>'apple','c'=>'cat'};
strmap.put('p','pen');
strmap.get('b');
System.debug(strmap.get('a'));
for(String s:strmap.keyset()){
if(s=='b'){
s+='cil';
system.debug(s);
}
}
}
}
My Page:
<apex:page controller="clsmap">
<apex:form >
Values:
<br/>
    <apex:outputtext value="{!s}"/><br/>
</apex:form>
</apex:page>

here i want to display a value of a string s.can any one help me pls?

Thanks
crop1645v2crop1645v2
You have a variable scoping issue here:

<pre>
public class clsmap{
public String s{public get;public set;}
public clsmap() {
  Map<String,String> strmap=new Map<String,String>{'a'=>'apple','c'=>'cat'};
  strmap.put('p','pen');
  strmap.get('b');
  System.debug(strmap.get('a'));
  for(String s:strmap.keyset()){
     if(s=='b'){
        s+='cil';
       system.debug(s);
     }
  }
 }
}

<apex:page controller="clsmap">
<apex:form >
Values:
<br/>
    <apex:outputtext value="{!s}"/><br/>
</apex:form>
</apex:page>
</pre>

In the VF page, {!s} refers to the controller property s via its getter (line 2). Yet this is never set to anything other than its default null.  Within your for loop, you declare a loop variable s that is completely different that the controller variable s in line 2.
mahishamahisha
then how can i display of s which is in for loop.pls tell me the detail
crop1645v2crop1645v2
mahisha:  Which 's' do you want to display?, the map contains three keys: 'a', 'p', and 'c'.  Do you want to show the whole map?  apex:outputText will, by itself, only display one value unless it is within an apex:repeat, apex:datatable, or apex:pageblocktable