Zay hf
Zay hf

Reputation: 139

@requestscope not working instead looks like sessionscope working as inital request is cashed

i am doing project using spring JSF integration I have @RequestScope bean with certain attributes which after suumitted in form(a search application) my list attribute of same bean gets populated from db values and viewed on same page using datatable (ajax applied on submit/search button). I get results fine first time i search but problem is when i refresh or open page in another browser page the datatable is still with the data of the initial request also navigating from other pages and back to same page still shows initial request page/data as if requestscope is not working instead session scope. i am using spring for managing beans and its creation and jsf for front end pages. Could this be problem with faces and spring anotation mixing if so what is the solution here??because i am also using DAO methods through autowiring of other beans. e.g.

@ManagedBean(name="inputService")
@RequestScoped
public class InputService {

 @Autowired
 AdvancSearchDaoImpl Dao;

 private String name;
 private String bloodgroup;
 private String dateofbirth;
 List<Result> searchResults;
 getter/setters of above attributes

   public String outputService()
    {
     searchResults=Dao.getAdvacnceServiceSearch(name,bloodgroup,dateofbirth);
    return "successful";
     }
   }

xhtml is:

  <div >
        <h:dataTable id="tbl" value="#{inputService.searchResults}" var="o" styleClass="display">
    <h:column>
    #{o.name}
    </h:column>
            <h:column>
    #{o.dateofbirth}
    </h:column>
           <h:column>
    #{o.bloodgroup}
       </h:column>
      </h:dataTable>

   </div>
  <h:form>
   <table>
   <tr><td>Full Name</td>
    <td>
    <h:inputText value="#{inputService.name}" styleClass="text-box" />
         </td></tr>

       <tr><td>Date of Birth</td>
          <td>
           <h:inputText  value="#{inputService.dateofbirth}" />
          </td></tr>

         <tr><td>Blood group</td>
         <td>
         <h:inputText  value="#{inputService.bloodgroup}" />
         </td></tr>

           <tr><td colspan="2" align="right">
                        <h:commandButton id="btnServiceSearch" value="Search" action="#{inputService.outputService}" styleClass="submitButton" >
                       <f:ajax execute="@form" render="tbl"></f:ajax>
                        </h:commandButton> </td> </tr>
 </h:form>

all the beans are defined in application context:

Upvotes: 0

Views: 1794

Answers (1)

Freak
Freak

Reputation: 6873

When I looked towards your code then I found a line

 @Autowired
 AdvancSearchDaoImpl Dao;

It means you are building a application using JSF + Spring. Now, You need to understand that When you are using two frameworks then we must need to handle scope for both frameworks(as I am sure about Spring+JSF).Now,In your case, JSF request scope is not working because your bean is captured by Spring as well.As Spring is Singleton scope by default so it is still present in the container.Now, You need to set the scope in spring context as well .You can do this by putting annotation on your bean

@RequestScoped

Or by make the entry in spring context and set scope there.Here you can find a brief tutorial about setting spring scopes

Upvotes: 1

Related Questions