I have two beans to be called and I want to use one button to call them. How to do this?
Here is my try:
<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>
But it throws this error:
/calendar.xhtml @109,55 binding="#{uploadText.upload}": The class 'textView.UploadText' does not have the property 'upload'.
Only because I'm using binding here :
<h:commandButton action="#{uploadImage.upload}" value="Submit">
<f:actionListener binding="#{uploadText.upload}" />
</h:commandButton>
It says The class textView.UploadText
does not have the property 'upload' which is not true! I tried actionListner
as well but it's not working.
Here is uploadtext class:
public class UploadText implements Serializable {
private static final long serialVersionUID = 1L;
private String text;
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public void upload() {
if (text != null) {
try {
String f_username = JloginDAO.user;
Connection con = DBconnection.getConnection();
PreparedStatement pre = con.prepareStatement("insert into upload_text (text,user_idt) values(?, (SELECT id from users WHERE username = ?))");
pre.setString(1, text);
pre.setString(2, f_username);
pre.executeUpdate();
System.out.println("Inserting Successfully!");
pre.close();
FacesMessage msg = new FacesMessage("Succesful", text + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, msg);
} catch (Exception e) {
System.out.println("Exception-File Upload." + e.getMessage());
}
} else {
FacesMessage msg = new FacesMessage("Please select image!!");
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}
}