0
我是新來的xhtml,我試圖通過一個特定的名稱(拍賣名稱在我的情況下)在表的單元格內使用href。當我按拍賣的名字時,我想要在另一個頁面內發送添加出價,看到最高出價等。它只是向我展示了引用頁面中的最後一個面板組(它表示:此次拍賣沒有出價)。如何在rich:column中使用href?
有人可以幫我嗎?
從豐富的代碼:柱是auctionList.xhtml:
<composite:implementation>
<rich:dataTable id="auctionsTable" rows="6" value="#{cc.attrs.auctions}" var="auct" border="1" styleClass="flat list auctions" rendered="#{cc.attrs.rendered and not empty cc.attrs.auctions}">
<f:facet name="header">
<rich:dataScroller forComponent="auctionsTable" />
</f:facet>
<h:link outcome="/destination" value="link" />
<rich:column sortBy="#{auct.name}" sortOrder="ascending" >
<a href="detail.xhtml">
#{auct.name}
</a>
</rich:column>
和detail.xhml是:
<ui:composition>
<h2>Details</h2>
<h:panelGroup layout="div"
rendered="#{auctionManager.currentAuction != null}">
<a4j:poll interval="3000" render="highestBidOutput, bidHistory" action="#{auctionManager.refreshAuction(currentAuction)}" />
<h3>#{currentAuction.name}</h3>
<h:panelGrid>
<h:column>
<h:outputLabel value="ID:" />
<h:outputText value="#{currentAuction.id}" />
</h:column>
<h:column>
<h:outputLabel value="Owner:" />
<h:outputText value="#{currentAuction.owner.name}" />
</h:column>
<h:column>
<h:outputLabel value="Original price:" />
<h:outputText value="#{currentAuction.originalPrice}" />
</h:column>
<h:column>
<h:outputLabel value="Description:" />
<h:outputText value="#{currentAuction.description}" />
</h:column>
<h:column>
<h:outputLabel value="Location:" />
<h:outputText value="#{currentAuction.location}" />
</h:column>
</h:panelGrid>
<h:panelGrid columns="2">
<h:outputLabel value="Highest bid:"
rendered="#{not empty currentAuction.highestBid}" />
<h:outputText id="highestBidOutput"
value="#{currentAuction.highestBid.amount} (#{currentAuction.highestBid.bidder.name})"
rendered="#{not empty currentAuction.highestBid}" />
<h:outputLabel value="Bid" rendered="#{loginManager.logged}" />
<h:form rendered="#{loginManager.logged}">
<h:inputText id="bidAmountInput" value="#{bidAmount}"
validator="#{bidValidator.validateBid}" />
<h:commandButton value="Add"
action="#{auctionManager.addBid(bidAmount)}" />
<h:messages style="color: red" />
</h:form>
</h:panelGrid>
<h:panelGroup id="bidHistory" rendered="#{not empty currentAuction.bids}">
<h3>Bids</h3>
<h:dataTable var="offer" value="#{currentAuction.bids}" border="1"
styleClass="flat">
<h:column>#{offer.bidder.name}</h:column>
<h:column>#{offer.amount}</h:column>
</h:dataTable>
</h:panelGroup>
</h:panelGroup>
<h:panelGroup layout="div"
rendered="#{auctionManager.currentAuction == null}">
<p>No bids for given auction.</p>
</h:panelGroup>
和AuctionManagerImpl.java在detail.xhtml使用:
private static final long serialVersionUID = 1L;
private Auction currentAuction = null;
@PersistenceContext(type=PersistenceContextType.EXTENDED)
private EntityManager em;
@Inject
private LoginManager loginManagerBean;
@Resource SessionContext sessionContext;
@Produces
@Named
@Dependent
@CurrentAuction
@PermitAll
public Auction getCurrentAuction() {
if (currentAuction != null && !em.contains(currentAuction)) {
currentAuction = em.merge(currentAuction);
}
return currentAuction;
}
@PermitAll
public Long getCurrentAuctionId() {
return (currentAuction == null) ? null : currentAuction.getId();
}
@PermitAll
public void setCurrentAuctionId(Long currentId) {
this.currentAuction = em.find(Auction.class, currentId);
}
@PermitAll
public List<Auction> getAll() {
return em.createQuery("SELECT a FROM Auction a", Auction.class)
.getResultList();
}
@PermitAll
public List<Auction> getAuctionsWinningByUser(User user) {
String jql = "SELECT auction FROM Auction auction, User user "
+ "WHERE user=:user AND auction.highestBid member of user.bids "
+ "ORDER BY auction.id";
TypedQuery<Auction> query = em.createQuery(jql, Auction.class);
query.setParameter("user", user);
List<Auction> auctions = query.getResultList();
return auctions;
}
@PermitAll
public List<Auction> getAuctionLoosingByUser(User user) {
String jql = "SELECT DISTINCT auction FROM User user "
+ "JOIN user.bids bid JOIN bid.auction auction "
+ "WHERE user=:user AND auction.highestBid.bidder != user "
+ "ORDER BY auction.id";
TypedQuery<Auction> query = em.createQuery(jql, Auction.class);
query.setParameter("user", user);
List<Auction> auctions = query.getResultList();
return auctions;
}
@PermitAll
public void refreshAuction(Auction auction) {
em.refresh(auction);
}
//@PermitAll
public void addBid(long bidAmount) {
if (sessionContext.getCallerPrincipal() == null) {
throw new IllegalStateException(
"user must be logged in order to add bid");
}
if (currentAuction == null) {
throw new IllegalStateException(
"currentAuction have to be selected in order to add bid");
}
Bid bid = new Bid(loginManagerBean.getCurrentUser(), currentAuction, bidAmount);
em.persist(bid);
em.flush();
em.refresh(bid);
}
}
也是非常重要的是list.xhtml,我利用auctionList.xhtml的:
<ui:composition template="templates/home.xhtml">
<ui:param name="activeTab" value="list" />
<ui:define name="content">
<h2>Auction List</h2>
<a:auctionList auctions="#{auctionManager.all}" />
</ui:define>
OK。謝謝。我將在auctionList.xhtml中調用sendToPageAndPutValue()方法.. paramName,paramValue應該是拍賣的名稱?..我看不到如何使拍賣的名稱和命令按鈕之間的連接(我不喜歡使用< h:selectOneMenu>,你能告訴我另外一個解決方案嗎?),並且爲了目標頁面,我將創建另一個類(「DestinationBean」)..我的問題是:要獲得目標bean的GET值,可以在detail.xhtml(我的目的地頁面)的呼叫?雖然我的是這樣的:
帕拉姆:#{} destinationbean.paramName
– DaianaB命令按鈕將調用該方法sendToPageAndPutValue()方法中,你必須給一個名稱爲拍賣寄這封信給其他bean時,PARAMNAME使用爲了恢復價值,就這樣,通過這種方式,你可以發送任何對象到其他bean的任何地方。 這將使用paramName:currentAuction = FacesContext.getCurrentInstance()。getExternalContext()。getFlash()。get(「paramName」);返回將放入請求的對象。 –
好的。因此,這不是更好的實現方法:sendToPageAndPutValue()在拍賣類(放聲明屬性附加傷害參數值的方式拍賣的名字),而不是創建一個類你的bean?我有一個名爲Auction.java的類,也是一個AuctionManagerImpl.java? – DaianaB