Jsf 一个按钮,多个动作
我有两个bean要调用,我想用一个按钮调用它们。如何做到这一点 以下是我的尝试: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
<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()}"/>