"Invalid number of parameters supplied for pattern" error

Splash Forums PrettyFaces Users "Invalid number of parameters supplied for pattern" error

This topic contains 32 replies, has 5 voices, and was last updated by  albatros 6 years, 5 months ago.

Viewing 15 posts - 1 through 15 (of 33 total)
  • Author
    Posts
  • #17808

    balteo
    Participant

    Hello,

    I am trying to run an annotation-configured pretty faces application. Here is the URL I use:

    http://localhost:8080/lang/fr/” (my app is the root one).

    And here is the error I have:

    ********************

    com.ocpsoft.pretty.PrettyException: Invalid number of parameters supplied for pattern: /lang/#{accueilView.language}/, expected <1>, got <0>

    com.ocpsoft.pretty.faces.url.URLPatternParser.getMappedURL(URLPatternParser.java:242)

    com.ocpsoft.pretty.faces.util.PrettyURLBuilder.build(PrettyURLBuilder.java:192)

    com.ocpsoft.pretty.faces.component.renderer.LinkRenderer.encodeBegin(LinkRenderer.java:70)

    javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:813)

    javax.faces.component.UIComponent.encodeAll(UIComponent.java:934)

    javax.faces.component.UIComponent.encodeAll(UIComponent.java:942)

    com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)

    org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)

    org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176)

    com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:109)

    com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)

    com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)

    javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)

    org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)

    org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)

    org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:368)

    org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:495)

    com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:112)

    com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:104)

    org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:113)

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

    ********************

    Can anyone please help?

    Thanks in advance,

    J.

    #20346

    It seems like you are using a <pretty:link> component on your page. In this case you must add a <f:param> to set the value of the path parameter for the outgoing link. Something like this:

    <pretty:link mappingId="myMapping">
    <f:param value="DE"/>
    Click here!
    </pretty:link>

    If you want to keep the language from the URL the user is accessing, you can use a value binding to refer to the value in your bean like this:

    <pretty:link mappingId="myMapping">
    <f:param value="#{accueilView.language}"/>
    Click here!
    </pretty:link>

    #20347

    balteo
    Participant

    Thanks Christian!

    It almost works. The only problem I have now is as follows: when I run this: “http://localhost:8080/&#8221; (notice the “/lang/fr/” is not specified) I get the same error as before.

    Any idea?

    Here is my bean:

    *************************

    package com.jeanbaptistemartin.view;

    import com.ocpsoft.pretty.faces.annotation.URLAction;

    import com.ocpsoft.pretty.faces.annotation.URLMapping;

    import java.util.Locale;

    import javax.faces.component.UIViewRoot;

    import javax.faces.context.FacesContext;

    import org.apache.log4j.Logger;

    import org.springframework.beans.factory.annotation.Autowired;

    import org.springframework.context.annotation.Scope;

    import org.springframework.stereotype.Component;

    /**

    *

    * @author julien

    */

    @Component(“accueilView”)

    @Scope(“request”)

    @URLMapping(id = “rootAction”, pattern = “/lang/#{accueilView.language}/”, viewId = “/accueil.jsf”)

    public class AccueilView {

    private static transient Logger log = Logger.getLogger(“com.jeanbaptistemartin.view”);

    private SuggestionOeuvreView suggestionOeuvreView;

    private String language;

    public AccueilView() {

    log.info(“AccueilView()”);

    }

    public String suggererSculpture() {

    log.debug(“suggererSculpture”);

    getSuggestionOeuvreView().setSculptureSuggeree(getSuggestionOeuvreView().suggererSculpture());

    return null;

    }

    @URLAction

    public void changeLocale() {

    log.info(“changeLocale”);

    UIViewRoot view = FacesContext.getCurrentInstance().getViewRoot();//todo locale en dur içi

    if (“fr”.equals(this.language)) {

    view.setLocale(Locale.FRENCH);

    } else if (“en”.equals(this.language)) {

    view.setLocale(Locale.ENGLISH);

    }

    getSuggestionOeuvreView().setSculptureSuggeree(getSuggestionOeuvreView().suggererSculpture());//refactor

    }

    @Autowired

    @Scope

    public void setSuggestionOeuvreView(SuggestionOeuvreView suggestionOeuvreView) {

    log.debug(“setSuggestionOeuvreView”);

    this.suggestionOeuvreView = suggestionOeuvreView;

    }

    public SuggestionOeuvreView getSuggestionOeuvreView() {

    log.debug(“getSuggestionOeuvreView”);

    return this.suggestionOeuvreView;

    }

    /**

    * @return the language

    */

    public String getLanguage() {

    return language;

    }

    /**

    * @param language the language to set

    */

    public void setLanguage(String language) {

    this.language = language;

    }

    }

    *************************

    #20348

    Could you post your .xhtml file and the full stacktrace please? If it is really the exact same exception, it will be probably another missing <f:param> in one of your <pretty:link> components.

    #20349

    balteo
    Participant

    Thanks Christian: it fixed the problem.

    Regards,

    J.

    #20350

    You are welcome! Let us know if you have other problems or ideas for improvement! :-)

    #20351

    balteo
    Participant

    Will do :-)

    J.

    #20352

    lisboa
    Participant

    Hello guys,

    I use Prettyfaces with success. It generates links like /job/show?jobId=xx.

    However, when I set up the pretty-config.xml to use path parameters, it stop to work. There are two different errors, depending on how configure <f:param> in view:

    Situation 1: setting the attributes ‘name’ and ‘value’ of <f:param>

    <pretty:link mappingId=”showJobId” id=”jobTitle” >

    <f:param name=”jobId” value=”#{job.jobId}” />#{job.title}

    </pretty:link>

    In this case, prettyfaces generates the exception:

    Invalid number of parameters supplied for pattern: /job/show/#{jobId}/, expected <1>, got <0>

    And the page is blank. No link is generated.

    Siatuação 2: Setting only the value attribute of <f:param>

    <pretty:link mappingId=”showJobId” id=”jobTitle” >

    <f:param value=”#{job.jobId}” />#{job.title}

    </pretty:link>

    In this case, the links are generated correctly (for example: /job/show/1). However, in the Becking bean, the jobId parameter always is null, i.e., request.getParmeter(“jobId”) is null.

    Do you have any idea of the cause of this problem?

    I use:

    – JSF 1.2 + Facelets 3.2.0 prettyfaces

    – The PrettyFilter Spring is located after the security filter.

    – In the pretty-config.xml, use the following configuration:

    <url-mapping id=”showJobId”>

    <pattern value=”/job/show/#{jobId}/” />

    <view-id>#{showJob.getViewPath}</view-id>

    </url-mapping>

    – In view, I use the pretty link:

    <pretty:link mappingId=”showJobId” id=”jobTitle” >

    <f:param name=”jobId” value=”#{job.jobId}” />#{job.title}

    </pretty:link>

    Thanks,

    Fabio.

    #20353

    Again, do not use a name in your <f:param>.

    This is incorrect:

    <pretty:link mappingId="showJobId" id="jobTitle" >
    <f:param name="jobId" value="#{job.jobId}" />#{job.title}
    </pretty:link>

    This is correct:

    <pretty:link mappingId="showJobId" id="jobTitle" >
    <f:param value="#{job.jobId}" />#{job.title}
    </pretty:link>

    #20354

    lisboa
    Participant

    Thanks Lincoln,

    Without name attribute, the links are generated in the page. However, the jobId is away null.

    String jobId = request.getParameter(“jobId”);

    If I remove the path parameters from the pretty-config (/show/job), the jobId is correctly setted.

    Thanks a lot,

    Fabio.

    #20355

    Please post your URL-mapping configuration.

    #20356

    lisboa
    Participant

    In my pretty-config.xml

    <url-mapping id=”showJobId”>

    <pattern value=”/job/show/#{jobId}/” />

    <view-id>#{showJob.getViewPath}</view-id>

    </url-mapping>

    and showJob.getViewPath method:

    public String getViewPath() {

    return “/pages/job/showJob.html”;

    }

    #20357

    If you want the value to be injected into the bean, you need to specify that in the configuration:

    <url-mapping id="showJobId">
    <pattern value="/job/show/#{jobId : job.jobId }/" />
    <view-id>#{showJob.getViewPath}</view-id>
    </url-mapping>

    #20358

    lisboa
    Participant

    Hello Lincoln,

    Instead of inject into the bean, the code

    String jobId = request.getParameter (“jobId”)

    should work?

    *

    Injecting into the bean work, but does not respect the @PostCosntruct annotation: The setJobId(..) is called after the init method.

    Thanks again !

    Fabio.

    #20359

    Yep, String jobId = request.getParameter ("jobId") should work.

Viewing 15 posts - 1 through 15 (of 33 total)

You must be logged in to reply to this topic.

Comments are closed.