function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MG ConsultingMG Consulting 

Adding an Error Message to an InputText Component



I have inputText components along side inputField components in a form and thus I would like to be able to display errors associated with inputText components next to them via the message component. Right now, I am forced to display them in the messages component at the bottom of the form. This is awkard, and not ideal, because if an inputField has an error it displays next to it and if an inputText has an error it displays it at the bottom of the form.



It seems the only error you can get to display in the message component for an inputText is the standard required message by setting required equal to true.



Is there anyway to add custom error messages associated with a specific inputText component like I can with inputFields?



Thanks a lot,


Try a validation rule or make an extension to the standard controller with the .adderror method of the Sobject class
MG ConsultingMG Consulting
Unfortunately, the inputText components in question, are not bound to sObject fields.
Try Page.addmessages
MG ConsultingMG Consulting

That method doesn't  allow you to associate the message with a specific component.


Clearly, there must be some way to do it, because when you mark Required as true on the inputText component that error message displays in the message component associated with it. This happens regardless of whether not the inputText component is bound to an sObject field or not.


My only guess is that the method to do so is an internal method that is not exposed to developers.

I think the solution will come from finding a good example of the difference between <apex:messages and <apex:message   The singular should allow you to target a component.