0

ok I am trying to use the f:param here to pass the requestid as parameter to the review page. Currently am doing it as shown below but managedproperty is not working as I want because I need to post again from review.xhtml. How can i add this f:param tag and then handle it in bean?

    <p:dataTable style="width:50px;" id="requestList" value="#
            {requestBean.requestsList}" var="requestClass">  
            <p:column>  
                <f:facet name="header">  
                    <h:outputText value="ID" />  
                </f:facet> 
                 <a href="review.xhtml?id=#{requestClass.requestID}">
                    <h:outputText value="#{requestClass.requestID}" />  
                 </a>

            </p:column>  

            <p:column>  
                <f:facet name="header">  
                    <h:outputText value="Status" />  
                </f:facet>  
                <h:outputText value="#{requestClass.requestStatus}" />  
            </p:column>  

              <p:column>  
                <f:facet name="header">  
                    <h:outputText value="Details" />  
                </f:facet>  
                  <h:outputText value="#{requestClass.requestTitle}" />  
            </p:column>
        </p:dataTable>  

Thanks

sys_debug
  • 3,883
  • 17
  • 67
  • 98
  • I am not totally understanding please confirm it,So you want to make `POST` not the `GET` – jmj Dec 19 '11 at 07:09
  • I'm not sure if I understand your situation correctly. I guess what you mean is that you want to use `` to pass the ID from the data table to the review.xhtml page. Besides, on the review.xhtml page, you also have a form which needs to submit the ID again but it's gone when you try to submit. Am I correct? – Mr.J4mes Dec 19 '11 at 09:09
  • possible duplicate of [How can I pass a parameter to a commandLink inside a datatable?](http://stackoverflow.com/questions/4994458/how-can-i-pass-a-parameter-to-a-commandlink-inside-a-datatable) – BalusC Dec 19 '11 at 12:09

4 Answers4

2

I think you can try the following:

. Keep your bean as RequestScoped and put a hidden field in your form in review.xhtml to contain the id:

<h:form>
   ...
   <h:inputHidden id="id" value="#{mrBean.id}" />
   ...
</h:form>

@ManagedBean(name = "mrBean")
@RequestScoped
public class MrBean {
   @ManagedProperty(value = "#{param.id}")
   private String id;
}

. Keep your bean as RequestScoped and put a <f:param> inside the commandButton in review.xhtml:

<h:form>
   ...
   <h:commandButton value="Submit">
      <f:param name="id" value="#{param.id)" />
   </h:commandButton>
</h:form>

. Change you bean to ViewScoped

@ManagedBean(name = "mrBean")
@ViewScoped
public class MrBean {
   private String id;

   @PostConstruct
   public void prepareReview() {
       HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
       id = request.getParameter("id");
   }
}
Mr.J4mes
  • 9,168
  • 9
  • 48
  • 90
  • i think this got to be the messy way. It is like trying to play a trick :( I need a solid answer. @edze above seems to get it, but i am getting a combo of key & value – sys_debug Dec 19 '11 at 09:36
  • hmmm I think what I tell you is not a trick ^^. It simply means that if you want to get the ID again, you need to store it somewhere on the form to get it again in the case of RequestScoped backing bean. Otherwise, you can use ViewScoped bean and get it once and for all. What I gave you above is what I have been doing ^^. I think you should go with my 2nd or 3rd option =). – Mr.J4mes Dec 19 '11 at 09:40
  • oh am sorry am quite new just seemed a bit tricky. It worked in that it actually has a string in id but I guess there is another issues I will have to investigate. either ways, thank you so much for being really helpful and patient :D – sys_debug Dec 19 '11 at 10:07
1

JSF

<p:column>  
    <f:facet name="header">  
        <h:outputText value="ID" />  
    </f:facet>
    <h:outputLink value="review.xhtml">
        <f:param name="myId" value="#{requestClass.requestID}" />
            <h:outputText value="#{requestClass.requestID}" />
    </h:outputLink>
</p:column> 

BEAN

Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
int requestID = Integer.parseInt(params.get("myId"));
edze
  • 2,965
  • 1
  • 23
  • 29
  • In the debugger in netbeans, it is showing the value of id as abc->9d9sd9sdsdsds7. I had to change your bean code to: id = params.get("requestID"); and that was the result. what can I do just to get the value and not key? – sys_debug Dec 19 '11 at 09:35
  • Ohhh. I forgot something. The method in the sitebean have to be @PostConstruct. Look at Mr.J4mes code :) – edze Dec 19 '11 at 09:47
0

Tables don't have f:params. They can however have f:attributes.

user207421
  • 305,947
  • 44
  • 307
  • 483
0

Use a h:outputLink or h:link with a nested f:param like in Edze's answer.

But then on review.xhtml, use an f:viewParam with name="myId" and a value binding to the backing bean of review.xhtml.

f:viewParam is a stateful component and will remember the value between subsequent requests, even if your backing bean is request scoped. An additional advantage is that with f:viewParam you can use normal JSF validators.

Google for BalusC's "communication in JSF 2" article for some examles.

Mike Braun
  • 3,729
  • 17
  • 15