1
我試圖創建一個分頁程序複合材料部件。該組件應爲每個可用頁面提供一個commandLink。它看起來是這樣的:如何針對嵌套在一個界面內一個commandLink:重複,在複合組件?
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:cc="http://java.sun.com/jsf/composite"
xmlns:ui="http://java.sun.com/jsf/facelets">
<cc:interface>
<cc:attribute name="action" targets="jumpButton" required="true"/>
<cc:attribute name="bean" type="java.lang.Object" required="true"/>
</cc:interface>
<cc:implementation>
<ui:repeat value="#{cc.attrs.bean.pages}" var="page">
<h:commandLink id="jumpButton"
actionListener="#{cc.attrs.bean.jumpToPage(page)}">
<h:outputText value="#{page}"/>
</h:commandLink>
</ui:repeat>
</cc:implementation>
</html>
該組件在不同的頁面中使用這樣的:
<ccc:paginator bean="#{myBean}"
action="/index?faces-redirect=true&includeViewParams=true"/>
或者:
<ccc:paginator bean="#{myOtherBean}"
action="/dir/index?faces-redirect=true&includeViewParams=true"/>
注意使用面孔重定向=真實includeViewParams的= true,據我所知,它不能直接用在複合組件的commandLinks上。
的問題是,jumpButton不可能是目標,因爲它是一個界面內:重複。我得到的消息:
javax.servlet.ServletException: /index?faces-redirect=true&includeViewParams=true : Unable to re-target MethodExpression as inner component referenced by target id 'jumpButton' cannot be found.
如果我創建UI外使用id =「jumpButton」命令鏈接:重複,複合材料部件和按鈕正常工作。如何使我的複合組件在ui中的命令鏈接上工作:repeat?
解決方案
管理bean的jumpToPage行動:
public String jumpToPage(String path, Integer page) {
...
setCurrentPage(page);
return path;
}
的複合成分:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:cc="http://java.sun.com/jsf/composite"
xmlns:ui="http://java.sun.com/jsf/facelets">
<cc:interface>
<cc:attribute name="bean" type="java.lang.Object" required="true"/>
<cc:attribute name="path" type="java.lang.String" required="true"/>
</cc:interface>
<cc:implementation>
<ui:repeat value="#{cc.attrs.bean.pages}" var="page">
<h:commandLink id="jumpButton"
action="#{cc.attrs.bean.jumpToPage(cc.attrs.path, page)}">
<h:outputText value="#{page}"/>
</h:commandLink>
</ui:repeat>
</cc:implementation>
</html>
組件用法示例:
<ccc:paginator bean="#{myBean}"
path="/index?faces-redirect=true&includeViewParams=true"/>
<ccc:paginator bean="#{myOtherBean}"
path="/dir/index?faces-redirect=true&includeViewParams=true"/>
謝謝,我已經做了一些改動原來的問題。據我知道這是不可能的,我使用'?在複合材料部件直接面對重定向=真includeViewParams = TRUE;在commandLinks。如果不是這樣,你的建議就有效。但是'?面臨重定向=的分頁程序的真includeViewParams = TRUE;一部分是很重要的。 –
看到我的更新。您仍然不需要組件上的action屬性。 – fischermatte
謝謝!很簡單。不能相信我讓它變得如此複雜。我已經用結果更新了我的問題。它完美的作品。 –