【问题标题】:h:inputText not working with a4j:commandLinkh:inputText 不适用于 a4j:commandLink
【发布时间】:2013-04-15 14:00:58
【问题描述】:

myBeanrequest 范围内。

<h:form id="indexFormID">
<a4j:outputPanel ajaxRendered="true" layout="block">
    <h:inputText id="inputForHD" value="#{myBean.inputParam}"></h:inputText>
    <a4j:commandLink value="Submit" action="#{myBean.myMethod}" reRender="renderSuccess" process="indexFormID:inputForHD"></a4j:commandLink>
</a4j:outputPanel>


 <h:panelGroup id="renderSuccess">
    <h:panelGroup rendered="#{myBean.someBoolean}">
       //Some other JSF components go here          
    </h:panelGroup>
 </h:panelGroup>
</h:form>

MyBean类定义:

private String inputParam;
//Getters and setters are there

public String myMethod()
{
    log.debug("~ Value of inputParam" +this.getInputParam()); //This is printing null value for inputParam 
    //when commandLink is clicked
    return null;
}

为什么我的inputParam 没有设置输入参数?

【问题讨论】:

  • mymethod 是否被调用?
  • 您在 getter/setter 方法中处理什么?
  • @HimanshuBhardwaj myMethod 被调用。这没有问题。在我写的评论中,我在myMethod 内得到initParamnull 值@
  • @LuiggiMendoza 在 getter/setter 方法中没有进行额外的处理。他们只是 getter 和 setter。
  • 问题是你的组件ID是formID:outputPanelID:inputTextID,而你只是发送formID:inputTextID这是一个不正确的ID。

标签: jsf richfaces jsf-1.2


【解决方案1】:

好的,我发现您的方法存在一些问题:

<h:inputText id="inputForHD" value="#{myBean.inputParam}"></h:inputText>

你已经用这个 bean 映射了 inputParam 属性,为什么要有一个新的 Id "inputForHD"

使用 inputParam 本身,如果你想使用 inputForHD,你可以从 request Parameter map 中选择相同的。

String inputForHD = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("indexFormID:inputForHD");

正如我之前提到的,将输出面板包装在 a4j 面板中,例如

     <h:panelGroup id="renderSuccess">
        <h:panelGroup rendered="#{helloWorld.someBoolean}">
           //Some other JSF components go here
           <h:inputText id="inputForHDasdasd" value="#{helloWorld.inputParam}"></h:inputText>
        </h:panelGroup>
     </h:panelGroup>

一切正常,如有问题请告知。

【讨论】:

  • 看起来myBean.myMethod 正在根据myBean.inputParam 的值管理myBean.someBoolean 的值,所以如果myBean.someBooleanfalse 然后它变成true 就可以了(注意OP 不会重新渲染 h:panelGroup 而是重新渲染包装器 UIContainer &lt;a4j:outputPanel&gt;)。
  • 是的,我也是这么想的,这就是为什么我要求它在方法之后不会解析为“false”,否则它不会被渲染。我相信如果重新渲染外部容器,内部组件会自行重新渲染。应该是这样的。
  • 问题是 OP 没有在&lt;a4j:commandLink&gt;process 属性中为&lt;h:inputText&gt; 发送正确的ID。请参阅我的答案以获得解决方案。
  • 我已经看到了,也不反驳。我正在回复你的评论。
  • @HimanshuBhardwaj 尝试使用您更新的答案。但是,仍然没有得到输入的实际值。我仍然得到null 的价值。我什至将 myBean 的范围更改为 session 并将 getRequestParameterMap 更改为 getSessionMap。即使那样它也没有用!
猜你喜欢
  • 1970-01-01
  • 2015-02-13
  • 2013-06-29
  • 1970-01-01
  • 1970-01-01
  • 2011-04-25
  • 1970-01-01
  • 2011-12-24
  • 2010-12-21
相关资源
最近更新 更多