Forwarding the request to Spring Controller

Splash Forums PrettyFaces Users Forwarding the request to Spring Controller

Tagged: 

This topic contains 5 replies, has 2 voices, and was last updated by  singhv 4 years, 11 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #18411

    singhv
    Participant

    I have been using the pretty faces with JSF withiut any issues. Now we have introduced Spring MVC and juggling between JSF and Spring .

    I want to forward a request to spring controller and this is my code from pretty-config.xml

    <url-mapping id="profileId">
    <pattern> /profile/#{forwarderBean.profileId}</pattern>
    <query-param name="id">#{forwarderBean.profileId}</query-param>
    <view-id> /userProfile.html?id=#{forwarderBean.profileId}</view-id>
    </url-mapping>

    I have created a forwarder bean which has a field profileId and setters and getters for the field.

    I expect the request to be forwarded to spring controller and it happens. But the #{forwarderBean.profileId} is not being transformed into the value and this is the exception I get

    SEVERE: Servlet.service() for servlet controller threw exception
    java.lang.NumberFormatException: For input string: "#{forwarderBean.profileId}"
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
    at java.lang.Integer.parseInt(Integer.java:449)
    at java.lang.Integer.valueOf(Integer.java:554)

    I am using pretty faces 1.2.6

    #22579

    Hi,

    first of all you should really update the PrettyFaces version you are using. Version 1.2.6 is VERY old. The current version is 3.3.3 and contains MANY improvements over 1.2.6.

    If you only want to transform the path parameter from the pretty URL into a query parameter, the following mapping should work fine:

    <url-mapping id="profileId">
    <pattern>/profile/#{id}</pattern>
    <view-id>/userProfile.html</view-id>
    </url-mapping>

    In this example the path parameter is automatically converted into a query parameter with the corresponding name.

    Could could additionally inject the path parameter into a bean property using something like this:

    <url-mapping id="profileId">
    <pattern>/profile/#{ id : forwarderBean.profileId }</pattern>
    <view-id>/userProfile.html</view-id>
    </url-mapping>

    In this case the path parameter is injected into #{forwarderBean.profileId} and also converted into a query parameter named id.

    I hope this helps. :)

    Christian

    #22580

    singhv
    Participant

    Christian

    I have not upgraded and trying the solution you suggested and they do not work.

    If I go with this solution

    <url-mapping id=”profileId”>

    <pattern>/profile/#{id}</pattern>

    <view-id>/userProfile.html</view-id>

    </url-mapping>

    com.ocpsoft.pretty.PrettyException: PrettyFaces: Exception occurred while processing <newReg:#{id}> for URL </profile/7874>

    at com.ocpsoft.pretty.beans.ParameterInjector.injectParams(ParameterInjector.java:122)

    at com.ocpsoft.pretty.beans.ParameterInjector.injectParameters(ParameterInjector.java:49)

    at com.ocpsoft.pretty.PrettyContext.injectParameters(PrettyContext.java:127)

    at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:55)

    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)

    at com.skill.guru.web.filter.AnalyticsFilter.doFilterInternal(AnalyticsFilter.java:44)

    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)

    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)

    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)

    If I try this solution

    <url-mapping id=”profileId”>

    <pattern>/profile/#{ id : forwarderBean.profileId }</pattern>

    <view-id>/userProfile.html</view-id>

    </url-mapping>

    this is the exception I get

    java.util.regex.PatternSyntaxException: Illegal repetition near index 9

    /profile/#{ id : forwarderBean.profileId }

    ^

    java.util.regex.Pattern.error(Pattern.java:1713)

    java.util.regex.Pattern.closure(Pattern.java:2775)

    Should I upgrade and then try or I am doing something wrong ?

    #22581

    singhv
    Participant

    Sorry posted twice. Deleting one post

    #22582

    I’m not really sure if PrettyFaces 1.2.6 supports conversion of path parameters into query parameters at all. If I remember correctly 1.2.6 only support direct value injection using EL expressions:

    <url-mapping id="profileId">
    <pattern>/profile/#{ forwarderBean.profileId }</pattern>
    <view-id>/userProfile.html</view-id>
    </url-mapping>

    But I really think you should try to update to PrettyFaces 3.3.3.

    #22583

    singhv
    Participant

    Hi Christian

    Yes it was the version problem I switched to 3.3 and the solution suggested by you works fine

    Thanks

    Vinay

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

You must be logged in to reply to this topic.

Comments are closed.