Reputation: 4003
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
Upvotes: 0
Views: 5588
Reputation: 3769
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.
Upvotes: 0
Reputation: 3005
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"));
Upvotes: 1
Reputation: 9266
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");
}
}
Upvotes: 2
Reputation: 310860
Tables don't have f:params. They can however have f:attributes.
Upvotes: 0