setErrorForComponentID()
The sysLib.setErrorForComponentID() system function associates a message with a field in a JSF handler.
The association is based on the ID of a component on the web page. If a JSF handler invokes the function, the message is placed at the location of a message or messages tag in the JSP.
The message is displayed when the related web page is displayed. You can use this function as part of a validation routine, or use it for informational messages.
If a validation function invokes sysLib.setErrorForComponentID(), the web page is redisplayed automatically when the function ends.
You can associate multiple messages with a component. If the JSF handler runs a forward statement, the messages are lost.
Syntax
sysLib.setErrorForComponentID(
componentID STRING in,
msgKey STRING in
[, msgInserts STRING in])
- componentID
- The ID of a component on the web page with which you want to associate
the message, in the form
formName:componentName, where formName is the ID of the form containing the component and componentName is the ID of the component. - msgKey
- Input can be any variable or expression that is assignment compatible with the STRING type. The msgKey provides the key into the message resource bundle or properties file used at run time. If the key is blank, the message is a concatenation of all messages in the file.
- msgInserts
- Input can be one or more variables or expressions that are assignment
compatible with the STRING type. Each of the msgInserts is
inserted into the output message. The substitution symbol in the message
text is an integer surrounded by braces, as in this example:
Invalid file name {0} - msgText
- Input can be any variable or expression that is assignment compatible with the STRING type. This is the text of a message that is associated with the web page itself.
Example
This example shows an entry from the message file errorMessages_en_US.properties:
badname = The name you entered, {0}, is not valid.
userName STRING = getUserName(); // ask for input
rc = validateUserName(userName);
if (rc < 0)
SysLib.setErrorForComponentID( "form1:CustName",
SysLib.getMessage( "badname", [ userName ] ) );
endCompatibility
| Platform | Issue |
|---|---|
| COBOL generation | The setErrorForComponentID() function is not supported |
| JavaScript™ generation | The setErrorForComponentID() function is not supported |