2012-10-18 2 views
2

JBoss AS 7.1.1에서 JSF 2.1.7 및 Myfaces CODI 1.0.5를 사용하고 있습니다. 내 <h:commandButton>이 작동하지 않습니다. 나는 요구 사항을 읽고 많은 블로그에서 예제를 통해 아무 소용이있다.<h : commandButton>이 포스트 백을 시작하지 않습니다.

<ui:define name="pagecontent"> 
    <h1 class="title ui-widget-header ui-corner-all">Upload Bulk Contact File</h1> 
    <div class="entry"> 
     <h:form enctype="multipart/form-data" id="upload"> 
      <p:panel closable="false" collapsed="false" header="Excel Contact Uploader" 
       id="pnlupload" rendered="true" toggleable="false" visible="true" widgetVar="pnlupload"> 
       <p:growl id="msg" showDetail="true" life="3000" showSummary="true"/> 
       <p:fileUpload auto="true" 
        allowTypes="/(\.|\/)(xls)$/" 
        sizeLimit="1024000" 
        mode="advanced" 
        multiple="true" invalidFileMessage="Invalid file type" invalidSizeMessage="File too 
        large" dragDropSupport="true" 
        fileUploadListener="#{excelFileController.handleFileUpload}" showButtons="true" 
        update="msg, tblcontacts" required="false"/> 
       <p:scrollPanel rendered="true" style="height:200px;"> 
        <p:dataTable draggableColumns="false" editable="false" emptyMessage="No 
         Contacts Uploaded" id="tblcontacts" rendered="true" rows="8" 
         selection="#{excelFileController.contactsSelected}" 
         value="#{excelFileController.contactDataModel}" var="contact" style="width:50pc;"> 
         <p:column selectionMode="multiple" style="width:18px" /> 
         <p:column headerText="File Name"> 
          #{contact.groupName} 
         </p:column> 
         <p:column headerText="Number of Contacts"> 
          #{contact.numberofentries} 
         </p:column> 
         <p:column> 
          <h:button outcome="blkedit?faces-redirect=true" rendered="true" value="Edit"> 
           <f:param name="contact" value="#{contact.contactId}"/> 
          </h:button> 
         </p:column> 
        </p:dataTable> 
       </p:scrollPanel> 
       <br /> 
      </p:panel> 
      <h:commandButton value="Delete" id="btndelete" 
       action="#{excelFileController.removeContact}" type="button" immediate="true" 
       disabled="false"  rendered="true"/> 
      <h:message for="btndelete" /> 
     </h:form> 
    </div> 
</ui:define> 
를 다음과 같이 내 Facelets의 코드는

다음과 같이 ExcelFileController에 대한 코드는 다음과 같습니다

@Named 
@ViewAccessScoped 
public class ExcelFileController implements Serializable, IFileController { 
    /** 
    * 
    */ 
    private static final long serialVersionUID = -8117258104485487921L; 

    @Inject 
    PhoneNumberFormatter formatter; 

    @Inject 
    @Authenticated 
    UserProfile profile; 

    public PhoneNumberFormatter getFormatter() { 
    return formatter; 
    } 

    public void setFormatter(PhoneNumberFormatter formatter) { 
    this.formatter = formatter; 
    } 

    @EJB 
    BulkContactDeleter deleter; 

    @Inject 
    Logger logger; 

    @Inject 
    @CurrentContext 
    FacesContext context; 

    @Inject 
    BulkSMSContactListProducer listProducer; 

    @Inject 
    ConfigurationListProducer producer; 

    private BulkSMSContacts[] contactsSelected; 

    private BulkContactDataModel contactDataModel; 

    public BulkSMSContacts[] getContactsSelected() { 
     return contactsSelected; 
    } 

    public void setContactsSelected(BulkSMSContacts[] contactsSelected) { 
     this.contactsSelected = contactsSelected; 
    } 

    public BulkContactDataModel getContactDataModel() { 
     return contactDataModel; 
    } 

    @PostConstruct 
    public void init() { 
     logger.log(Level.INFO, "Entering excel file controller"); 
     contactDataModel = new BulkContactDataModel(
       listProducer.getBulkSMSContacts()); 

    } 
    /* 
    * (non-Javadoc) 
    * 
    * @see 
    * org.jboss.tools.examples.controller.IFileController#handleFileUpload(
    * org.primefaces.event.FileUploadEvent) 
    */ 
    @Override 
    public void handleFileUpload(FileUploadEvent event) { 
     StringBuffer buffer = new StringBuffer(); 
     // create a new file input stream with the input file specified 
     // at the command line 

     InputStream fin = null; 
     try { 
      fin = event.getFile().getInputstream(); 
     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
     // create a new org.apache.poi.poifs.filesystem.Filesystem 
     POIFSFileSystem poifs = null; 
     try { 
      poifs = new POIFSFileSystem(fin); 

     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
     HSSFWorkbook wb = null; 
     try { 
      wb = new HSSFWorkbook(poifs); 
     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
     int numberofsheets = wb.getNumberOfSheets(); 
     for (int i = 0; i < numberofsheets; i++) { 
      HSSFSheet sheet = wb.getSheetAt(i); 
      for (Row row : sheet) { 
       for (Cell cell : row) { 
        switch (cell.getCellType()) { 
         case Cell.CELL_TYPE_STRING : 
          if (!cell.getStringCellValue().isEmpty()) 
           buffer.append(formatter.formatPhoneNumber(cell 
             .getStringCellValue())); 
          buffer.append(producer.getConfiguration(
            SettingsName.SMS_PHONENUMBERDELIMITER 
              .toString()).getValue()); 

          break; 
         case Cell.CELL_TYPE_NUMERIC : 
          if (cell.getNumericCellValue() != 0) { 

           buffer.append(formatter 
             .formatPhoneNumber(String.valueOf(cell 
               .getNumericCellValue()))); 
           buffer.append(producer.getConfiguration(
             SettingsName.SMS_PHONENUMBERDELIMITER 
               .toString()).getValue()); 
           break; 
          } 

         default : 
          break; 
        } 

       } 

      } 
     } 
     BulkSMSContacts contacts = new BulkSMSContacts(); 
     contacts.setAccount(profile.getSmsAccount()); 
     int number = formatter.splitPhoneNumbers(buffer.toString()).length; 
     contacts.setContacts(buffer.toString()); 
     String filenameString = event.getFile().getFileName(); 
     int index = filenameString.indexOf("."); 
     filenameString = filenameString.substring(0, index); 
     contacts.setGroupName(filenameString); 
     contacts.setNumberofentries(number); 
     try { 
      deleter.addContact(contacts); 
      List<BulkSMSContacts> temp = listProducer.getBulkSMSContacts(); 
      contactDataModel.setWrappedData(temp); 
     } catch (Exception e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 

     context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, 
       "Success", number 
         + " entries processed. Please refresh page to view")); 

    } 

    /* 
    * (non-Javadoc) 
    * 
    * @see org.jboss.tools.examples.controller.IFileController#removeContact() 
    */ 
    @Override 
    public String removeContact() { 
     int contactsdeleted = 0; 
     if (contactsSelected != null) { 
      for (BulkSMSContacts contacts : contactsSelected) { 
       if (contacts != null) { 
        deleter.deleteContact(contacts); 
        contactsdeleted += 1; 
       } 

      } 

      List<BulkSMSContacts> temp = listProducer.getBulkSMSContacts(); 
      contactDataModel.setWrappedData(temp); 

      logger.log(Level.INFO, "Deleted " + contactsdeleted + " Contacts"); 
      context.addMessage(null, new FacesMessage(
        FacesMessage.SEVERITY_INFO, "Success", contactsdeleted 
          + " entries where deleted successfully")); 
     } else { 
      context.addMessage(null, new FacesMessage(
        FacesMessage.SEVERITY_ERROR, "Error", 
        "No contact file was selected!")); 
     } 
     return null; 
    } 
} 

모든 방법이있는 명령이도를 시작하지 않습니다 우려 마지막 "removeContact"를 제외하고 잘 작동 다시 게시.

어떻게 이것이 발생하며 어떻게 해결할 수 있습니까?

+0

파일 업로드가 정상적으로 작동합니까? 파일을 업로드하지 않으면 버튼이 작동합니까? 귀하의 진술에 관해서도 "다시 게시를 시작하지 않는다", 당신은 HTTP 요청이 전혀 전송되지 않았다는 것을 의미합니까? 웹 브라우저의 개발자 툴셋에서 HTTP 트래픽을 확인 했습니까? – BalusC

+0

@BalusC, 파일이 업로드되지 않으면 버튼이 작동하지 않습니다. 두 번째 질문에 대해서는 아무 일도 일어나지 않습니다. 요청이 전혀 시작되지 않습니다. 나는 다양한 브라우저에서 시도했지만, 아무 소용이 없다. 그래도 답장을 보내 주셔서 감사합니다 –

+0

버튼이 파일이 업로드 될 때만 작동합니까? 그래서 파일 자체가 잘 작동합니까? JS 콘솔에 오류가 있습니까? – BalusC

답변

4

<h:commandButton>에서 type="button"을 제거해야합니다. 이미 기본값 인 type="submit"이어야합니다.

type="button"은 그것에게 <input type="button"> 대신 보통 등등 onclick 등을 사용하여 연결 클라이언트 측 핸들러에만 유용 <input type="submit">의 수 있습니다.

+0

감사합니다. 정말 감사드립니다. –

+0

안녕하세요. – BalusC

관련 문제