+ Start a Discussion
KeithJKeithJ 

inputText required="true" not working

Hi there.My inputText field in my vf page is renderd like so:

 

 

 

but in my vf code I have 

<apex:pageBlockSectionItem > <apex:outputLabel value="Title" for="titleField" /> <apex:inputText value="{!title}" required="true" id="titleField" style="width: 200px;" /> </apex:pageBlockSectionitem>

 

Where you can see that the inputText is required=true but it's not showing up on my vf page.

This field binds to a String property in my custom controller that's called title

 

Thanks for the help & regards

 

Best Answer chosen by Admin (Salesforce Developers) 
devNut!devNut!

 I believe it should look something like this.  The"value" is bound to a string array which will contain the selected values.

 

VF page

<apex:page controller="samplecon">
<apex:form >
<apex:selectList value="{!countries}" multiselect="false">
<apex:selectOptions value="{!items}"/>
</apex:selectList><p/>
<apex:commandButton value="Test" action="{!test}" rerender="out" status="status"/>
</apex:form>
</apex:page>

 

 

 

Your controller:

public class samplecon {
String[] countries = new String[]{};
public PageReference test() {
return null;
}
public List<SelectOption> getItems() {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('US','US'));
options.add(new SelectOption('CANADA','Canada'));
options.add(new SelectOption('MEXICO','Mexico'));
return options;
}
public String[] getCountries() {
return countries;
}
public void setCountries(String[] countries) {
this.countries = countries;
}

}

 

 

All Answers

devNut!devNut!

 There are a couple of threads related to your issue:

 

link 1

 

Link 2

KeithJKeithJ

Thanks devNut!

One other thing instead of starting a new thread:

if you have a selectList with attribute multiselect="true"

do you know how you can capture multiple selected values?

 

In my controller, I tried binding my selectList to a List and a string, but these

can't seem to be able to handle multiple selected values.

Any ideas?
Thanks again

devNut!devNut!

 I believe it should look something like this.  The"value" is bound to a string array which will contain the selected values.

 

VF page

<apex:page controller="samplecon">
<apex:form >
<apex:selectList value="{!countries}" multiselect="false">
<apex:selectOptions value="{!items}"/>
</apex:selectList><p/>
<apex:commandButton value="Test" action="{!test}" rerender="out" status="status"/>
</apex:form>
</apex:page>

 

 

 

Your controller:

public class samplecon {
String[] countries = new String[]{};
public PageReference test() {
return null;
}
public List<SelectOption> getItems() {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('US','US'));
options.add(new SelectOption('CANADA','Canada'));
options.add(new SelectOption('MEXICO','Mexico'));
return options;
}
public String[] getCountries() {
return countries;
}
public void setCountries(String[] countries) {
this.countries = countries;
}

}

 

 

This was selected as the best answer
KeithJKeithJ

I see. That's pretty strange because I would've imagined a List would do it.

Wouldn't work out for me. Thanks again for your help and your time!

KeithJKeithJ

That works great for capturing the selected values of a multiselectpicklist.

But how would one actually set them in the sobject field explicitly?

For example, if you imagine that there was an SObject field called Country which was a 

multiselectpicklist, how can you set the values explicitly after you have captured the

values for the apex selectlist?

 

If you say Country__c = countries;

this isn't going to work.

Any ideas?
Thank you very much

devNut!devNut!

Ultimately a multi-select picklist in salesforce saves the selected values in a semi-colon delimited string.

 

 

You can build a semi-colon delimited string of the values in the countries array.

 

Then you would save this semi-colon delimited string to the salesforce database, using Country__c = countriesSemiColonString;

 

KeithJKeithJ

Brilliant!

Thank you very much. :)

 

Where did you find this information btw?