You need to sign in to do that
Don't have an account?
Krishna Prasad K P
Problem with this code is that, if the user skips the TeamRole for the second or third input row, the message shows near the Team Role input field in the FIRST input row.
How to show Error message near an inputField using custom controller
Hi,
I have made a Visualforce page and custom controller for mass adding Sales Team Members for Opportunities.
I used a newly created list of 5 OpportunityTeamMember records(to be inserted) for iteratively dispalying 5 input sets as in the standard Add Sales Team Page.
I wish to have a validation rule which, when the "Save" button is clicked, should add an error message near the TeamRole field of the if it is null.
I tried by the code
Code:
<apex:pageBlockTable value="{!OpportunityTeamMemberList}" var="TeamMember"> .......................... <apex:column headerValue="Team Role"> <apex:inputField id="inputTeamRole" value="{!TeamMember.TeamMemberRole}" /> </apex:column> ............................ </apex:pageBlockTable>
Code:
if(MyTeamMemberList[index].TeamMemberRole==null) { MyTeamMemberList[index].TeamMemberRole.addError('You must enter a value'); ......... }
Problem with this code is that, if the user skips the TeamRole for the second or third input row, the message shows near the Team Role input field in the FIRST input row.
How can I add an Error message near theTeam Role inputField of the REQUIRED input row?
Can I use ApexPages.addMessage to input component of the SPECIFIC input row?
Thanks in advance
Krishna
Krishna
If all you are trying to do is make an inputField required and then "when the 'Save' button is clicked...add an error message near the TeamRole field of the if it is null" there's a built-in Visualforce attribute for that called required. You don't need to do anything in your controller. Just do this:
Message Edited by ptepper on 09-02-2008 03:43 PM
You could do a workaround, using some variables to store individual error messages and displaying them as outputFields, rendering them only if the vars are set with error messages.
-paul
Were you able to show the error at the right position. If yes, it would be great if you could post the solution in this thread.
If not, can anyone else help us find the solution.
The problem is:
Whenever we are iterating through an object and displaying its properties in a page block table and if there is a validation error, then I want that error to show up just below that field.
Currently, I am using addError() on a particular field in the controller and inputField in the page. However, the page always displays the error on the first row irrespective of which row the error has taken place.
Controller:
obj1[i].field1.addError('Error');
Page:
<apex:pageBlockTable id="orderTable" value="{!orderItems}" var="orderItem" styleClass="list" headerClass="headerRow">
<apex:column>
<apex:facet name="header">
<apex:outputText value="Field1"/>
</apex:facet>
<apex:inputField Id="field1" value="{!obj1.field1}" required="false"/>
</apex:column>
</apex:pageBlockTable>
Hi Krishna,
I was trying for the same thing, But i was not able to get the error message in the page block table, can you help me how were you able to get a error message on the field used/dispayed in pageblocktable.
Thanks much in advance,
Sanjay
Has anybody found a solution?
To paraphrase, the question is: When you enable editing through a list controller, how do you get any on-save error messages to be displayed only on the record(s) that have an error? The <apex:message> and <apex:messages> tags do not appear to work within a <apex:pageBlockTable> tag for this purpose.
Unless there is a solution, then editing in lists is essentially unusable, because there's no way to provide a user with feedback about which specific row triggered an error.
This is related to the following two pages of documentation.
Visualforce Developer's Guide, version 24.0