3 Replies Latest reply on Apr 25, 2013 7:19 AM by androsov

    JSF REST-post troubles

    androsov

      Hello!

      I'm newbie in JSF. Also I'm from Russia and my English is bad. So I hope you'll forgive me if I write stupidities.

       

      I use richfaces 4.3 and Eclipse Juno as my enviroment. I'm trying to use get-post as I've red in book of David Herry.

      So I've wrote been-class

      @ManagedBean
      @SessionScoped
      public class NavigateGetBean implements Serializable{
      
      
                private static final long serialVersionUID = 1L;
      
      
                private HashMap<String, JsfView> views;
        
                private JsfView workZone;
        
                public NavigateGetBean() {
                          views = new HashMap<String, JsfView>();
                          views.put("1", new JsfView("work_zone", "/pages/views/mainView1.xhtml"));
                          views.put("2", new JsfView("work_zone", "/pages/views/mainView2.xhtml"));
                          workZone=views.get("1");
                }
      
      
                public String getWorkZone() {
                          return workZone.getWay();
                }
      
      
                public void setWorkZone(String workZone) {
                          this.workZone = views.get(workZone);
                }
        
        
        
      }
      

      I've wrote xhtml View

      <ui:composition  xmlns="http://www.w3.org/1999/xhtml"
            xmlns:h="http://java.sun.com/jsf/html"
            xmlns:f="http://java.sun.com/jsf/core"
            xmlns:ui="http://java.sun.com/jsf/facelets"
            xmlns:a4j="http://richfaces.org/a4j">
                <f:metadata>
                          <f:viewParam name="view" value="1"/>
                </f:metadata>
                <h:link value="view1" includeViewParams="true" outcome="main" >
                          <f:param name="view" value="1"/>
                </h:link>
                <br/>
                <h:link value="view2" includeViewParams="true" outcome="main?view=2" /><br/>
                <h:link value="view3" includeViewParams="true" outcome="main?view=3" />
            
      </ui:composition>
      

       

      I've added breakpoint on getWorkZone() and setWorkZone() methods. When my page opens this view, getter is called (I don't sure it is right, but it is so). But when I click link, setter is NOT called. So I don't know where I made mistake. And if I made it.

        • 1. Re: JSF REST-post troubles
          michpetrov

          Hi!

           

          The setter isn't being called because you are not callling it

           

          It should look like this:

           

          <ui:composition  xmlns="http://www.w3.org/1999/xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:a4j="http://richfaces.org/a4j">
                    <f:metadata>
                              <f:viewParam name="view" value="#{navigateGetBean.workZone}"/>
                    </f:metadata>
                    <h:link value="view1" includeViewParams="true" outcome="main" >
                              <f:param name="view" value="1"/>
                    </h:link>
                    <br/>
                    <h:link value="view2" includeViewParams="true" outcome="main?view=2" /><br/>
                    <h:link value="view3" includeViewParams="true" outcome="main?view=3" />
                
          </ui:composition>

          • 2. Re: JSF REST-post troubles
            androsov

            Oh, I'm so sorry. This mistake was made by me when I was trying done itworking.

            Of course I've tryed as you write. But it still doesn't working :C

            • 3. Re: JSF REST-post troubles
              androsov

              Trouble was in a place where I had written metadata-block

              I've replace it from view to page and now it's working.

               

              <?xml version="1.0" encoding="UTF-8"?>
              <!--main.xhtml-->
              <ui:composition template="/pages/templates/mainTemplate.xhtml"
                        xmlns="http://www.w3.org/1999/xhtml"
                              xmlns:ui="http://java.sun.com/jsf/facelets"
                              xmlns:f="http://java.sun.com/jsf/core"
                              xmlns:h="http://java.sun.com/jsf/html"
                              xmlns:a4j="http://richfaces.org/a4j"
                              xmlns:rich="http://richfaces.org/rich">
                         <f:metadata>
                                  <f:viewParam name="view" value="#{navigateGetBean.workZone}"/>
                        </f:metadata>
                        <ui:define name="right-menu">
                                  <ui:include src="/pages/views/navigateView.xhtml"/>
                        </ui:define>
                                  <ui:define name="work-zone">
                                  <ui:include src="#{navigateGetBean.workZone}"/>
                        </ui:define>
              
              </ui:composition>
              
              <!--navigateView.xhtml-->
              <ui:composition  xmlns="http://www.w3.org/1999/xhtml"
                    xmlns:h="http://java.sun.com/jsf/html"
                    xmlns:f="http://java.sun.com/jsf/core"
                    xmlns:ui="http://java.sun.com/jsf/facelets"
                    xmlns:a4j="http://richfaces.org/a4j">
              
                        <h:link outcome="main" value="view1">
                                  <f:param name="view" value="1"/>
                        </h:link>
                        <br/>
                        <h:link value="view2" includeViewParams="true" outcome="main?v=2" /><br/>
                        <h:link value="view3" includeViewParams="true" outcome="main?view=3" />
              
              </ui:composition>