I have code in a managed bean:
public void setTestProp(String newProp) {
FacesMessage yourFailure = new FacesMessage();
yourFailure.setDetail("Really you need to promise to never do that again!");
yourFailure.setSummary("Stop here, now!");
yourFailure.setSeverity(FacesMessage.SEVERITY_FATAL);
throw new ValidatorException(yourFailure);
}
and in the XPage:
<xp:messages id="messages1" layout="table" showSummary="false"
showDetail="true" globalOnly="false">
</xp:messages>
but I get as result message (nicely in the yellow box as expected, not in an error page):
Error setting property 'testProp' in bean of type com.ibm.sg.demo.Test: javax.faces.validator.ValidatorException: Stop here, now!
I would like to:
What do I miss?
The problem is that the property resolver catches all java.lang.Throwable from the get/set method of the managed beans. The "original" facesMessage is replaced with a new one (the previous message is appended).
You have three possibilities:
Hope this helps
Sven
EDIT:
How to add a validation method to your bean
a) Add a validation method to your bean
public void validate(FacesContext context, UIComponent toValidate, Object value){
// Do your validation with value
// if everything is ok, exit method
// if not, flag component invalid...
((UIInput)toValidate).setValid(false);
// ... create your message ...
FacesMessage yourFailure = new FacesMessage();
yourFailure.setDetail("Really you need to promise to never do that again!");
yourFailure.setSummary("Stop here, now!");
yourFailure.setSeverity(FacesMessage.SEVERITY_FATAL);
context.addMessage(toValidate.getClientId(context), yourFailure);
}
b) Add your validator to the field
<xp:inputText id="inputText1"
value="#{TBean.test}"
validator="#{TBean.validate}">
(You can name the method whatever you want.)
This validator has not to be added to the faces-config.xml.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With