-
15. Re: Problem: Custom validate methods in EJBs crash
bfo81 Sep 9, 2006 5:31 AM (in response to bfo81)Gavin, maybe we misunderstood each other. It's important to mention that the actionMethod above shall perform "complex" validation and then save if everything is alright.
@Stateful @Scope(CONVERSATION) @Name("whateverEditor") @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) public class WhateverEditorBean .... { ... @TransactionAttribute(TransactionAttributeType.REQUIRED) @End(ifOutcome={"backToListPage"}) public String actionMethod() { if ( ! complexValidationOk() ) { ejbCtx.setRollbackOnly(); //no flushing at the end of the method addFacesMessage("Complex validation failed"); return null; //redisplay editor page } //everything ok? then auto-flushing will be performed at the end of the method. return "backToListPage"; } ... }
The flush-mode in the begin annotation is much better, yes... but for a non-beta, non-CVS, production environment I need another solution. And I'm really interested what you think about the approach above. For me it seemed to work perfectly.
btw: what does "hosed" mean? Sorry, I'm German, and the dictionary doesn't know that word *dooooh* ;). -
16. Re: Problem: Custom validate methods in EJBs crash
bfo81 Sep 13, 2006 5:11 AM (in response to bfo81)Ok, found out that "hosed" is it slang and means "broken" ;).
However...
@Gavin, could you explain me why using setRollbackOnly() causes isn't good for the PersistenceContext? -
17. Re: Problem: Custom validate methods in EJBs crash
gavin.king Sep 13, 2006 12:22 PM (in response to bfo81)If a txn rolls back, the EJB3 spec says that the PC should be cleared. So you will lose the state of the PC.
-
18. Re: Problem: Custom validate methods in EJBs crash
bfo81 Sep 13, 2006 12:58 PM (in response to bfo81)Thanks for your answer. But the PC only exists during editing one single entity (in a conversation), so I think it's ok... it works without problems ;).
-
19. Re: Problem: Custom validate methods in EJBs crash
krica Mar 5, 2007 8:33 AM (in response to bfo81)I know this is an old thread, but I ran into the same problem with the ValidatorException causing the crash. After much trial and error, this is the solution I have come up with. I thought it may be useful for others, at least once I get the last little niggle out of it, which I don't think is relevant to the problem at hand.
At the bottom of my form, I create a hidden input field, with a dummy value and a bound validator method. In this method, I then get the components I'm interested in and validate the values. If a field is deemed invalid, the flag it as such and add a message to the context. E.g.public void validateForm(FacesContext context, UIComponent component, Object value) throws ValidatorException { HtmlInputText theInputText = (HtmlInputText) context.getViewRoot().findComponent("myForm:myInputId"); String theValue = (String) faxInputText.getValue(); if ("anError".equals(theValue)) { theInputText.setValid(false); context.addMessage(theInputText.getClientId(context), FacesMessages.createFacesMessage(FacesMessage.SEVERITY_ERROR, "This is an error!")); } }
My only problem left is that sometimes, for some reason, the method does not get called.