【问题标题】:RichFaces commandbutton onclick methodsRichFaces commandbutton onclick 方法
【发布时间】:2011-09-09 14:45:55
【问题描述】:

我正在使用 RichFaces 命令按钮,我需要它在单击时执行两个功能,一个接一个。现在,我有这样的代码:

<a4j:commandButton  styleClass="btn-hide"
                                        onl
                                        id="btnId"  
                                        type="submit" 
                                        value="addNew"
                                        rendered="true" 
                                        reRender="panel"
                                        eventsQueue="eventQueue"    
                                        status="eventQueue" 
                                        actionListener="#{(someMethod.something)}"                                           
                                        oncomplete="javascript:something;this.disabled=false"
                                        onclick="Bean.setDesc(document.getElementById('inputArea').value);this.disable=false"
                                        ignoreDupResponses="true"
                                        immediate= "true"> 
                                          <s:conversationId></s:conversationId>
                            </a4j:commandButton>

如果您查看 onclick 部分,我需要先运行 Bean.setDesc,然后再运行 this.disabled=false。我将如何按时间顺序执行此操作?

谢谢

【问题讨论】:

  • onclick 是一种客户端方法。 Bean 是 javascript 对象还是您正在寻找触发 ajax 请求的方法?
  • Bean 不是 javascript 对象。这是一个java方法。
  • inputArea 是 jsf 组件吗?
  • 是的,inputArea 是一个 jsf 组件。

标签: javascript jsf richfaces ajax4jsf


【解决方案1】:

这是一个帮助您入门的代码存根。如果您希望直接从客户端获取值并使用 javascript 将它们传递给服务器方法,则需要使用 a4j:jsFunction。

<h:form id="form1" prependId="false">        

    <a4j:jsFunction 
        name="setDesc"
        action="#{exampleBean.actionMethod()}" 
        immediate="true">
        <a4j:param name="inputAreaValue" assignTo="#{exampleBean.desc}"/>
    </a4j:jsFunction>

    <h:commandButton id="button" onclick="setDesc(document.getElementById('inputArea').value); this.disabled = true;" />
</h:form>

和托管 bean:

@ManagedBean(name = "exampleBean")
@SessionScoped
public class ExampleBean implements Serializable {

    private static final long serialVersionUID = 6823632613070575039L;

    private String desc;

    public String getDesc() { return desc; }
    public void setDesc(String desc) { this.desc = desc; }

    /**
     * Action Method 
     */
    public void actionMethod() {
        // do something here
    }


}

【讨论】:

  • 谢谢,但请您解释一下 action="#{jsFunctionBean.actionMethod}" 是什么?
  • 可以是您想要调用的任何操作方法。在您的示例中,您有 actionListener="#{(someMethod.something)}"。大概你想在 Bean.desc 上设置 inputArea 的值,然后在服务器端做其他事情?如果您不想要该功能,您可以删除该属性。
猜你喜欢
  • 1970-01-01
  • 2014-03-17
  • 2010-12-26
  • 2017-02-21
  • 1970-01-01
  • 1970-01-01
  • 2013-05-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多