簡體   English   中英

JSF-重定向到頁面並記住用於搜索的參數ID

[英]JSF - Redirect to page and remember parameter ID for searching

我有兩個xhtml頁面和兩個托管bean。

在第一頁上,我有一個主題列表(數據庫表中的記錄-第二列包含<h:commandLink>標記):

在此輸入圖像描述

簡化代碼的一部分:

<rich:column><h:outputText value="#{item.id}"/></rich:column>
<rich:column><h:outputText value="#{item.createdBy}"/></rich:column>
<rich:column>
  <h:commandLink value="#{item.topic}" action="#{myTools.setMenuItem('posts')}"/>
</rich:column>

我正在使用action="#{myTools.setMenuItem('posts')}"重定向到頁面posts.xhtml。 如何傳遞參數"#{item.id}"以找到具有給定ID的主題的所有帖子?

UPDATE(使用DataModel):可能是這樣的:

<h:commandLink value="#{item.topic}" action="#{myTopic.submit}">

public String submit()
{
  topic = model.getRowData();
  return "/posts.xhtml?faces-redirect=true&id=" + topic.getId();
}

但是我仍然不知道如何將topic.getId()參數傳遞給另一個bean(MyPosts)..?

只需通過它。

例如

<h:commandLink value="#{item.topic}" action="#{myTools.navigate('posts', item.id)}"/>

public String navigate(String menuItem, Long id) {
    this.menuItem = menuItem;
    return menuItem + "?faces-redirect=true&id=" + id;
}

Bean不需要也不需要在會話范圍內。 視圖范圍很好。 否則,最終用戶在多個瀏覽器選項卡/窗口中與同一頁面進行交互時將面臨不直觀的行為。

您可以使用 :

<f:setPropertyActionListener target="#{propertyToSet}" value="#{item.id}" />

在您的commandLink中。

您可以添加一個隱藏字段,在提交之前將ID存儲在該字段中(在Javascript中使用onclick ),然后將此隱藏字段綁定到Bean中的變量。

<h:inputHidden id="selectedId" value="#{beakbean.selectedId}">

<h:commandLink value="#{item.topic}" onclick="updateSelectedId()" action="#{myTools.setMenuItem('posts')}"/>

function updateSelectedId(){
    //put the selected id in the field selectedId
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM