You need to sign in to do that
Don't have an account?
Justin D
Question on output after Guard Clause (which shows error message)
I have been working on showing error messages (guard clause).
When I click the commandButton, the guard clauses (error messages) show up, but it does not retrieve the output.
So, the issue now is, data output would not showing up.
Appereciate for any help!
I have added these lines on Apex file (bold).
-----------------------------------------------------------------
public PageReference searchPatients(){
if (lname == null || lname.length() < 3)
{
ApexPages.addMessage(new ApexPages.Message(
ApexPages.Severity.ERROR, 'Please specify at least three characters of Last Name'
));
return null;
}
if (fname == null || fname.length() < 3)
{
ApexPages.addMessage(new ApexPages.Message(
ApexPages.Severity.ERROR, 'Please specify at least three characters of First Name'
));
return null;
}
String bind_fname = string.isBlank(fName) || fname.length() <3 ? null : (fname.left(3) + '%');
String bind_lname = string.isBlank(lname) || lname.length() <3 ? null : (lname.left(3) + '%');
RowList = new List<TableRow2>();
TableRow2 tr;
for(Patient__c con : [SELECT sfprn__c,
mrn__c,
LName__c,
FName__c,
(select SurveySelection__c.SurveySelection__c from SurveySelections__r)
FROM Patient__c
where ( mrn__c =:mrn )
or ( LName__c LIKE :bind_lname and FName__c LIKE :bind_fname ) LIMIT 1
]){
tr = new TableRow2();
tr.sfprn = con.sfprn__c;
tr.mrn = con.mrn__c;
tr.lname = con.LName__c;
tr.fname = con.FName__c;
tr.SurveySelection = con.SurveySelections__r.isEmpty() ? null : con.SurveySelections__r[0].SurveySelection__c;
RowList.add(tr);
}
return null;
}
_______________________________________
Bottom is VF page
<apex:pageBlock >
<!-- Search button-->
<apex:pageBlockButtons location="top">
<apex:pageMessages id="msgs" />
<apex:commandButton value="Search" action="{!searchPatients}" rerender="msgs"/>
</apex:pageBlockButtons>
<apex:pageBlockSection id="msgs" columns="1">
<!--
<apex:pageBlockSection id="contact-table" columns="1"> -->
<!-- Input starts -->
<apex:pageBlockSectionItem >
<apex:outputLabel value="MRN" />
<apex:inputText value="{!mrn}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Last Name" />
<apex:inputText value="{!lname}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="First Name" />
<apex:inputText value="{!fname}"/>
</apex:pageBlockSectionItem>
<!-- Input ends -->
<!-- Output starts --->
<apex:pageBlockTable value="{!RowList}" var="c">
<apex:column >
<apex:facet name="header">MRN</apex:facet>
{!c.mrn}
</apex:column>
<apex:column >
<apex:facet name="header">Last Name</apex:facet>
{!c.lname}
</apex:column>
<apex:column >
<apex:facet name="header">First Name</apex:facet>
{!c.fname}
</apex:column>
</apex:pageBlockTable>
<!-- Output ends --->
</apex:pageBlock>
When I click the commandButton, the guard clauses (error messages) show up, but it does not retrieve the output.
So, the issue now is, data output would not showing up.
Appereciate for any help!
I have added these lines on Apex file (bold).
-----------------------------------------------------------------
public PageReference searchPatients(){
if (lname == null || lname.length() < 3)
{
ApexPages.addMessage(new ApexPages.Message(
ApexPages.Severity.ERROR, 'Please specify at least three characters of Last Name'
));
return null;
}
if (fname == null || fname.length() < 3)
{
ApexPages.addMessage(new ApexPages.Message(
ApexPages.Severity.ERROR, 'Please specify at least three characters of First Name'
));
return null;
}
String bind_fname = string.isBlank(fName) || fname.length() <3 ? null : (fname.left(3) + '%');
String bind_lname = string.isBlank(lname) || lname.length() <3 ? null : (lname.left(3) + '%');
RowList = new List<TableRow2>();
TableRow2 tr;
for(Patient__c con : [SELECT sfprn__c,
mrn__c,
LName__c,
FName__c,
(select SurveySelection__c.SurveySelection__c from SurveySelections__r)
FROM Patient__c
where ( mrn__c =:mrn )
or ( LName__c LIKE :bind_lname and FName__c LIKE :bind_fname ) LIMIT 1
]){
tr = new TableRow2();
tr.sfprn = con.sfprn__c;
tr.mrn = con.mrn__c;
tr.lname = con.LName__c;
tr.fname = con.FName__c;
tr.SurveySelection = con.SurveySelections__r.isEmpty() ? null : con.SurveySelections__r[0].SurveySelection__c;
RowList.add(tr);
}
return null;
}
_______________________________________
Bottom is VF page
<apex:pageBlock >
<!-- Search button-->
<apex:pageBlockButtons location="top">
<apex:pageMessages id="msgs" />
<apex:commandButton value="Search" action="{!searchPatients}" rerender="msgs"/>
</apex:pageBlockButtons>
<apex:pageBlockSection id="msgs" columns="1">
<!--
<apex:pageBlockSection id="contact-table" columns="1"> -->
<!-- Input starts -->
<apex:pageBlockSectionItem >
<apex:outputLabel value="MRN" />
<apex:inputText value="{!mrn}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="Last Name" />
<apex:inputText value="{!lname}"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputLabel value="First Name" />
<apex:inputText value="{!fname}"/>
</apex:pageBlockSectionItem>
<!-- Input ends -->
<!-- Output starts --->
<apex:pageBlockTable value="{!RowList}" var="c">
<apex:column >
<apex:facet name="header">MRN</apex:facet>
{!c.mrn}
</apex:column>
<apex:column >
<apex:facet name="header">Last Name</apex:facet>
{!c.lname}
</apex:column>
<apex:column >
<apex:facet name="header">First Name</apex:facet>
{!c.fname}
</apex:column>
</apex:pageBlockTable>
<!-- Output ends --->
</apex:pageBlock>