2017-02-18 1 views
0

Meine JSF-Befehlsschaltfläche ruft nicht die Methode auf, die sie aufrufen sollte. Hier ist der Code:JSF-Befehlsschaltfläche, die keine Bean-Methode aufruft

<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> 

Ich habe alles versucht, aber es hat nicht funktioniert. Kann mir jemand dabei helfen?

Hier ist die Bean-Methode:

@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; 
} 

Ich habe so etwas wie dieser Code in einer anderen XHTML-Seite und es funktionierte. Also habe ich diese Befehlsschaltfläche in die andere Seite gelegt und es gab mir eine NullPointerException, die ich noch nie zuvor gesehen habe

Vielen Dank!

Antwort

0

Sind Sie sicher, dass die hochgeladene Datei nicht null ist? Versuchen Sie, ein debug in Ihrer Methode registrar() auszuführen.

Wenn das nicht das Problem ist, bitte posten Sie Ihre Stack-Trace. "Eine Stapelspur sagt mehr als tausend Worte". Diese

+0

Dieses Mal habe ich eine andere XHTML tryed mit und es funktionierte. Warum funktioniert das nur in einem xhtml? –

0

ist das eine andere XHTML es

arbeitete
<h:body 
style="background-color: #2b5dad;width:100%;height:100%;margin:0px;"> 
<div class="lay_page"> 
    <div style="width: 100%; height: 100%; padding-top: 3.5%;"> 
     <h:outputText styleClass="title_font" value="PROTÓTIPO ALPHA" /> 
    </div> 
</div> 
<div class="lay_page_center"> 
    <div class="lay_page_center_center"> 
     <h3 class="default_font">Login</h3> 
     <h:form> 
      <h:outputText value="Email" 
       style="font-size: 15px; float:left;margin-left:20%;" /> 
      <br /> 
      <h:inputText value="#{loginPageMBean.email}" 
       styleClass="default_input" 
       style="float:left;margin-left:20%;width:60%"></h:inputText> 
      <br /> 
      <h:outputText value="Senha" 
       style="font-size: 15px; float:left;margin-left:20%;" /> 
      <br /> 
      <h:inputSecret value="#{loginPageMBean.senha}" 
       styleClass="default_input" 
       style="float:left;margin-left:20%;width:60%" /> 
      <br /> 
      <br /> 
      <br /> 
      <h:commandButton styleClass="default_button" value="Login" 
       action="#{loginPageMBean.login}"></h:commandButton> 
      <h:commandButton styleClass="default_button" value="Registrar" 
       action="register_page.xhtml"></h:commandButton> 
      <h:commandButton styleClass="default_button" value="Próximo passo" 
       action="#{registroPageMBean.registrar}"></h:commandButton> 
     </h:form> 
    </div> 
</div> 
<div class="lay_page"></div> 

+0

Gleiche Bean für diese Datei? Sie haben nicht den in diesem xhtml. – ceklock

Verwandte Themen