I'm trying to get na few parameters (now it's two, but on the other xhtml probably I'll need more).
On page index.html I have a link, to page Threads.xhtml, with parameters user_id and section_id:
<h:dataTable value="#{Sections.sections}" var="Section">
<h:column>
<h:form>
<h:link value="#{Section.section_label}" outcome="Threads">
<f:param name="user_id" value="#{LoginIn.user_id}"/>
<f:param name="section_id" value="#{Section.section_id}"/>
</h:link>
</h:form>
</h:column>
</h:dataTable>
When I click into on of the links, it goes to for ex.:
Project/faces/Threads.xhtml?user_id=5§ion_id=2
So it's good :).
Now, on page Threads.xhtml I have a link (one link, not dataTable, as on index.xhtml - to create new section), to page NewThread.xhtml, with parameters user_id and section_id:
<h:form>
<h:link value="#{msg.create_new_thread}" outcome="NewThread">
<f:param name="user_id" value="#{param.user_id}"/>
<f:param name="section_id" value="#{param.section_id}"/>
</h:link>
</h:form>
When I click into on of the links, it goes to, for ex..:
Project/faces/NewThread.xhtml?user_id=5§ion_id=2
So it's also nice :).
Now, I check on NewThread.xhtml page values of user_id and section_id, by:
<h:outputText value="User_id: #{param.user_id}"/><br/>
<h:outputText value="Section_id: #{param.section_id}"/><br/>
And I see on page values:
User_id: 5
Section_id: 2
So ok :). But now, when I'm trying to get these values in Java code NewThread.java, they returns only null:
FacesContext facesContext = FacesContext.getCurrentInstance();
String user_id = (String) facesContext.getExternalContext().getRequestParameterMap().get("user_id");
String section_id= (String) facesContext.getExternalContext().getRequestParameterMap().get("section_id");
//For test:
System.out.println("User_id: " + user_id);
System.out.println("Section_id: " + section_id);
And in console i've got:
User_id: null
Section_id: null
I've also try toString() method, but it didn't help.
Going back to the index.xhtml, when I click on the link to one of the section, ex. second section (by any user, ex. user_id=5), it goes to Threads.xhtml:
Project/faces/Threads.xhtml?user_id=5§ion_id=2
And on Threads.xhtml I've got list of Threads of second section (but this part of xhtml code is irrelevant):
<h:dataTable value="#{Threads.threads}" var="Thread">
<h:column>
<h:link value="#{Thread.thread_label}" outcome="Threads">
<f:param name="thread_id" value="#{Thread.thread_id}"/>
</h:link>
</h:column>
</h:dataTable>
And on Java code of Threads.java, I've got:
FacesContext facesContext = FacesContext.getCurrentInstance();
String section_id = (String) facesContext.getExternalContext().getRequestParameterMap().get("section_id");
System.out.println("Section_id: " + section_id);
And in console i've got:
Section_id: 2
So WTF? Once it works, but another time it won't.
EDIT:
Sorry, I forgot. I access into NewThread.java, by commandButton in NewThread.xhtml:
<h:commandButton value="#{msg.add_thread}" action="#{NewThread.AddThread}"/>
and it calls AddThread method in NewThread.java; and in try (of try-catch) of AddThread method, there I'm trying to get parameters.
I've also already add into faces-config.xml:
<managed-bean>
<managed-bean-name>Threads</managed-bean-name>
<managed-bean-class>forum.Threads</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>NewThread</managed-bean-name>
<managed-bean-class>forum.NewThread</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>