带参数的jsf2模板组件

时间:2012-09-05 11:44:27

标签: jsf-2

我有一个jsf模板页面。在这个模板中,我想使用带参数的组件。其实我想迭代收集。此集合应由特定页面的参数确定。参数名称为selectedMenu。我如何在我的bean中使用它?

<div id="notes">
                    selectedMenu: #{selectedMenu}
                    <h:form>
                        <h:inputHidden value="#{notatkaController.searchForm.kategoria}">
                            <f:param value="#{selectedMenu}" />
                        </h:inputHidden>
                        <ui:repeat value="#{notatkaController.items}" var="item" varStatus="iter">
                            <f:param value="#{selectedMenu}" />
                            <p class="q-title"><strong><h:outputText value="#{item.ntaData}" /></strong></p>
                            <p class="answer"><h:outputText value="#{item.ntaDane}" escape="false" /></p>                                    
                        </ui:repeat>
                        <span>Moje notatki</span>
                        <textarea>Tu wpisz treść swojej notatki</textarea>
                        <span>[+] dodaj notatkę</span>
                    </h:form>
                </div>

我的豆子:

@ManagedBean(name = "notatkaController")
@ViewScoped
public class NotatkaController extends AbstractController<Notatka> implements Serializable {

@EJB
private pl.alfaprojekt.model.session.NotatkaFacade ejbFacade;
 private NotatkaSearchForm searchForm;

public DataModel getItems() {
    if (items == null)
        items = getPagination().createPageDataModel();
    return items;
}

public PaginationHelper getPagination() {
    if (pagination == null) {
        if (paginationSize == null)
            paginationSize = 10;
        pagination = new PaginationHelper(paginationSize) {

            @Override
            public int getItemsCount() {
                return getFacade().countByParam(getSearchForm());
            }

            @Override
            public DataModel createPageDataModel() {
                if (rapId == null)
                    return new ListDataModel(getFacade().findRangeByParam(getSearchForm(), new int[]{getPageFirstItem(), getPageFirstItem() + getPageSize()}));
                else {
                    Long uzyId = SessionUtil.getUser().getUzyId();
                    return new ListDataModel(convertToRaportWierszList(getFacade().findRangeByParam(getSearchForm(), new int[]{getPageFirstItem(), getPageFirstItem() + getPageSize()}), uzyId));
                }
            }
        };
    }
    return pagination;
}

}

1 个答案:

答案 0 :(得分:0)

我不确定我理解这个问题,但我回答的问题是:

我想动态显示一些东西。我想告诉它在访问页面时要显示什么。

查看:

然后您可以使用以下内容:

<f:event listener="#{myBean.myMethod}" type="preRenderView" />

Bean:

public void myMethod(ComponentSystemEvent event){
//your logic here
}

使用参数:

<f:metadata>
    <f:event listener="#{myBean.myMethod}" type="preRenderView" id="fevent"/>
    <f:attribute name="myParam" value="#{mySecondBean.param)" />
</f:metadata>

public void myMethod(ComponentSystemEvent event){
String id = (String) event.getComponent().getAttributes().get("myParam");
}