2

I have menu bar <p:submenu> which have phone brands as its menu items these menu items should redirect to same page but loading data should different. So I tried to use param and viewparam to catch the brand name

Menu bar JSF code

<p:submenu label="PHONES">
    <p:menuitem value="Apple" outcome="phones" >                               
        <f:param name="brand" value="Apple" />
    </p:menuitem>
    <p:menuitem value="Motorola" outcome="phones" >
        <f:param name="brand" value="Motorola"/>
    </p:menuitem>
    <p:menuitem value="Nokia" outcome="phones">
        <f:param name="brand" value="Nokia"/>
    </p:menuitem>
    <p:menuitem value="Samsung" outcome="phones">
        <f:param name="brand" value="Samsung"/>
    </p:menuitem>
</p:submenu> 

paramview code - this code is in different xhtml file. coded beginning of body

<h:body>
    <f:metadata>  
        <f:viewParam name="brand" value="#{phonesBean.brand}" />  
    </f:metadata>

PhonesBean

@ManagedBean
@RequestScoped
public class PhonesBean implements Serializable {

    private String brand;
    private List<PhoneSummary>phoneList = new ArrayList<PhoneSummary>();

    /**
     * Creates a new instance of PhonesBean
     */
    public PhonesBean() {
        getPhoneModelList();
    }

    private void getPhoneModelList(){
        brand=MenuItemManage.phoneBrand;
        DbPhones dbPhones = new DbPhones();
        phoneList=dbPhones.getPhonesSummary(brand);    
    }
}

Now when <p:menuitem> is clicked it redirects to page with parameter tagging like "brand=Nokia" but I can't catch it from <f:viewParam> and set it to a bean variable. How to fix this?

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
smk
  • 351
  • 2
  • 4
  • 14
  • `` goes in `` section as shown here: [ViewParam vs @ManagedProperty(value = “#{param.id}”)](http://stackoverflow.com/q/4888942/1065197) – Luiggi Mendoza Jun 09 '13 at 04:10
  • could you please show me the error here? – smk Jun 09 '13 at 04:41
  • Refer to [Communication in JSF 2: Processing GET request parameters](http://balusc.blogspot.com/2011/09/communication-in-jsf-20.html#ProcessingGETRequestParameters). Note that links in comments are meant for you to check the info provided there (this includes the links inside that Q/A as well). – Luiggi Mendoza Jun 09 '13 at 04:43

0 Answers0