Take the 2-minute tour ×

I'm currently stuck with a problem which would be solved easily using JSP. Anyhow I got a generated page which has an ID in it. Now JSF has to read this value at runtime (eg. loading of the page), and do a query on a DB with this ID and displaying the results. With JSP this would be a non-brainer but with JSF I do not know how to manipulate the data of the backing bean from the outside. Any ideas?

Thx in advance, Chris

share|improve this question
What is this ID for? How is this supplied? Hardcoded? Request parameter? –  BalusC Dec 15 '10 at 14:08
This ID is used to get entries in a DB which are connected to the ID. The ID is hardcoded. –  methical Dec 15 '10 at 14:58
Can you show how you did it in JSP? we can try in JSF –  mvg Dec 16 '10 at 5:35

2 Answers 2

up vote 1 down vote accepted

It's really beyond me that this ID is hardcoded in the view side, I would rather have made it part of the HTTP request someway (URI, parameter, etc) or just do it in the model, but ala.

You can use JSTL c:set to set a bean property from the view on and you can use its setter method or the f:view beforePhase to execute some stuff on render response.

<c:set scope="request" target="#{bean}" property="id" value="123" />
<f:view beforePhase="#{bean.onload}">


public class Bean {
    private String id; // +getter+setter

    public void onload(PhaseEvent event) {
        // Value of id is available here.
        System.out.println(id); // 123

    // ...
share|improve this answer
thanks for the hint, I think this will do it. The reason beyond all this is, that the CMS generates static pages. The author can select a DB in the CMS, the ID gets rendered into the page and due to some stupid technology decisions i'll have to stick around with JSF trying to fiddle out how to do this correctly. I wouldn't have used JSF in here but I'm just a henchman. –  methical Dec 17 '10 at 10:04

hm, do i understand correctly that you want to read out a GET argument from java code?

e.g. the url is http://www.example.com/?foo=bar

then you can read out the value in your java code with this snippet

FacesContext context = FacesContext.getCurrentInstance();
String theValue = context.getExternalContext().getRequestParameterMap().get("foo");
share|improve this answer
no its not a get parameter its rendered into the page before –  methical Dec 17 '10 at 10:01

Your Answer


