1

On various places they said that you should use @ManagedProperty to get a request parameters. The problem is that I try to get the token from the request string but it somehow stays null all the time.

The link where the page is with called looks like this:

http://example.com/faces/Check.xhtml?token=EC-8AT450931P272300C&ID=VKEFF29XNGNJG

The bean:

@Named(value = "bean")
@RequestScoped
public class Bean implements Serializable {

    @Inject
    private AccountBean account;
    @Inject
    private Service web;
    @ManagedProperty(value = "#{param.token}")
    private String token;
    @ManagedProperty(value = "#{param.ID}")
    private String id;

    @PostConstruct
    public void init() {
        System.out.println("token: " + token);
    }

The page

<ui:define name="content">
    <h:form>
        <pou:commandButton action="#{bean.test()}" value="complete"/>
    </h:form>
</ui:define>

And other things I tried:

Map<String, String> e = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();

This doesn't contain the request parameters also. Same goes for all the facesContext things where you can get requests with.

Help will be appreciated.

P.S. I can't change anything behind the ? cause its called from a program not in my reach

Niceone
  • 31
  • 2
  • 5
  • see http://stackoverflow.com/questions/10058852/inject-to-pass-params-to-a-cdi-named-bean-via-url-gives-jboss-error-on-netbean basically, this is the wrong approach. Let me know if you figure it out! You cannot use @ManagedProperty with Named, they are incompatible. – Thufir Apr 08 '12 at 06:04
  • ohw that helps... and the suggested solve doesn't really work for me... – Niceone Apr 08 '12 at 11:05
  • Ty Thufir for pointing me to that post – Niceone Apr 08 '12 at 12:10

1 Answers1

0

Okay made it work.

@Inject to pass params to a CDI @Named bean via URL

This was the solution just needed to add a few more things to my site

<ui:define name="content">
    <h:form>
        <h:inputHidden value="#{bean.token}"/>
        <h:inputHidden value="#{bean.id}"/>
        <pou:commandButton action="#{bean.test()}" value="complete"/>
    </h:form>
</ui:define>

And remove the #{param.xxx} part from the naming

@Inject @HttpParam
private String token;
@Inject @HttpParam(value = "ID")
private String id;
Community
  • 1
  • 1
Niceone
  • 31
  • 2
  • 5