【问题标题】:jsf2 template component with parameter带参数的jsf2模板组件
【发布时间】:2012-08-30 03:05:32
【问题描述】:

我有一个 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;
}

}

【问题讨论】:

    标签: jsf-2


    【解决方案1】:

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

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

    查看:

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

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

    豆子:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-15
      • 2014-09-08
      • 2016-04-16
      • 2011-08-25
      • 2012-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多