Brian Wheeler

Ranch Hand
+ Follow
since Dec 06, 2010
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
2
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Brian Wheeler

Bill,

The service Spring managed service bean works fine and injects mappers successfully, no problem there. The part where it's failing is when I try to register legacy classes as Spring beans. These legacy classes are created with the new operator, which could explain the problem. For this reason, I am using webapplicationcontext to get access to the Spring/Mybatis service beans.

Thanks
11 years ago
Bill,

I'm using Spring/Mybatis for the application's data access layer. There is a spring bean service class that basically injects a mapper that does all the SQL calls. The class I'm trying to write unit test for is a legacy code that was originally implemented using JDBC. I modified this legacy code to utilize Spring/Mybatis. And the only way I got it to work was to get the applicationcontext so that I can get the service beans to make the database calls.

I've tried to make this legacy code a bean by adding @Component/@Named so that I can inject the service class, however, this didn't work for me.

Thanks
11 years ago
Bill,

I actually have tried to make the class I'm testing a spring bean, however, this approach wasn't working consistently. For some beans, it failed to get the applicationcontext. I've also tried to implement applicationcontextaware to get the applicationcontext. However from reading materials online, a web application should stick with using webapplicationcontext and not applicatoncontext. Not to sure why, but it has to do with something about the default bean scope for application context is 'singleton' compared to 'request' for webapplicationcontext.

Thanks for the links, I'll take a look at them.
11 years ago
Hey Bill,

Autowire wont work in this case because class LocationDAOImpl is legacy code and is not a bean(not part of Spring). This is why the I'm using WebApplicationContext to get LocationDAOService bean. Works perfect. But not so well with unit testing. Does anyone know a way to write a unit test that tests a class utilizing ContextLoader.getCurrentWebApplicationContext()?

Thanks in advance!
11 years ago
Hi All,

I'm trying to write unit tests on a DAO class which uses Spring-Mybatis. I'm running the unit test with maven without running the web application. The error that I'm getting is java.lang.NullPointerException at line WebApplicationContext ctx = ContextLoader.getCurrentWebApplicationContext(); (Please see below for code snippet). However, I can successfully run the unit test if I call the LocationDAOService class directly in the test class.

Does anyone know a way to unit test the class that uses the WebApplicationContext/ContextLoader.getCurrentWebApplicationContext() outside the web containter?

Thanks in advance!




11 years ago
Tim Holloway,

I tried what you suggested with no luck.

I also tried just jsf validation and getting the same behavior, no validation.

So far Richfaces validation works but only when I type something in the form and move focus out of the form. As a workaround, how can I code to explicitly validate all the forms when the user hit the submit button?


11 years ago
JSF

Tim Holloway wrote:ALL form submits are validated. That's a fundamental part of the JSF contract.

RichFaces offers two extensions to the standard form validation process. One is client-based, using generated Javascript and one is server-based, using AJAX.

This element:


runs client-side validation. There is an implied (default) 'event="change"' on the validator tag. I've had occasional grief with change events, so I tend to use the blur event, instead.

This tag is ONLY available on RichFaces 4 and will be silently ignored if you're using RichFaces 3.

The other extension is the "ajaxValidator" tag. It is available for RichFaces 3 and it basically submits the form as though the containing control was the only control on the form, JSF runs the validation, then short-circuits past the update and action phases, so that only validation is done.

Actually, RF3 also supports a beanValidator, but that's another story.



All forms are validated on submit? But why isn't it?

Here is the code, this should work but it doesn't. No validation or submits.

xhtml code snippet
11 years ago
JSF

Tim Holloway wrote:JSF validators are done at the GUI level. JSR-303 validations are executable at multiple levels. For example, I use them on ORM record fields to catch bad data before it commits to the database. You can also mix and match, which can be good, for example, if you are connected to an ORM record, but for the particular task in the GUI, you want additional restrictions above and beyond the default ORM validations.

Web clients don't care about "moving outside the form", but if you move outside the control, a JavaScript onblur event is fired to indicate that the control has lost focus. Normally you have to explicitly code any AJAX handling of that event, but if you use appropriate AJAX-friendly tags, they can handle the job for you. The base JSF tags do not do any javascript events without external help.



Hey Tim Holloway,

I appreciate the explanation. I've tried using <a4j:commandButton/> instead of <h:commandButton/> but with no success. According to the demo documentation, <a4j:commandButton/> should do the job, however, nothing happens, no validation or submission of the form. But with the <h:commandButton/> there is no validation, which I expected. But at least it can submit the form. As you can tell, I'm new to JSF/Richfaces, can you advise how I can explicitly code an ajax handling event to fire all the validation forms after clicking the <h:commandButton/>?
11 years ago
JSF
Hey Tim,

I'm just playing around with the JSR-303 constraints. I can use either the JSR-303 or the JSF validator constraints, they both do what I want it to do. I'm not sure which way is preferred, but I'm not concerned with it right now.

My focus right now is to validate the input forms client side (server ajax calls) after the user clicks the submit button.
11 years ago
JSF

Tim McGuire wrote:

Brian Wheeler wrote:Hey Everyone,

I got my client side validation to work using this example provided here RichFaces Client Side Validation

Notice, that there is no validation errors until you type and click out of that input form. Not a use case I want.

I'm trying to validate the input forms during an on submit action. Similar to to example provided here. rich:message demo

Using the above example source code, the problem I'm having is when I click the submit button nothing happens. No validation error and no submit action. Am I missing something? Can someone experienced with what I'm trying to do give me some feedback?

Thanks in Advance.



To be clear, you want validation to happen when you click submit button? I can't give feedback unless I see the code you use. Can you post the code that you are using?



Hey Tim,

Yes, I would like it to validate on the client side on submit, if validation pass submit form. Currently, it validates when you type text and move focus outside the form. I think this is default behavior. Here's the code snippet.

xhtml


bean
11 years ago
JSF
Hey Everyone,

I got my client side validation to work using this example provided here RichFaces Client Side Validation

Notice, that there is no validation errors until you type and click out of that input form. Not a use case I want.

I'm trying to validate the input forms during an on submit action. Similar to to example provided here. rich:message demo

Using the above example source code, the problem I'm having is when I click the submit button nothing happens. No validation error and no submit action. Am I missing something? Can someone experienced with what I'm trying to do give me some feedback?

Thanks in Advance.
11 years ago
JSF

Tim Holloway wrote:You can't use the "@NotNull" validation on a property that has been populated from a web form (JSF or otherwise). That's because HTML doesn't support binary constructs such as "null" and so what you'll get instead is an empty string. Which isn't the same thing, and therefore passes validation. So you either need a "required=true" attribute on your View Definition (xhtml) or you need an annotation that forbids a zero-length (empty) string on the backing bean property.

Your javascript error is probably due to syntax errors in your EL expression. It should be "#{data.name}". The braces make all the difference.



Thanks Tim for the FYI on the @NotNull annotation. By the way, this issue was due to using <body>. Replaced it with <h:body> and it fixed it.
11 years ago
JSF
Hey Everybody,

I'm trying to validate input forms on my page using using this client side validation method explained here 'Client Side Validation'.

However, I'm getting this JavaScript error 'Object Expected' and no validation error gets rendered. Does anyone know why this is happening?

Heres the code snippet from my project.

Bean


xhtml


Thanks in advance

11 years ago
JSF
Hey Tim,

I'm using this component out of the box without modifying the style.

Here's an update though. I am using the rich:select component along with many h:inputtext components on the same page. I noticed that when I removed all of the h:inputtext, rich:select worked perfectly just like how the demo showcased it. Any ideas why this might be?
11 years ago
JSF
Hey everybody!

I'm using richfaces 4.2.0 and have a problem with the rich:select component. Here is the link to the demo. Richface Select Demo

In this demo, notice when you do a drop down and rollover anywhere in the row, it hightlights the item. However, when using rich:select component on my application, it would only highlight an item when I rollover the actual text on that row.

Does anyone know why this is happening?

Thanks in advance!
11 years ago
JSF