JSF: reloading page via p:button using "?includeViewParams=true" results in %2C for integer GET param in new URL
Asked Answered
N

0

0

I have a page that has two GET params:

round = [some integer]

group = [some string]

enter image description here

See URL above.

These are the two components of the group's PK, an INT + a VARCHAR.

Facelet code:

    <f:metadata>
        <f:viewParam name="round" value="#{groupHandler.roundId}">
            <f:convertNumber integerOnly="true" />
        </f:viewParam>
        <f:viewParam name="group" value="#{groupHandler.groupCode}" />
        <f:viewAction action="#{groupHandler.loadEntity}" />
    </f:metadata>

    ...

    <p:button widgetVar="reloadPageButton"
              value="Reload page"
              outcome="#{view.viewId}?includeViewParams=true" />

    <h1>Group Manager</h1>

    ...

As you can see, the groupHandler bean receices the round ID via <h:viewParam name="round" value="#{groupHandler.roundId}"> using a number converter.

I construct a button to reload the page including the view parameters. When clicking this button, the page gets reloaded correctly, however, it now includes a comma character %2C in the new URL:

enter image description here


EDIT #1:

This is what a p:link hover has to say:

enter image description here


EDIT #2:

Minimal reproducible example:

XHTML:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      xmlns:h="http://java.sun.com/jsf/html">

    <f:view encoding="UTF-8">

        <f:metadata>
            <f:viewParam name="round" value="#{groupHandler.roundId}">
                <f:convertNumber integerOnly="true" />
            </f:viewParam>
            <f:viewParam name="group" value="#{groupHandler.groupCode}" />
            <f:viewAction action="#{groupHandler.loadEntity}" />
        </f:metadata>

        <h:head>
            <title>PrimeFaces View Param Int Reload Test</title>
        </h:head>

        <h:body>

            <p:link widgetVar="reloadPageButton"
                    value="Reload page"
                    outcome="#{view.viewId}?includeViewParams=true" />
            <p />

            <h:form id="test-form">

                The selected group is: [#{groupHandler.roundId}, #{groupHandler.groupCode}]

            </h:form>

        </h:body>

    </f:view>

</html>

Bean:

@Named
@ViewScoped
public class GroupHandler implements Serializable
{
    private static final long serialVersionUID = 1L;

    private Integer roundId;
    private String groupCode;

    public Integer getRoundId()
    {
        return roundId;
    }

    public void setRoundId( Integer roundId )
    {
        this.roundId = roundId;
    }

    public String getGroupCode()
    {
        return groupCode;
    }

    public void setGroupCode( String groupCode )
    {
        this.groupCode = groupCode;
    }

    public void loadEntity()
    {
        System.out.println( GroupHandler.class.getSimpleName() + ".loadEntity(): round ID = " + getRoundId() + ", group code = " + getGroupCode() );
    }
}

QUESTION:

Why is this happening?

How do I get rid of this?

I'm using Mojarra 2.3.x, PrimeFaces 8, WildFly 14

Narine answered 13/3, 2020 at 16:3 Comment(4)
minimal reproducible example please...Tillfourd
Just gimme a secNarine
I just removed the <f:convertNumber ...> from the view param... this seems to work. But then, I don't get why JSF is able to convert this for the setRound(Integer roundId) method...Narine
Use <f:convertNumber integerOnly="true" groupingUsed="false"/>. Otherwise the number is defaulted to use a comma for grouping. And %2C is because of that comma.Scripture

© 2022 - 2024 — McMap. All rights reserved.