You need to sign in to do that
Don't have an account?
balu palavalasa
error in adding select options
hi All,
I've witten a code which has to take input from an input box and add the input to select options until submit button is pressed.
that is as long as i give input and click on add button it should keep on adding the given input texts to select option list. and if i click on submit button it should display the selectoptions list.
vf code :
<apex:page Controller="selectlistoption">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:outputlabel value="Enter Country"/>
<apex:inputText value="{!str}"/>
<apex:commandButton value="Add" action="{!setCountry}"/>
<apex:commandButton value="submit" rerender="showdetails"/>
</apex:pageBlockSection>
<apex:pageBlockSection id="showdetails">
<apex:selectlist size="1" value="{!str}">
<apex:selectoptions value="{!country}"/>
</apex:selectlist>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller :
public class selectlistoption {
public string str{get;set;}
public list<selectoption> country{get;set;}
public pagereference setCountry()
{
country.add(new selectoption(str,str));
return null;
}
}
Error :
System.NullPointerException: Argument 1 cannot be null
Error is in expression '{!setCountry}' in component <apex:commandButton> in page selectlist: Class.selectlistoption.setCountry: line 11, column 1
Class.selectlistoption.setCountry: line 11, column 1
I've witten a code which has to take input from an input box and add the input to select options until submit button is pressed.
that is as long as i give input and click on add button it should keep on adding the given input texts to select option list. and if i click on submit button it should display the selectoptions list.
vf code :
<apex:page Controller="selectlistoption">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:outputlabel value="Enter Country"/>
<apex:inputText value="{!str}"/>
<apex:commandButton value="Add" action="{!setCountry}"/>
<apex:commandButton value="submit" rerender="showdetails"/>
</apex:pageBlockSection>
<apex:pageBlockSection id="showdetails">
<apex:selectlist size="1" value="{!str}">
<apex:selectoptions value="{!country}"/>
</apex:selectlist>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller :
public class selectlistoption {
public string str{get;set;}
public list<selectoption> country{get;set;}
public pagereference setCountry()
{
country.add(new selectoption(str,str));
return null;
}
}
Error :
System.NullPointerException: Argument 1 cannot be null
Error is in expression '{!setCountry}' in component <apex:commandButton> in page selectlist: Class.selectlistoption.setCountry: line 11, column 1
Class.selectlistoption.setCountry: line 11, column 1
Pradeep Singh
Hi, Please use below code:-