1

I have a Spring-JSF integrated application. Integration is done with SpringBeanFacesELResolver. My bean class in managed by Spring. Now I am looking to get my query string parameter value inside the bean in 'Spring way'. I am able to get the query string parameter value in 'JSF way' as follows, which I don't want to use as the bean is managed by Spring.

FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("myParamName");

Can you please suggest the Spring way to get those?

From my xhtml file I call the method in bean as follows

<h:commandLink  action="#{myUserBean.onUserLoad}">

This is the pseudo code of my bean class

@Component
@Scope("session")
public class MyUserBean {

    @Autowired
    private UserService userService;


    public String onUserLoad() {
              //get the request parameter value here
    }
 }
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Rakesh
  • 217
  • 2
  • 10
  • You use JSF, so why do you want it differently? It is the normal way, independend of what manages the beans. JSF, CDI, Spring… – Kukeltje Jul 14 '15 at 06:40
  • @Kukeltje, If the bean is managed by Spring, it would be good if I can manage it completely with Spring. – Rakesh Jul 14 '15 at 07:05
  • Why would that be **good**? You probably can achieve this by adding additional filters in the web.xml (not sure if these exist in spring or have to be written yourself) and then pray that all kinds of other problems do not show up, or just use this... And (and now I am a liddly kidding you, but not totally): If you want to go the Spring way, why not drop JSF and use Spring MVC? – Kukeltje Jul 14 '15 at 07:10
  • 2
    "JSF way" is by the way `` or `@ManagedProperty`. Manually accessing the request parameter map as you've shown is more like a workaround for cornercase situations. The `` approach should work as good with beans managed by a 3rd party framework instead of by standard Java EE. – BalusC Jul 14 '15 at 07:10
  • @Kukeltje, the reason for moving more towards 'Spring way' is in the future for some reason if I drop JSF the impact should be minimum. This drop case is not because the advantage or disadvantage of one over the other, it is purely business. – Rakesh Jul 14 '15 at 07:28
  • @BalusC, thank you very much for your valuable suggestion. – Rakesh Jul 14 '15 at 07:29
  • So, I gather this is acceptable as dupe? http://stackoverflow.com/questions/10724428/how-do-i-process-get-query-string-url-parameters-in-backing-bean-on-page-load – BalusC Jul 14 '15 at 07:34
  • 1
    Then you can always wrap those jsf specific calls in a custom utility class and change the implementation of that in one place if you switch jsf out. But BalusC suggestion (which is obviously correct) you have to do more work in the views if switching… or if the new mvc does not support it, still augment your beans. – Kukeltje Jul 14 '15 at 07:42

1 Answers1

0

Use org.springframework.web.context.request.RequestContextHolder to get your solution

Sam
  • 554
  • 1
  • 12
  • 23