【问题标题】:Dynamically loaded commandlinks not working动态加载的命令链接不起作用
【发布时间】:2014-03-18 15:48:05
【问题描述】:

我正在尝试使用<f:ajax render=":component"/> 动态加载视图。 那部分工作没有问题。但是,在该视图中使用 commandLinks 不会。

动态加载目标视图的容器:

<h:form>
    <h:commandLink>
        <f:param name="tmp2" value="tmp/newxhtml.xhtml"/>
        <f:ajax render=":newXhtml"/>
    </h:commandLink>
</h:form>

<h:panelGroup layout="block" id="newXhtml">
    <ui:include src="#{param['tmp2']}"/>
</h:panelGroup>

点击commandLink时,tmp2值被设置,'newXhtml'通过ajax重新渲染。

此链接在包含的 .xhtml 上,但无效:

<h:form>
    <h:commandLink>
        <f:ajax listener="#{backingBean.sampleMethod}"/>
    </h:commandLink>
</h:form>

BackingBean.java:

public class BackingBean{

    public void sampleMethod() {
         //breakpoint here is never hit
    }

}

【问题讨论】:

标签: java jsf


【解决方案1】:

当我不使用 &lt;f:ajax&gt; 包含页面而是使用普通的 &lt;h:commandLink&gt; 和 action 属性时,我让它工作,这会将包含页面保存到 @SessionScope bean 中。

包括xhtml:

 <h:form>
    <f:ajax render=":newXhtml">
        <h:commandLink action="#{includeBean.setIncludePage('tmp/newXhtml.xhtml')}">
        </h:commandLink>
    </f:ajax>
 </h:form>


 <h:panelGroup layout="block" id="newXhtml">
    <ui:include src="#{includeBean.includePage}"/>
 </h:panelGroup>

包含的 .xhtml 可以保持不变。

以及包含页面的支持 bean:

@Named
@SessionScope
public class IncludeBean implements Serializable {

  private static final long serialVersionUID = 1L;

  private String includePage;

  @PostConstruct
  public void init() {
    includePage = "tmp/newxhtml.xhtml";
  }

  public String getIncludePage() {
    return includePage;
  }

  public void setIncludePage(String includePage) {
    this.includePage = includePage;
  }

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多