[jboss-user] [JBoss Seam] - Re: Problem: Custom validate methods in EJBs crash

2007-03-05 Thread krica
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.

View the original post : 
http://www.jboss.com/index.html?module=bbop=viewtopicp=4025041#4025041

Reply to the post : 
http://www.jboss.com/index.html?module=bbop=postingmode=replyp=4025041
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [JBoss Seam] - Re: Problem: Custom validate methods in EJBs crash

2006-09-13 Thread 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?

View the original post : 
http://www.jboss.com/index.html?module=bbop=viewtopicp=3971221#3971221

Reply to the post : 
http://www.jboss.com/index.html?module=bbop=postingmode=replyp=3971221
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [JBoss Seam] - Re: Problem: Custom validate methods in EJBs crash

2006-09-13 Thread [EMAIL PROTECTED]
If a txn rolls back, the EJB3 spec says that the PC should be cleared. So you 
will lose the state of the PC.

View the original post : 
http://www.jboss.com/index.html?module=bbop=viewtopicp=3971307#3971307

Reply to the post : 
http://www.jboss.com/index.html?module=bbop=postingmode=replyp=3971307
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [JBoss Seam] - Re: Problem: Custom validate methods in EJBs crash

2006-09-13 Thread 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 ;).

View the original post : 
http://www.jboss.com/index.html?module=bbop=viewtopicp=3971324#3971324

Reply to the post : 
http://www.jboss.com/index.html?module=bbop=postingmode=replyp=3971324
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [JBoss Seam] - Re: Problem: Custom validate methods in EJBs crash

2006-09-09 Thread 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 *dh* ;).


View the original post : 
http://www.jboss.com/index.html?module=bbop=viewtopicp=3970521#3970521

Reply to the post : 
http://www.jboss.com/index.html?module=bbop=postingmode=replyp=3970521
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [JBoss Seam] - Re: Problem: Custom validate methods in EJBs crash

2006-09-08 Thread denis-karpov
1. For simple validation (just value) we can still use JSF validation.

2. For complex validation I use drools (jBoss Rules).
It nicely integrated with Seam Page Flow (see seam samples).

You can express your validation in rule set. IMHO it looks like quite 
elegantly. You can define as complex rules as you want. And validation logic is 
separated.

And most important, it works steadily. I have not experienced any problems yet.

Denis.


View the original post : 
http://www.jboss.com/index.html?module=bbop=viewtopicp=3970396#3970396

Reply to the post : 
http://www.jboss.com/index.html?module=bbop=postingmode=replyp=3970396
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [JBoss Seam] - Re: Problem: Custom validate methods in EJBs crash

2006-09-08 Thread bfo81
[EMAIL PROTECTED] wrote : There is one problem with performing validation 
during the action phase: if you are using an extended persistence context, you 
would prefer to do validation before applying values onto the model object. But 
by the time we get to the action method, the values have already been applied. 
It is then difficult to roll back the change to prevent them being written to 
the database.
  | 
  | However, there is a solution: if you use an extended persistence context 
with manual flushing, you are fine. There is better support for this in CVS.
Here's another way, which works already now without having to wait for Seam 1.1 
or using the CVS version;).


  | 
  | import javax.ejb.SessionContext;
  | 
  | @Resource
  | SessionContext ejbCtx;
  | 
  | public String actionMethod() {
  | ...
  | if (validationFailed)
  | ejbCtx.setRollbackOnly();
  | ...
  | }

By the way: To prevent the Extended Persistence Context from auto-flushing 
where you maybe do not expect it, annotate your class with 
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) so that no 
storing will be performed. And to make your save-method work again, annotate it 
with @TransactionAttribute(TransactionAttributeType.REQUIRED) 

View the original post : 
http://www.jboss.com/index.html?module=bbop=viewtopicp=3970438#3970438

Reply to the post : 
http://www.jboss.com/index.html?module=bbop=postingmode=replyp=3970438
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [JBoss Seam] - Re: Problem: Custom validate methods in EJBs crash

2006-09-08 Thread [EMAIL PROTECTED]
Unfortunately this is not a solution. The EPC is considered hosed after a 
transaction rollback.

The only way (per-spec) is to annotate actionMethod() or the bean as 
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED), which is ugly.

CVS version of Seam has @Begin(flushMode=FlushMode.MANUAL) as a much cleaner 
alternative.

View the original post : 
http://www.jboss.com/index.html?module=bbop=viewtopicp=3970441#3970441

Reply to the post : 
http://www.jboss.com/index.html?module=bbop=postingmode=replyp=3970441
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [JBoss Seam] - Re: Problem: Custom validate methods in EJBs crash

2006-09-07 Thread CptnKirk
I agree with Gavin.  I've always been ok with complex validation in the action 
method (or control flow).  If you need something a little more declarative, it 
shouldn't be too hard to use Seam plus EJB interceptors to write your thin 
framework.

If you think about it this is what JSF is doing anyway with its phased approach 
to conversion and validation.  Being able to use EJB 3 allows you to slip in 
your own layer immediately preceeding action invocation.  You'd then be able to 
apply any declarative application concerns, including validation, on objects 
that had already been converted and validated in isolation.

Would it help if Seam provided a standard annotation that highlights this 
ability or should users just implement something like this on their own?  I 
guess if this feature is being requested, giving the masses what they want may 
have some value, even if it's just providing a utility that they could provide 
themselves.  Utility is a good thing. 

View the original post : 
http://www.jboss.com/index.html?module=bbop=viewtopicp=3970169#3970169

Reply to the post : 
http://www.jboss.com/index.html?module=bbop=postingmode=replyp=3970169
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [JBoss Seam] - Re: Problem: Custom validate methods in EJBs crash

2006-09-07 Thread petemuir
I still think that it is frustrating that JSF validator error messages and 
action phase validation error messages won't appear at the same time. Any ideas?

View the original post : 
http://www.jboss.com/index.html?module=bbop=viewtopicp=3970183#3970183

Reply to the post : 
http://www.jboss.com/index.html?module=bbop=postingmode=replyp=3970183
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [JBoss Seam] - Re: Problem: Custom validate methods in EJBs crash

2006-09-07 Thread [EMAIL PROTECTED]
There is one problem with performing validation during the action phase: if you 
are using an extended persistence context, you would prefer to do validation 
before applying values onto the model object. But by the time we get to the 
action method, the values have already been applied. It is then difficult to 
roll back the change to prevent them being written to the database.

However, there is a solution: if you use an extended persistence context with 
manual flushing, you are fine. There is better support for this in CVS.

View the original post : 
http://www.jboss.com/index.html?module=bbop=viewtopicp=3970170#3970170

Reply to the post : 
http://www.jboss.com/index.html?module=bbop=postingmode=replyp=3970170
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [JBoss Seam] - Re: Problem: Custom validate methods in EJBs crash

2006-09-07 Thread CptnKirk
And required checking happens outside of conversion/validation at yet another 
time.  Unfortunately, JSF seems to be designed to support providing a 
consistent checked state through each phase of the lifecycle and short circuit 
phases if there are problems.  This almost explicitly designs away your desire 
to collect all this information and display it at once.

I don't see a JSF provided solution to this problem in 1.2 (Gavin has mucked 
more with the internals though, maybe he knows better).  It seems to me the 
easiest solution would be to ditch JSF validation and simply validate yourself 
within the application.  Use the framework or not, but don't fight it.

There may be a way to reuse your existing validator classes and write a custom 
phase listener that would provide your own hooks to the validation phase, but 
then you'd be using your own validator framework and not JSFs (no UI component 
tie in).  I just don't think JSF was designed to give you what you want.

View the original post : 
http://www.jboss.com/index.html?module=bbop=viewtopicp=3970191#3970191

Reply to the post : 
http://www.jboss.com/index.html?module=bbop=postingmode=replyp=3970191
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [JBoss Seam] - Re: Problem: Custom validate methods in EJBs crash

2006-09-07 Thread petemuir
I see where you are coming from with validating within the application but IMO 
the disadvantages are greater
*  Your entities get updated with invalid values (less of an issue with manual 
flushing as Gavin says)
  | *  That's what @Invalid did and IIRC it didn't work brilliantly
  | *  As you say, harder to attach errors to the correct component on the page 
(the ease with which this is possible in JSF is, IMO, one of its real strengths)
In JSF 1.2 there is the findComponent method available; using this it could be 
possible to get another component, retrieve it's value and use it.  It wouldn't 
really fit with the validator annotations but could be good for custom 
validators. I will stew on it.

The only way I found around the NotNull/required problem is to have a 
ModelValidator as a component and, if the notnull annotation is on it's 
parent's value, automatically sets required=true on it's parent; I did have 
something like this working in my version of ModelValidator but then dumped it 
as I felt that (in my application) whether a field was required or not was up 
to the view not the Entity (e.g. a customer is required to enter more details 
than a account manager when setting up a new account)

View the original post : 
http://www.jboss.com/index.html?module=bbop=viewtopicp=3970202#3970202

Reply to the post : 
http://www.jboss.com/index.html?module=bbop=postingmode=replyp=3970202
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [JBoss Seam] - Re: Problem: Custom validate methods in EJBs crash

2006-09-06 Thread [EMAIL PROTECTED]
IMO, it is perfectly reasonable to put complex validations in the action 
method...

View the original post : 
http://www.jboss.com/index.html?module=bbop=viewtopicp=3969930#3969930

Reply to the post : 
http://www.jboss.com/index.html?module=bbop=postingmode=replyp=3969930
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [JBoss Seam] - Re: Problem: Custom validate methods in EJBs crash

2006-09-01 Thread petemuir
AFAIK the ModelValidator doesn't solve the 'complex' validation case: when you 
want to validate the value of component x against the value of component y. A 
simple example of this is that the integers entered into X and Y must add up to 
 150.

View the original post : 
http://www.jboss.com/index.html?module=bbop=viewtopicp=3968874#3968874

Reply to the post : 
http://www.jboss.com/index.html?module=bbop=postingmode=replyp=3968874
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [JBoss Seam] - Re: Problem: Custom validate methods in EJBs crash

2006-08-31 Thread bfo81
Well, forget it. There's another problem.

That complex validation would work well on an existing person that you edit.

But when you create a new person all its properties are null. And when you fill 
in the fields in a form and click save, then the persons properties are still 
null during validation (phase 3). They get their concrete values later, in 
phase 4 (update model values). And, alas, you cannot compare something to null.

So this is a killer for the idea of validators that should know more than 
just one field.

View the original post : 
http://www.jboss.com/index.html?module=bbop=viewtopicp=3968599#3968599

Reply to the post : 
http://www.jboss.com/index.html?module=bbop=postingmode=replyp=3968599
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [JBoss Seam] - Re: Problem: Custom validate methods in EJBs crash

2006-08-31 Thread petemuir
IMO this is a (big) problem with JSF validation - not that the validation 
framework can only handle 'simple' validation, but that you can't display 
'complex' validation errors at the same time as simple ones. I can't see a way 
around it.  I wonder if there has been any disucssion about this on other JSF 
fora (myfaces, facelets, glassfish) and whether any JSF component libraries 
have found a way around it.

View the original post : 
http://www.jboss.com/index.html?module=bbop=viewtopicp=3968790#3968790

Reply to the post : 
http://www.jboss.com/index.html?module=bbop=postingmode=replyp=3968790
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [JBoss Seam] - Re: Problem: Custom validate methods in EJBs crash

2006-08-31 Thread raja05
bfo81 wrote : 
  | But when you create a new person all its properties are null. And when you 
fill in the fields in a form and click save, then the persons properties are 
still null during validation (phase 3). They get their concrete values later, 
in phase 4 (update model values). And, alas, you cannot compare something to 
null.
  | 

Take a look at the ModelValidator class in org.jboss.seam.ui. That does its 
validation at the process Validation phase by using the model class (and the 
validators that go along with it) and the values that are in the request. 

One other way is that since the values are updated in the model only 
later(after the processValidations), you could queue a new type of event and 
set the phaseid of that to be UPDATE_MODEL_VALUES. That way the event will be 
queued during validations but will only be processed after the model values are 
updated. Thats still ugly(as you are validating in a phase thats not meant for 
that ) but will work.


View the original post : 
http://www.jboss.com/index.html?module=bbop=viewtopicp=3968824#3968824

Reply to the post : 
http://www.jboss.com/index.html?module=bbop=postingmode=replyp=3968824
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user