I am displaying fields from fieldset on VF page using repeat, but I am unable to validate the emptiness of required field. I want to display error message in case of empty required field.
VF Page:
<apex:page controller="IncidentDetails">
<apex:form >
<apex:commandButton value="{!$Label.SSSubmit}" title="{!$Label.SS_ProfileSubmit} (Ctrl+Alt+S)" action="{!saveUserProfile}" />
<apex:repeat value="{!fields}" var="f">
<table>
<tr>
<td valign="top" align="left" width="120px">
<apex:outputText value="{!f.Label}" />
<apex:outputText value="*" style="color:red;" rendered="{!OR(f.DBRequired, f.required)}" />
</td>
<td valign="top" align="left" title="{!$ObjectType.User.fields[f].inlineHelpText}">
<apex:inputField value="{!userobj[f.fieldPath]}"
required="{!OR(f.required, f.dbrequired)}"/>
</td>
</tr>
</table>
</apex:repeat>
</apex:form>
</apex:page>
Controller:
public class IncidentDetails{
public User userobj { get; set; }
public string userid { get; set; }
public Integer i{get; set;}
public IncidentDetails() {
this.userobj = getUserDetails();
}
public List<Schema.FieldSetMember> getFields() {
return SObjectType.User.FieldSets.Self_Service_My_Profile.getFields();
}
private User getUserDetails() {
userid = UserInfo.getUserId();
String query = 'SELECT ';
for(Schema.FieldSetMember f : this.getFields()) {
query += f.getFieldPath() + ', ';
}
query += 'Id FROM User where Id=:userid LIMIT 1';
return Database.query(query);
}
public PageReference saveUserProfile(){
system.debug('saveuser');
try{
update userobj;
system.debug('in update');
}catch(DMLException e){
system.debug('in exception');
}
return null;
}
}
Commandbutton
does not follow action function in case of I try to save the record with empty required field. Even 'Update' operation doesn't give exception in above case.