Question

I'll try to explain my problem. I use the JSF 1.2 implementation of IBM in a very very rigid environment (company layer, and strict constraints -don't add library etc.-).

I want to create a simple page for confirmation that can be reused (kind of generic). For example : 1-page1.jsp > click on button 2-pageConfirmation.jsp > 2 buttons Yes or No 3-click on No > go back / 3bis-click on Yes > go to someAction then go to page2.jsp

So I wanted to store in session the things I need, where I come from, where I want to go. But here's the problem : How can I invoke the action I want? The name is dynamic. Let's suppose I'm in the controller after I click on "Yes", I want to call the "myMethodAction" from its name which I stored in session. I thought about evaluating it using the expression-language api, but i'm blocked because I can't access the ELContext, and am not allowed to use the el package (el-api.jar).

To sum-up, after the click, I'm trying to invoke an action/method and then redirect to a page, instead of calling a page.

Do anyone have some magic ideas? Or am I just totally wrong?

Thanks in advance.

Was it helpful?

Solution

You can create a fully independent managed bean ConfirmationBean and put it in the request scope. You can access it in the "parent" bean by under each the managed property injection facility or just create it yourself and put it in request map.

The first way requires lot of work in faces-config.xml if you want to associate it with lot of other beans, so I don't think this is very attractive.

The second way only requires a bit of (reuseable) code in the action method. I'll give an example:

public String submit() {
    ConfirmationBean conformationBean = new ConfirmationBean();
    confirmationBean.setOutcome("outcome"); // Set navigation case outcome where it should return back.
    FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("confirmationBean", confirmationBean);
    return "confirm";
}

and the confirm.jsf should have the "outcome" in a hidden field, e.g.

<h:selectBooleanCheckbox value="#{confirmationBean.confirm}" />
<h:inputHidden value="#{confirmationBean.outcome}" />
<h:commandButton value="confirm" action="#{confirmationBean.submit}" />

the action method of ConfirmationBean should look like:

public String submit() {
    if (confirm) {
        return outcome;
    } else {
        return "confirm";
    }
}

or if you're a fan of ternary operators ;)

public String submit() {
    return confirm ? outcome : "confirm";
}

OTHER TIPS

So I come with two options : -Override the navigation management of JSF like this solution to enable EL in the to-view-id tag

(next solution in the next message, limited because I'm new on stackoverflow)

Second solution: -Call the action (string stored in the confirmationBean in session) invoking EL like this solution

That could be useful for some people here, but unavailable for me as I'm not allowed to import libraries (el-api).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top