You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shale.apache.org by Veit Guna <ve...@gmx.de> on 2006/11/25 19:22:07 UTC

Shale's commonsValidator + Facelets

Hi.

I'm also trying to get apache commons validator running together with
shale-1.0.4-SNAPSHOT and facelets 1.11. This is because I can use the
commons-validator package for business validation, too - independent of
the view technologie.

I've read the posts on the mailing-list but now I'm stuck somehow.

The following things I've done:

- added shale-core, shale-validator and shale-view to my libs
- added the things I need to a facelets taglib.xml like in the posts
I've seen so far and added a reference to it in the web.xml:

<?xml version="1.0"?>
<!DOCTYPE facelet-taglib PUBLIC "-//Sun Microsystems, Inc.//DTD Facelet
Taglib 1.0//EN" "facelet-taglib_1_0.dtd">
<facelet-taglib>
    <namespace>http://shale.apache.org/core</namespace>
    <tag>
        <tag-name>token</tag-name>
        <component>
            <component-type>org.apache.shale.Token</component-type>
            <renderer-type>org.apache.shale.Token</renderer-type>
        </component>
    </tag>
    <tag>
        <tag-name>commonsValidator</tag-name>
        <validator>
            <validator-id>org.apache.shale.CommonsValidator</validator-id>
        </validator>
    </tag>
</facelet-taglib>

- referenced the commonsValidator as follows in the xhtml file:

<input type="text" jsfc="h:inputText" id="subject"
value="#{messageAction.mailSubject}" maxlength="100" size="40">
	<sh:commonsValidator type="required"
arg="#{msg.NotEmptyValidator_VALUE_IS_EMPTY}" server="true" client="false"/>
</input>

- Added the shale namespace to the top of the page:

xmlns:sh="http://shale.apache.org/core"

So, I'm also using the token tag - that works fine. That means shale
works as expected. But somehow the commonsValidator doesn't seem to
work. When I submit the page, no validation takes place.
If I changed the name of the commonsValidator tag to something else, I
get an error that this tag doesn't exist. So that is setup correctly so far.

Any hints what the problem might be? Perhaps one need really a Facelet
Tag handler to get it running?

btw: people.apache.org is up and running again.

regards,
Veit

Re: Shale's commonsValidator + Facelets

Posted by David Geary <sa...@gmail.com>.
2006/11/25, Veit Guna <ve...@gmx.de>:
>
> David Geary schrieb:
> > 2006/11/25, Veit Guna <ve...@gmx.de>:
> >>
> >> Now the validation takes place and the JS gets rendered into the page.
> >> Something with the validation msg looks strange,
> >
> >
> > What does it look like?
>
> The problem was, that I put a EL resource-bundle reference to the arg
> parameter of the  commonsValidator that pointed to the error msg key in
> my resource bundle. I thought this parameter is used for the error msg -
> so it can be customized. So the raw msg of my RB was inserted in the
> default shale error msg as {0} - that looked strange ;). Didn't find
> documentation about that.


The arg parameter is used for the name of the field when the err msg is
constructed. It's not the error message itself.

BTW: why do I have to pass the label explicit by the arg parameter to
> the validator? The information is already in the component tree. It
> could take it from there?! If I leave it out, (null) is shown for the
> label in the error msg.


Yes, we could take it from the component tree, but the current
implementation does not do that.

Another strange things is, I mixed on a form
> commonsValidator with std. JSF validators. Now the problem arises, that
> shale allows only ONE error msg. Not separate summary and detail msgs as
> JSF offers. Now when the form gets validated I get in h:messages the
> summary plus the detail for jsf validators and from the commonsValidator
> just ONE msg. That looks odd. So there is the same msg for h:message and
> h:messages when using commonsValidator. Could that be optimized?


Not sure about that. I'd have to take a closer look.

> but I'll figure that
> >> out. Also I expected a msgbox to appear due to JS client verification?!
> >
> > Yes. If you specify client="true", you should see a JS alert if you have
> JS
> > turned on; otherwise,  the validation will be performed on the server.
>
> Thats the second strange thing. As I mentioned before I mix both
> validators - jsf and commmonsValidator. I've set client and server to
> true. But there's no JS msgbox concerning the required field when
> sending it. There's just a "normal" msg, like for the other jsf
> validators. I got _once_ a msgbox - I don't know why. But then even the
> msg was not I18N style - the german umlaut got rendered as some html
> encoding - can't remember exactly. Is there a problem mixing both
> validation methods in one form? I expected JS validation first with a
> msgbox, after that the server validation of the other jsf validator
> fields.
>
Any hints?



JSF validators are separate from Shale's integration with Commons Validator.
If you want a required validator to fire on the client use a commons
validator with type="required".


david

regards,
> Veit
>

Re: Shale's commonsValidator + Facelets

Posted by Veit Guna <ve...@gmx.de>.
So, I got it now working so far.

The missing JS msgbox was a JS-error problem. In my resource bundle I
used quotes around the fieldname and they won't be escaped so this broke
the JS. Using &quot; or &#34; didn't work either because it won't be
translated in the msgbox :(. So ' and " aren't an option. Not so nice
that it can't handle the encoding properly.

Another thing is, that the JS doesn't check the required flag on
selectboxes. So this will only be handled on server-side validation -
also not so nice presenting the user two different error msg "styles".

So, after I've got it "working" I must admit that this won't be an
option for me anymore. All the points are no go's for me.

Perhaps I will take a look at:

http://jsf-comp.sourceforge.net/components/clientvalidators/index.html
or
http://wiki.apache.org/myfaces/OptionalValidationFramework

which seem to be more integrated into jsf. But I will have separate
view/business logic validations then :(.

Thanks so far.

regards,
Veit


Veit Guna schrieb:
> David Geary schrieb:
>> 2006/11/25, Veit Guna <ve...@gmx.de>:
>>> Now the validation takes place and the JS gets rendered into the page.
>>> Something with the validation msg looks strange,
>>
>> What does it look like?
> 
> The problem was, that I put a EL resource-bundle reference to the arg
> parameter of the  commonsValidator that pointed to the error msg key in
> my resource bundle. I thought this parameter is used for the error msg -
> so it can be customized. So the raw msg of my RB was inserted in the
> default shale error msg as {0} - that looked strange ;). Didn't find
> documentation about that.
> 
> BTW: why do I have to pass the label explicit by the arg parameter to
> the validator? The information is already in the component tree. It
> could take it from there?! If I leave it out, (null) is shown for the
> label in the error msg. Another strange things is, I mixed on a form
> commonsValidator with std. JSF validators. Now the problem arises, that
> shale allows only ONE error msg. Not separate summary and detail msgs as
> JSF offers. Now when the form gets validated I get in h:messages the
> summary plus the detail for jsf validators and from the commonsValidator
> just ONE msg. That looks odd. So there is the same msg for h:message and
> h:messages when using commonsValidator. Could that be optimized?
> 
> 
>> but I'll figure that
>>> out. Also I expected a msgbox to appear due to JS client verification?!
>> Yes. If you specify client="true", you should see a JS alert if you have JS
>> turned on; otherwise,  the validation will be performed on the server.
> 
> Thats the second strange thing. As I mentioned before I mix both
> validators - jsf and commmonsValidator. I've set client and server to
> true. But there's no JS msgbox concerning the required field when
> sending it. There's just a "normal" msg, like for the other jsf
> validators. I got _once_ a msgbox - I don't know why. But then even the
> msg was not I18N style - the german umlaut got rendered as some html
> encoding - can't remember exactly. Is there a problem mixing both
> validation methods in one form? I expected JS validation first with a
> msgbox, after that the server validation of the other jsf validator fields.
> 
> Any hints?
> 
> regards,
> Veit
> 

Re: Shale's commonsValidator + Facelets

Posted by Veit Guna <ve...@gmx.de>.
David Geary schrieb:
> 2006/11/25, Veit Guna <ve...@gmx.de>:
>>
>> Now the validation takes place and the JS gets rendered into the page.
>> Something with the validation msg looks strange,
> 
> 
> What does it look like?

The problem was, that I put a EL resource-bundle reference to the arg
parameter of the  commonsValidator that pointed to the error msg key in
my resource bundle. I thought this parameter is used for the error msg -
so it can be customized. So the raw msg of my RB was inserted in the
default shale error msg as {0} - that looked strange ;). Didn't find
documentation about that.

BTW: why do I have to pass the label explicit by the arg parameter to
the validator? The information is already in the component tree. It
could take it from there?! If I leave it out, (null) is shown for the
label in the error msg. Another strange things is, I mixed on a form
commonsValidator with std. JSF validators. Now the problem arises, that
shale allows only ONE error msg. Not separate summary and detail msgs as
JSF offers. Now when the form gets validated I get in h:messages the
summary plus the detail for jsf validators and from the commonsValidator
just ONE msg. That looks odd. So there is the same msg for h:message and
h:messages when using commonsValidator. Could that be optimized?


> but I'll figure that
>> out. Also I expected a msgbox to appear due to JS client verification?!
> 
> Yes. If you specify client="true", you should see a JS alert if you have JS
> turned on; otherwise,  the validation will be performed on the server.

Thats the second strange thing. As I mentioned before I mix both
validators - jsf and commmonsValidator. I've set client and server to
true. But there's no JS msgbox concerning the required field when
sending it. There's just a "normal" msg, like for the other jsf
validators. I got _once_ a msgbox - I don't know why. But then even the
msg was not I18N style - the german umlaut got rendered as some html
encoding - can't remember exactly. Is there a problem mixing both
validation methods in one form? I expected JS validation first with a
msgbox, after that the server validation of the other jsf validator fields.

Any hints?

regards,
Veit

Re: Shale's commonsValidator + Facelets

Posted by David Geary <sa...@gmail.com>.
2006/11/25, Veit Guna <ve...@gmx.de>:
>
> Now the validation takes place and the JS gets rendered into the page.
> Something with the validation msg looks strange,


What does it look like?

but I'll figure that
> out. Also I expected a msgbox to appear due to JS client verification?!


Yes. If you specify client="true", you should see a JS alert if you have JS
turned on; otherwise,  the validation will be performed on the server.


david geary

regards,
> Veit
>
>
>
> Wendy Smoak schrieb:
> > On 11/25/06, Veit Guna <ve...@gmx.de> wrote:
> >
> >> I'm also trying to get apache commons validator running together with
> >> shale-1.0.4-SNAPSHOT and facelets 1.11. This is because I can use the
> >> commons-validator package for business validation, too - independent of
> >> the view technologie.
> > ...
> >> Any hints what the problem might be? Perhaps one need really a Facelet
> >> Tag handler to get it running?
> >
> > That's what I'm told, but I didn't get very far, either:
> >
> >
> http://www.nabble.com/Help-with-a-TagHandler-for-Shale%27s-%27validatorVar%27-t2398508.html
> >
> >
>

Re: Shale's commonsValidator + Facelets

Posted by Veit Guna <ve...@gmx.de>.
I don't need the ValidatorVar (yet?).

I've found your post:

http://www.mail-archive.com/user@shale.apache.org/msg00631.html

and this:

http://www.mail-archive.com/user@shale.apache.org/msg00547.html

That lead me to:

javax.faces.FacesException: Undefined component type
org.apache.shale.component.ValidatorScript

Corrected the shale taglib component-type:

org.apache.shale.component.ValidatorScript

to

org.apache.shale.ValidatorScript

Now the validation takes place and the JS gets rendered into the page.
Something with the validation msg looks strange, but I'll figure that
out. Also I expected a msgbox to appear due to JS client verification?!

regards,
Veit



Wendy Smoak schrieb:
> On 11/25/06, Veit Guna <ve...@gmx.de> wrote:
> 
>> I'm also trying to get apache commons validator running together with
>> shale-1.0.4-SNAPSHOT and facelets 1.11. This is because I can use the
>> commons-validator package for business validation, too - independent of
>> the view technologie.
> ...
>> Any hints what the problem might be? Perhaps one need really a Facelet
>> Tag handler to get it running?
> 
> That's what I'm told, but I didn't get very far, either:
> 
> http://www.nabble.com/Help-with-a-TagHandler-for-Shale%27s-%27validatorVar%27-t2398508.html
> 
> 

Re: Shale's commonsValidator + Facelets

Posted by Wendy Smoak <ws...@gmail.com>.
On 11/25/06, Veit Guna <ve...@gmx.de> wrote:

> I'm also trying to get apache commons validator running together with
> shale-1.0.4-SNAPSHOT and facelets 1.11. This is because I can use the
> commons-validator package for business validation, too - independent of
> the view technologie.
...
> Any hints what the problem might be? Perhaps one need really a Facelet
> Tag handler to get it running?

That's what I'm told, but I didn't get very far, either:

http://www.nabble.com/Help-with-a-TagHandler-for-Shale%27s-%27validatorVar%27-t2398508.html

-- 
Wendy