0

I have gone through a few answers on this topic already, especially from BalusC blogs. But its somehow not working in the implementation below. Am I missing something or doing something completely wrong.

I have a basic form with a few dropdowns, when I submit the form i.e. call submitDetails it returns the following String "phaseTwo?faces-redirect=true" which is backed by bean called PhaseTwoController.java

So on submit from phaseOne.xhtml I want to see phaseTwo.xhtml with values selected on phaseOne.xhtml

Here is the code:

THis is PhaseOne.xhtml backed by PhaseOneController.java

<h:form>
            <p:panel header="Select country" style="margin-bottom:10px;">
                <h:panelGrid columns="2" cellpadding="5">
                    <p:outputLabel for="country" value="Country: " />
                    <p:selectOneMenu id="country" value="#{phaseOneController.country}" style="width:150px">
                        <p:ajax listener="#{phaseOneController.onCountryChange}" update="subCategory" />
                        <f:selectItem itemLabel="Select Country" itemValue="" noSelectionOption="true" />
                        <f:selectItems value="#{phaseOneController.countries}" />
                    </p:selectOneMenu>

                    <p:outputLabel for="province" value="Province: " />
                    <p:selectOneMenu id="province" value="#{phaseOneController.province}" style="width:150px">
                        <p:ajax listener="#{phaseOneController.onProvinceChange}" update="city" />
                        <f:selectItem itemLabel="Select Province" itemValue="" noSelectionOption="true" />
                        <f:selectItems value="#{phaseOneController.provinces}" />
                    </p:selectOneMenu>

                <p:outputLabel for="city" value="City: " />
                <p:selectOneMenu id="city" value="#{phaseOneController.city}" style="width:150px">
                    <f:selectItem itemLabel="Select City" itemValue="" noSelectionOption="true" />
                    <f:selectItems value="#{phaseOneController.cities}" />
                </p:selectOneMenu>
            </h:panelGrid>

                <p:separator />

                <p:commandButton value="Select" actionListener="#{phaseOneController.submitDetails}" icon="ui-icon-check">
                    <f:param name="country" value="#{phaseOneController.country}" />
                    <f:param name="province" value="#{phaseOneController.province}" />
                    <f:param name="city" value="#{phaseOneController.city}" />
                </p:commandButton>
            </p:panel>
        </h:form>


@ManagedBean
@RequestScoped
public class PhaseTwoController {

    @ManagedProperty(value="#{param.country}")
    private String country;

    @ManagedProperty(value="#{param.province}")
    private String province;

    public void setCountry(String country) {
        this.country = country;
    }

    public void setProvince(String province) {
        this.province = province;
    }

    public void setCity(String city) {
        this.city = city;
    }
}

P.S. I havent posted the code for PhaseOneController.java as I am not sure if it is needed. But if someone wants to look at it, I can post it.

Nick Div
  • 5,338
  • 12
  • 65
  • 127
  • I don't think you can do it via the beans, if your beans stay request scoped. You can either change one or both to session scoped, or add a new session scoped bean for the purpose of storing session data. – KC Wong Oct 17 '16 at 04:38
  • I dont mind change the scope, I can make them both ViewScoped if that helps. But cant make them SessionScoped for sure. If I was to make them ViewScoped, would the code work or I would have to make changes to it? – Nick Div Oct 17 '16 at 04:41
  • Please provide version information and have a look at [this answer](http://stackoverflow.com/questions/3909267/differences-between-action-and-actionlistener) and this [article](https://www.mkyong.com/jsf2/4-ways-to-pass-parameter-from-jsf-page-to-backing-bean/). – irieill Oct 17 '16 at 06:35
  • duplicate (just ignore the title and viewscoped beans): https://stackoverflow.com/questions/11676224 – Kukeltje Oct 17 '16 at 15:14

0 Answers0