gpt4 book ai didi

jsf - 使用 f :attribute for commandButton instead of f:param for h:commandLink

转载 作者:行者123 更新时间:2023-12-04 10:11:53 25 4
gpt4 key购买 nike

我想根据单击的按钮包含特定页面。

到目前为止 h:commandButton用过,不能用f:param ,所以看起来我应该使用 f:attribute标签。

如果是 f:param我会这样编码:

<h:commandLink action="connectedFilein">
<f:param name="fileId" value="#{fileRecord.fileId}"/>
<h:commandLink>

<c:if test="#{requestParameters.fileId!=null}">
<ui:include src="fileOut.xhtml" id="searchOutResults"/>
</c:if>

什么是 f:attribuite案件?

谢谢

最佳答案

我假设您使用的是 JSF 1.x,否则这个问题没有意义。 <f:param><h:commandButton>旧版 JSF 1.x 确实不支持,但从 JSF 2.0 开始就支持了。
<f:attribute>可与actionListener结合使用.

<h:commandButton action="connectedFilein" actionListener="#{bean.listener}">
<f:attribute name="fileId" value="#{fileRecord.fileId}" />
</h:commandButton>


public void listener(ActionEvent event) {
this.fileId = (Long) event.getComponent().getAttributes().get("fileId");
}

(假设它是 Long 类型,这是一个经典的 ID)

然而更好的是使用引入的 JSF 1.2 <f:setPropertyActionListener> .
<h:commandButton action="connectedFilein">
<f:setPropertyActionListener target="#{bean.fileId}" value="#{fileRecord.fileId}" />
</h:commandButton>

或者,当您已经在运行支持 Servlet 3.0/EL 2.2 的容器(Tomcat 7、Glassfish 3 等)和您的 web.xml 时声明符合 Servlet 3.0,那么您可以将其作为方法参数传递。
<h:commandButton action="#{bean.show(fileRecord.fileId)}" />


public String show(Long fileId) {
this.fileId = fileId;
return "connectedFilein";
}

与具体问题无关,我强烈建议尽可能使用 JSF/Facelets 标签而不是 JSTL 标签。
<ui:fragment rendered="#{bean.fileId != null}">
<ui:include src="fileOut.xhtml" id="searchOutResults"/>
</ui:fragment>

(A <h:panelGroup> 也是可能的,并且是使用 JSP 代替 Facelets 时的最佳方法)

关于jsf - 使用 f :attribute for commandButton instead of f:param for h:commandLink,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5221299/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com