简体   繁体   English

JSF添加 <f:param> 到数据表

[英]JSF adding <f:param> to datatable

ok I am trying to use the f:param here to pass the requestid as parameter to the review page. 好的,我试图在这里使用f:param将requestid作为参数传递给审阅页面。 Currently am doing it as shown below but managedproperty is not working as I want because I need to post again from review.xhtml. 当前正在执行以下操作,但是Managedproperty不能按我的要求工作,因为我需要从review.xhtml重新发布。 How can i add this f:param tag and then handle it in bean? 我如何添加这个f:param标签,然后在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 谢谢

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: 将您的bean保持为RequestScoped,并在review.xhtml中的表单中放置一个隐藏字段以包含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: 将您的bean保持为RequestScoped,并在review.xhtml中的commandButton中放置一个<f:param>

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

. Change you bean to ViewScoped 将您的bean更改为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");
   }
}

JSF 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"));

Tables don't have f:params. 表格没有f:params。 They can however have f:attributes. 但是,它们可以具有f:attributes。

Use ah:outputLink or h:link with a nested f:param like in Edze's answer. 像在Edze的答案中一样,将ah:outputLink或h:link与嵌套的f:param一起使用。

But then on review.xhtml, use an f:viewParam with name="myId" and a value binding to the backing bean of review.xhtml. 但是,然后在review.xhtml上,使用带有name =“ myId”的f:viewParam和绑定到review.xhtml的支持bean的值。

f:viewParam is a stateful component and will remember the value between subsequent requests, even if your backing bean is request scoped. f:viewParam是一个有状态组件,即使您的支持bean是请求作用域的,它也会记住后续请求之间的值。 An additional advantage is that with f:viewParam you can use normal JSF validators. 另一个优点是,使用f:viewParam可以使用普通的JSF验证器。

Google for BalusC's "communication in JSF 2" article for some examles. Google for BalusC的“ JSF 2中的通信”文章有一些例子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM