如何将参数从commandLink传递到outputPanel以自定义outputPanel内容
我使用以下代码根据用户的需求生成 outputPanel
。 我想根据用户的响应自定义 outputPanel
内容。因此我需要将参数从 commandLink
传递到 ouputPanel.我怎样才能这样做呢?
<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>
I am using the following code to generate an outputPanel
on user's demand. I want to customize the outputPanel
content acc to the user's response. Thus I need to pass a parameter from commandLink
to ouputPanel
. How can I do so ?
<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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(1)
您可以像现在一样使用渲染的属性。问题是你想如何定制它。根据具体情况,有很多种方法。您可以根据具体情况设置一组值,这些值仅在其值为 true 时才呈现。
即
或者如果您获得更广泛的范围,您可以直接将 HTML 注入到面板中,
至于传递参数
真的,我认为这是非常简单的。显然您需要定义输入和输出。我建议在 requestScope 上使用 bean,只是因为 PrimeFaces 2.2.1 在转换器中对于几周前刚刚修复的文本有一个空指针。我不确定你为什么要使用远程命令。它的使用非常具体,除非您需要这种特殊性(我怀疑您确实需要),否则它只是增加了一些复杂性和出错的地方。
如果你想在 requestScope 中完成这一切,你也可以这样做......我只是不推荐它。
我将它用于搜索字符串等...
我希望有所帮助,它是一个强大的组件。
You can use the rendered property like you're doing now. The question is how you want to customize it. There's a fair number of ways depending on the situation. You can do a case by case set of values that are only rendered when their value is true.
i.e.
or if you're getting a much wider range you can directly inject HTML into the panel with
As far as passing parameters
Really I think it is pretty trivial to do. Obviously you need to define the input and output. I'd recommend using a bean over the requestScope simply because PrimeFaces 2.2.1 has a null pointer in the converter for text that was just fixed a few weeks back. I'm not sure why you're after the remote command. Its use is pretty specific and unless you have a need for that specificity (I would doubt you do) it is just adding some complexity and places for things to go wrong.
If you want to do it all in requestScope you can do that too... I just wouldn't recommend it.
I use it for things like a search string etc...
I hope that helps, its a powerful component.