Skip to Main Content

Java Development Tools

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

addMessage(FacesContext) Error

867471Jun 8 2011 — edited Jun 13 2011
Hi All,
I am facing a problem with addMessage of javax.faces.context.FacesContext

Steps
1. Two components, component A and component B (both of them are required) are on the page with a command button (OK).
2. If i click on OK without entering any data in the two components, it shows me the required error message. This works fine.
3. I have a message call on OK on click, which finally shows an error saying "Message is not getting cleared on second attempt."
<af:commandButton text="OK"
binding="#{backingBeanScope.TestPage.cb1}"
id="cb1"
actionListener="#{backingBeanScope.TestPage.btnOkOnClick}"/>


public void btnOkOnClick(ActionEvent actionEvent) {
UIMessage key = Message.MSG_NOT_CLEARING;
String msg =
JSFUtils.getStringFromBundle(key.getResourceBundle(), key.getCode());
showMessage(null, FacesMessage.SEVERITY_ERROR, msg);
}

private static void showMessage(String clientId,
FacesMessage.Severity severity,
String messageDesc) {
FacesContext facesContext = FacesContext.getCurrentInstance();
// detail message only shown
facesContext.addMessage(clientId,
new FacesMessage(severity, null, messageDesc));
}

4.*Issue* comes when I clear the two required fields A and B and now click on OK, now the above error "Message is not getting cleared on second attempt." as well as the
required error message both come on the page.



Other relevant code:

//Message
This is the class where i create message constants

package com.ofss.fc.ui.view.testPage;

public class Message {
public static final String MSG_BUNDLE_LOC =
"com.ofss.fc.ui.view.testPag.Message";

/**
*<p>Error Code: FC_MSG1</p>
*<p>Description :Message is not getting cleared on second attempt.</p>
*/
public static final UIMessage MSG_NOT_CLEARING =
new UIMessage(MSG_BUNDLE_LOC, "FC_MSG1");
}

This is the resource bundle file from where the actual message is present.
//Message.properties

FC_MSG1=Message is not getting cleared on second attempt.


This is files has the resource bundle message and message error code.

package com.ofss.fc.ui.view.testPage;

public final class UIMessage {

/**
* Resource Bundle name
*/
private String resourceBundle;
/**
* Message code
*/
private String code;

public UIMessage(String resourceBundle, String code) {
this.resourceBundle = resourceBundle;
this.code = code;
}

public String getResourceBundle() {
return resourceBundle;
}

public String getCode() {
return code;
}
}




public void btnOkOnClick(ActionEvent actionEvent) {
UIMessage key = Message.MSG_NOT_CLEARING;
String msg =
JSFUtils.getStringFromBundle(key.getResourceBundle(), key.getCode());
showMessage(null, FacesMessage.SEVERITY_ERROR, msg);
}

private static void showMessage(String clientId,
FacesMessage.Severity severity,
String messageDesc) {
FacesContext facesContext = FacesContext.getCurrentInstance();
// detail message only shown
facesContext.addMessage(clientId,
new FacesMessage(severity, null, messageDesc));
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 11 2011
Added on Jun 8 2011
2 comments
833 views