You need to sign in to do that
Don't have an account?
Abdul Mujeeb Shaik
I need SYNTAX to read the SelectedValues (selectList value) in picklist (selectoptions) which is in <APEX:REPEAT>
I need SYNTAX to read the SelectedValues (selectList value)
in picklist (selectoptions) which is in <APEX:REPEAT>
===
objectivetype: "yes, no, Maybe, dontknow"
===
in picklist (selectoptions) which is in <APEX:REPEAT>
===
objectivetype: "yes, no, Maybe, dontknow"
===
My VF code: ------------------- <table border="1" width="100%"> <apex:REPEAT value="{!ques}" var="singleQuestion"> <tr> <td> {!singleQuestion} </td> <td> <apex:selectList value="{!Selectedvalues}" size="1"> <apex:selectoptions value="{!objectivetype}" /> </apex:selectList> </td> </tr> </apex:repeat> </table> ===================== In Controller: -------------- public List<String> Selectedvalues{get; set;}
In the controller, if you need to access the value in a method, directly use Selectedvalues there. Also, Selectedvalues gives you a String value, not a List<String>, so the SelectValues variable should be defined as:
public String Selectedvalues{get; set;}
But I can see here, you are repeating some questions and the list of answers and you must be wanting a Question Answer pair.
I have created a Visualforce Page and controller. On clicking the Submit Button on the page, you can see a Map of Question and its answer.
You can use this and do the further processing.
Please find below the Page:
<apex:page controller="Questions_Controller">
<apex:form >
<table border="1" width="100%">
<apex:repeat value="{!ques}" var="singleQuestion">
<tr>
<td>{!singleQuestion}</td>
<td>
<apex:actionRegion >
<apex:selectList value="{!Selectedvalues}" size="1">
<apex:selectoptions value="{!objectivetype}" />
<apex:actionSupport event="onchange" action="{!populateAnswers}" reRender="dummy">
<apex:param assignTo="{!answeredQuestion}" value="{!singleQuestion}" name="answeredQuestion"/>
</apex:actionSupport>
</apex:selectList>
</apex:actionRegion>
</td>
</tr>
</apex:repeat>
</table>
<apex:commandButton value="Submit" action="{!submitAnswers}" rerender="dummy"/>
</apex:form>
</apex:page>
Please find below the controller:
public class Questions_Controller
{
public List<SelectOption> objectivetype{get; set;}
public String Selectedvalues{get; set;}
public List<String> ques{get; set;}
private Map<String, String> questionAnswerMap;
public String answeredQuestion{get; set;}
public Questions_Controller()
{
ques=new List<String>();
ques.add('Question 1');
ques.add('Question 2');
objectivetype=new List<SelectOption>();
objectivetype.add(new SelectOption('yes', 'yes'));
objectivetype.add(new SelectOption('no', 'no'));
objectivetype.add(new SelectOption('Maybe', 'Maybe'));
objectivetype.add(new SelectOption('dontknow', 'dontknow'));
questionAnswerMap=new Map<String, String>();
}
public void populateAnswers()
{
questionAnswerMap.put(answeredQuestion, Selectedvalues);
Selectedvalues=Null;
}
public void submitAnswers()
{
system.debug('questionAnswerMap---->'+questionAnswerMap);
Selectedvalues=Null;
}
}
Please let me know if this helps. If yes, please mark the answer as solved.
Thanks and Regards,
Anirudh Singh
All Answers
In the controller, if you need to access the value in a method, directly use Selectedvalues there. Also, Selectedvalues gives you a String value, not a List<String>, so the SelectValues variable should be defined as:
public String Selectedvalues{get; set;}
But I can see here, you are repeating some questions and the list of answers and you must be wanting a Question Answer pair.
I have created a Visualforce Page and controller. On clicking the Submit Button on the page, you can see a Map of Question and its answer.
You can use this and do the further processing.
Please find below the Page:
<apex:page controller="Questions_Controller">
<apex:form >
<table border="1" width="100%">
<apex:repeat value="{!ques}" var="singleQuestion">
<tr>
<td>{!singleQuestion}</td>
<td>
<apex:actionRegion >
<apex:selectList value="{!Selectedvalues}" size="1">
<apex:selectoptions value="{!objectivetype}" />
<apex:actionSupport event="onchange" action="{!populateAnswers}" reRender="dummy">
<apex:param assignTo="{!answeredQuestion}" value="{!singleQuestion}" name="answeredQuestion"/>
</apex:actionSupport>
</apex:selectList>
</apex:actionRegion>
</td>
</tr>
</apex:repeat>
</table>
<apex:commandButton value="Submit" action="{!submitAnswers}" rerender="dummy"/>
</apex:form>
</apex:page>
Please find below the controller:
public class Questions_Controller
{
public List<SelectOption> objectivetype{get; set;}
public String Selectedvalues{get; set;}
public List<String> ques{get; set;}
private Map<String, String> questionAnswerMap;
public String answeredQuestion{get; set;}
public Questions_Controller()
{
ques=new List<String>();
ques.add('Question 1');
ques.add('Question 2');
objectivetype=new List<SelectOption>();
objectivetype.add(new SelectOption('yes', 'yes'));
objectivetype.add(new SelectOption('no', 'no'));
objectivetype.add(new SelectOption('Maybe', 'Maybe'));
objectivetype.add(new SelectOption('dontknow', 'dontknow'));
questionAnswerMap=new Map<String, String>();
}
public void populateAnswers()
{
questionAnswerMap.put(answeredQuestion, Selectedvalues);
Selectedvalues=Null;
}
public void submitAnswers()
{
system.debug('questionAnswerMap---->'+questionAnswerMap);
Selectedvalues=Null;
}
}
Please let me know if this helps. If yes, please mark the answer as solved.
Thanks and Regards,
Anirudh Singh
Hello Anirudha,
Can i set default values for each selectlsit value....in a repeat tag.
I mean, in detail..,
can i set 'YES' fro some fileds and 'NO' for some fileds and 'May be' and remaining 'DonKnow'
based on some condion ....for example
if 'singleQuesthion' ==' do_u_like_this_event '.....then for that
<apex:selectList value="{!SELECTEDVALUES}" size="1"> should be'YES' "default values should be this.(in apex repeat tag)
if 'singleQuesthion' ==' do_u_like_to_appy_now '.....then fro that
SELECTEDVALUES should be 'NO'
if 'singleQuesthion' ==' r_u_intrested_in_doing_business '.....then fro that
SELECTEDVALUES should be 'May be'
.
.
.
Like this...based on some condition of 'Single Question' automatically corresponding default values must appear in
apex:selectlsit value.....which is in apex:repeat tag.
I hope you are still looking for the answer.
Yes, it is possible to set the default values. But it requires JavaScript.
The things to notice are below:
1. The submitAnswers method is now being called from JavaScript, and it is a RemoteAction static method.
You will need to do the further processing inside the method itself.
Also, since the method is static, you will not be able to use any non-static variables or methods inside it, and you will have to use only static methods or variables inside it.
2. Also, the 'ques' is now a Map instead of List, it is used to hold the Question as key and the default answer as value.
Don't forget to put all your questions like this only and give defualt answer values for all the questions. So, if you have 10 questions, put all the 10 and their default values. Please let me know if this helps.
Thanks and Regards,
Anirudh Singh