Jsf 如何将参数从commandLink传递到outputPanel以自定义outputPanel内容
我使用以下代码根据用户的需求生成outputPanel。我想根据用户的响应定制outputPanel内容。因此,我需要将一个参数从commandLink传递到OutPanel。我怎样才能做到Jsf 如何将参数从commandLink传递到outputPanel以自定义outputPanel内容,jsf,jsf-2,primefaces,Jsf,Jsf 2,Primefaces,我使用以下代码根据用户的需求生成outputPanel。我想根据用户的响应定制outputPanel内容。因此,我需要将一个参数从commandLink传递到OutPanel。我怎样才能做到 <h:form> <p:commandLink value="Load" onclick="lazyload()" /> <p:remoteCommand name="lazyload" update="lazypanel"> <f:s
<h:form>
<p:commandLink value="Load" onclick="lazyload()" />
<p:remoteCommand name="lazyload" update="lazypanel">
<f:setPropertyActionListener value="#{true}" target="#{requestScope.shouldRender}"/>
</p:remoteCommand>
<p:outputPanel id="lazypanel">
<h:outputText value="This part is lazily loaded" rendered="#requestScope.shouldRender}"/>
</p:outputPanel>
</h:form>
可以像现在一样使用渲染属性。问题是您想如何定制它。根据情况,有很多方法。您可以逐个执行一组值,这些值仅在其值为true时呈现 i、 e 或者,如果您的范围更广,您可以使用
<p:outputPanel ...>
<h:outputPanel escape="false" value="#{bean.htmlWithoutEscapes}" />
</p:outputPanel>
至于传递参数
<p:commandLink actionListener="#{bean.onClick}"...>
<f:attribute name="someParam" value="#{someValue}" /> <!-- you can get this from the component attribute map -->
</p:commandLink>
//Managed Bean
public void onClick(ActionEvent evt)
{
Object param = evt.getComponent().getAttributes().get("someParam");
}
真的,我认为这是非常琐碎的事。显然,您需要定义输入和输出。我建议在requestScope上使用bean,因为PrimeFaces 2.2.1在文本转换器中有一个空指针,这在几周前刚刚修复。我不知道你为什么要用遥控器。它的使用是非常具体的,除非你需要这种特殊性,否则我怀疑你这样做只是增加了一些复杂性和出错的地方
如果您想在requestScope中完成这一切,您也可以这样做。。。我只是不推荐
我用它来搜索字符串等
<h:inputText value="#{requestScope.searchString}" style="width:95%;"/>
<p:commandButton value="Search" actionListener="#{inventoryBean.wardrobe.searchViaParameters}" update="inventoryWardrobe:searchForm">
<f:attribute name="searchString" value="#{requestScope.searchString}"/>
</p:commandButton>
我希望这会有所帮助,因为它是一个功能强大的组件。您的问题缺少一些东西:您希望用户如何指定所述参数?通过a?
<h:inputText value="#{requestScope.searchString}" style="width:95%;"/>
<p:commandButton value="Search" actionListener="#{inventoryBean.wardrobe.searchViaParameters}" update="inventoryWardrobe:searchForm">
<f:attribute name="searchString" value="#{requestScope.searchString}"/>
</p:commandButton>