0

I am using prettyfaces-3.4.2 with primefaces-7.0 and I wanted to use a bean property in my URL as the documentation show it.

pretty-config.xml

<url-mapping id="myUrl1">
    <pattern value="/#{myBean.param}" />
    <view-id value="/views/myView.xhtml" />
</url-mapping>

MyBean.java

@Named(value = "myBean")
@ViewScoped
public class myBean implements Serializable {
    private String param;
    private String str1;
    private String str2;

    public void loadStr1() {
        if (param.equals("new")) this.str1 = "new_value";
        else this.str1 = "default_value";
    }        

    // getters & setters

    public void setParam() {
        this.param = param;
        loadStr1();
    }
}

myView.xhtml

<h:form>
    <p:inputText value="#{myBean.str1}">
        <p:ajax />
    </p:inputText>

    <p:inputText value="#{myBean.str2}">
        <p:ajax />
    </p:inputText>
</h:form>

My problem is that each time I change the value of my inputs which trigger a new ajax request to update my bean properties (str1 & str2), it triggers again the setter of my url parameter (param) because a new request is executed.

So, it triggers my loadStr1 each time an ajax request is made, resetting my str1 value.

Is it the normal behavior that ajax requests call setter of url parameter ? And can I prevent it ?

robinvrd
  • 1,760
  • 12
  • 28

1 Answers1

0

PrettyFaces onPostBack parameter of <action> seems to do the job.

<url-mapping id="myUrl1">
    <pattern value="/#{myBean.param}" />
    <view-id value="/views/myView.xhtml" />
    <action onPostback="false">#{myBean.loadStr1}</action>
</url-mapping>

And then I just remove the call of loadStr1 from MyBean.

public void setParam() {
    this.param = param;
    /*loadStr1();*/
}
robinvrd
  • 1,760
  • 12
  • 28