我的jsf命令按鈕沒有調用它應該調用的方法。這裏是代碼:JSF命令按鈕不調用bean方法
<h:form>
<h:outputText value="Data de nascimento"
style="font-size: 15px; float:left;margin-left:20%;" />
<br />
<h:inputText value="#{registroPageMBean.usuario.nascimento}"
styleClass="default_input"
style="float:left;margin-left:20%;width:60%"></h:inputText>
<h:outputText value="Foto de Perfil"
style="font-size: 15px; float:left;margin-left:20%;" />
<br />
<p:fileUpload value="#{registroPageMBean.file}" mode="simple"
skinSimple="true" label="Enviar arquivo" />
<br />
<br />
<br />
<h:commandButton rendered="true" styleClass="default_button" value="Finalizar"
action="#{registroPageMBean.registrar}" />
</h:form>
我嘗試了一切,但它沒有奏效。誰能幫我這個?
這裏是Bean方法:
@RequestScoped
@ManagedBean(name = "registroPageMBean")
public class RegistroPageMBean {
private Usuario usuario;
private UploadedFile file;
public RegistroPageMBean() {
usuario = new Usuario();
System.out.println("INICIANDO");
}
public static BufferedImage toBufferedImage(Image img) {
if (img instanceof BufferedImage) {
return (BufferedImage) img;
}
// Create a buffered image with transparency
BufferedImage bimage = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB);
// Draw the image on to the buffered image
Graphics2D bGr = bimage.createGraphics();
bGr.drawImage(img, 0, 0, null);
bGr.dispose();
// Return the buffered image
return bimage;
}
public static void saveToFile(BufferedImage img) throws FileNotFoundException, IOException {
File outputfile = new File("imagem.png");
ImageIO.write(img, "png", outputfile);
}
public void registrar() {
System.out.println("SALVANDO");
try {
Image image = ImageIO.read(file.getInputstream());
saveToFile(toBufferedImage(image));
usuario.setPerfil(image);
} catch (IOException e) {
e.printStackTrace();
}
}
public Usuario getUsuario() {
return usuario;
}
public void setUsuario(Usuario usuario) {
this.usuario = usuario;
}
public UploadedFile getFile() {
return file;
}
public void setFile(UploadedFile file) {
this.file = file;
}
我做了這樣的代碼在另一個XHTML頁面,它的工作。所以我把那個命令按鈕放在另一個頁面上,它給了我一個NullPointerException,我以前從未見過
謝謝!
這一次我tryed使用另一XHTML和它的工作。爲什麼這隻適用於一個xhtml? –