How to validate the type of your attributs?

Splash Forums PrettyFaces Users How to validate the type of your attributs?

This topic contains 1 reply, has 2 voices, and was last updated by  Lincoln Baxter III 2 years, 11 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #24686

    WilliamB
    Participant

    Greetings,

    I’ve something that looks like a very simple issue:

    I’ve defined several query param in my pretty-config.xml file:
    <query-param name="otherAge">#{form.age}</query-param>

    The Form bean has an attribut age which is an int.
    if my url is: http://www.test/page.jsf?otherAge=1 all is working fine
    But when my url is : http://www.test/page.jsf?otherAge=a because the user changed the url manualy, then i get a javax.faces.convert.ConverterException.

    Now i’ve a page define for error 500 in my web.xml

    <error-page>
      <error-code>500</error-code>
      <location>/erreur500.jsf</location>
    </error-page>

    But it’s not working i’ve an error 500 displayed with the Apache Tomcat error log.

    So I want to try and validate the param manualy before pretty faces map them with my bean. I added a validator
    <query-param name=”otherAge” validator=”#{AgeController.validateInteger}”>##{form.age}</query-param>

    When the attribut is an integer, i see it passing through my validator in Debug mode: Great.
    However if the attribut is not an integer, it doesn’t go through the validator at all. But the page displayed is now an empty page instead of my tomcat log, so something is happening.

    Why doesn’t it go through the validator then?
    How are you supposed to validate the type of your attributs?

    Furthermore, I’ve added the onError param to try and redirect it to my error page:
    <query-param name="otherAge" validator="#{AgeController.validateInteger}" onError="error">##{form.age}</query-param>
    In my faces-config.xml, i’ve added

    <navigation-case>
      <from-outcome>error</from-outcome>
      <to-view-id>//erreur500.xhtml</to-view-id>
    </navigation-case>

    But i still get the white empty page.

    Thanks for your help.

    #24688

    Hey there William,

    Sorry it took me so long to get back to you. I think I know what is wrong here.

    First thing that stands out to me, is that you are trying to use a JSF navigation case from PrettyFaces – as far as I know this doesn’t work very well, and isn’t really intended to work.

    You could try creating a URL-mapping for your error page and using the mapping id in onError.

    The other things that stand out to me:

    1. <to-view-id>//erreur500.xhtml</to-view-id> – Why two ‘/’ forward slashes?
    2.##{form.age} – Why two ‘#’ hashes?

    If the above doesn’t solve your problem:
    What version of PrettyFaces are you using? What version of JSF? Which app-server? What does the rest of your pretty config look like? (This info typically helps us debug.)

    Thanks,
    I hope this helps give you somewhere to start,
    ~Lincoln

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

Comments are closed.