Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 一个按钮,多个动作_Jsf_Jsf 2_Primefaces - Fatal编程技术网

Jsf 一个按钮,多个动作

Jsf 一个按钮,多个动作,jsf,jsf-2,primefaces,Jsf,Jsf 2,Primefaces,我有两个bean要调用,我想用一个按钮调用它们。如何做到这一点 以下是我的尝试: <h:form enctype="multipart/form-data"> <p:inputTextarea rows="6" cols="33" autoResize="false" value="#{uploadText.text}" maxlength="174" /> </h:form> <h:form enct

我有两个bean要调用,我想用一个按钮调用它们。如何做到这一点

以下是我的尝试:

<h:form enctype="multipart/form-data">
    <p:inputTextarea rows="6" cols="33" autoResize="false"
                     value="#{uploadText.text}" maxlength="174" />
</h:form>

<h:form enctype="multipart/form-data">
    <p:messages showDetail="true" />
    <p:panelGrid columns="2" style=" width:30px;">
        <h:outputLabel id="image" value="Select Image: *" />
        <p:fileUpload value="#{uploadImage.file}" mode="simple"
                      allowTypes="/(\.|\/)(gif|jpe?g|png)$/" />
    </p:panelGrid>

    <h:commandButton action="#{uploadImage.upload}" value="Submit">
        <f:actionListener binding="#{uploadText.upload}" />
    </h:commandButton>
</h:form>
只是因为我在这里使用绑定:

<h:commandButton action="#{uploadImage.upload}" value="Submit">
    <f:actionListener binding="#{uploadText.upload}" />
</h:commandButton>
如果您查看,您将看到
绑定
属性必须计算为
javax.faces.event.ActionListener
。这意味着
UploadText
类需要实现
javax.faces.event.ActionListener
接口(您有一个例子)

最简单的选择(取自)是向bean中添加如下方法:

public ActionListener createActionListener() {
    return new ActionListener() {
        @Override
        public void processAction(ActionEvent event) throws AbortProcessingException {
            System.out.println("here I have both the event object, and access to the enclosing bean");
        }
    };
}
并从
f:actionListener

<f:actionListener binding="#{uploadText.createActionListener()}"/>


使用这种技术,你可以用一个按钮调用多个方法。

你也可以显示这个类吗?请看上面的编辑文章@HoXaUpload是method而不是property,你不需要添加括号吗?action=“#{uploadImage.upload()}”您应该使用
类型
属性来引用它的实现(完全限定的类名),它是在
ActionListner
属性上实现的,或者仅在
actionListener
属性上实现的
public ActionListener createActionListener() {
    return new ActionListener() {
        @Override
        public void processAction(ActionEvent event) throws AbortProcessingException {
            System.out.println("here I have both the event object, and access to the enclosing bean");
        }
    };
}
<f:actionListener binding="#{uploadText.createActionListener()}"/>