1

I need help with passing a query parameter into my next JSF page. I have tried everything and I am stuck. I'm able to retrieve the param in the second page if i type the url myself. Example: localhost:8080/devices?propId=24&faces-redirect=true from a primefaces commandButton action. But if i try to do it dynamically, i get an error like: Not a Valid Method Expression: property/devices?propId=#{recentPropertyFEnd.selected.idpropertytable}&faces-redirect=true.

I have tried everything. f:param, f:viewParam, etc. but nothings works.

I guess the question is, what is the right way to send query params from a commandButton in JSF?

command button from first page:

<p:commandButton value="Show Devices" action="property/devices?propId=#{recentPropertyFEnd.selected.idpropertytable}&amp;faces-redirect=true"> </p:commandButton>

second page f:viewParam:

<f:metadata>
        <f:viewParam name="propId" value="#{deviceFEnd.propId}"/>
        <f:viewAction action="#{deviceFEnd.actioncheck()}" />
    </f:metadata>

manage bean second page:

    @Named(value = "deviceFEnd")
    @RequestScoped

public class DeviceFEnd implements Serializable {

    private int propId;

    public DeviceFEnd() {
    }

    public int getPropId() {
        return propId;
    }

    public void setPropId(int propId) {
        this.propId = propId;
    }

    public void actioncheck() {
        int x = 0;
        x++;
    }

    @PostConstruct
    public void init() {

    }

}

Like i said, if i type it myself in the action commandButton works, but if i tried to use a value from a bean fails. Please help...

JediSal
  • 65
  • 4

1 Answers1

1

I have figured it out. Use the action of the commandButton to call a method that makes the string url. like:

<p:commandButton value="Show Devices" action="firstBean.createString()"> </p:commandButton>

then in the firstBean you create the method createString as:

public String createString() {
    return "property/devices?propId=" + selected.getIdpropertytable() + "&faces-redirect=true";
}

this will create the string url = http://localhost:8080/yourApp/property/devices?propId=46

and that's it, you can get it from the second xhtml file using viewParam.

JediSal
  • 65
  • 4
  • Note that this only works with `&faces-redirect=true`. Without that, no parameters will be passed to the url. – Manuel M Mar 06 '19 at 22:26