2014-11-24 2 views
0

Я использую одно меню для выпадающего списка в xhtml с помощью конвертера, но когда я пытаюсь отобразить выбранное значение в бэкэнде, он возвращает null. Я попытался использовать ajax-тег с свойствами update и actionListener, но остается таким же. как я должен получить доступ к выбранному значению .... я также использую переменный сеанс, чтобы получить поле Логин персона объектjsf dropdown возвращает выбранное значение null в управляемом компоненте

@Xhtml File 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.org/ui" > 
<h:body> 
    <ui:composition template="/pages/protected/templates/master.xhtml"> 
     <ui:define name="divMain"> 
      <h:form id="fileDetailsForm"> 

       <p:commandButton immediate="true" ajax="false" action="#{fileMB.onBtnCancel}" value="#{bundle.back}"/> 

       <p:panel id="toggleable" header="File Details" toggleable="true" closable="false" toggleSpeed="500" closeSpeed="500" widgetVar="panel" style="margin-bottom:20px"> 
        <p:panelGrid columns="2" columnClasses="label,value"> 

         <h:outputText value="#{bundle.subject}" /> 
         <h:outputText value="#{fileMB.selectedFile.subject}" /> 

         <h:outputText value="#{bundle.fileRefNo}" /> 
         <h:outputText value="#{fileMB.selectedFile.fileRefNo}" /> 

         <h:outputText value="#{bundle.description}" /> 
         <h:outputText value="#{fileMB.selectedFile.description}" /> 

         <h:outputText value="#{bundle.creationDate}" /> 
         <h:outputText value="#{fileMB.selectedFile.creationDate}" /> 

         <h:outputText value="#{bundle.priority}" /> 
         <h:outputText value="#{fileMB.selectedFile.priority}" /> 

         <h:outputText value="#{bundle.classification}" /> 
         <h:outputText value="#{fileMB.selectedFile.classification}" /> 

         <h:outputText value="#{bundle.created} #{bundle.person}" /> 
         <h:outputText value="#{fileMB.selectedFile.createdPerson}" /> 

         <h:outputText value="#{bundle.submitStatus}" /> 
         <h:outputText value="#{fileMB.selectedFile.submitStatus}" /> 

         <h:outputText value="#{bundle.oldFileRefNo}" /> 
         <h:outputText value="#{fileMB.selectedFile.oldFileRefNo}" /> 



     <h:outputText value="#{bundle.person}" /> 
         <p:selectOneMenu value="#{fileMB.person}" required="true" label="#{bundle.reportingto}" converter="personConverter"> 
          <f:selectItem itemLabel="[Select]" noSelectionOption="true" itemValue="" /> 
          <f:selectItems value="#{personMB.persons}" var="orgType" itemLabel="#{orgType.firstName}" itemValue="#{orgType}"/> 

         </p:selectOneMenu> 


       <p:commandButton value="#{bundle.create}" ajax="true" immediate="true" update="@form" action="#{fileMB.forward}" /> 
        </h:panelGrid> 


       </p:panel> 

      </h:form> 
        <ui:include src="/pages/protected/filling/File/CreateComentDialog.xhtml" /> 

        </ui:define> 
    </ui:composition> 
</h:body> 
</html> 

здесь управляемый файл боб, в котором я хочу, чтобы получить доступ выбранного значения из выпадающего списка

@Backing bean 

package com.managedBean.Filling; 

import java.io.Serializable; 
import java.util.ArrayList; 
import java.util.List; 

import javax.faces.application.FacesMessage; 
import javax.faces.bean.ManagedBean; 
import javax.faces.bean.SessionScoped; 
import javax.faces.context.FacesContext; 
import javax.faces.event.ActionEvent; 
import javax.servlet.http.HttpServletRequest; 

import org.apache.log4j.LogManager; 
import org.apache.log4j.Logger; 


import com.controller.Controller; 
import com.managedBean.BaseMB; 
import com.model.um.Designation; 
import com.model.um.Organization; 
import com.model.um.Person; 


@ManagedBean(name="fileMB") 
@SessionScoped 
public class FileMB extends BaseMB implements Serializable 
{ 
    public static final long serialVersionUID = 1L; 
    public static final Logger log = LogManager.getLogger(FileMB.class.getName()); 


    private File info; 
    private File file; 
    private Person person; 
    private List<Person> personList; 
    private File selectedFile; 
    private Person per; 
    long id; 



    FacesContext cont=FacesContext.getCurrentInstance(); 
    HttpServletRequest req=(HttpServletRequest)cont.getExternalContext().getRequest(); 


    { 
    per=(Person) req.getSession().getAttribute("loginPerson"); 

    } 
     public Person getPer() { 
     return per; 
    } 

    public void setPer(Person per) { 
     this.per = per; 
    } 

    public File getSelectedFile() { 
     return selectedFile; 
    } 

    public void setSelectedFile(File selectedFile) { 
     this.selectedFile = selectedFile; 
    } 

    public List<File> getFileList() { 
     id = per.getPersonId(); 
     System.out.println(id); 
     this.fileList = controller.getSpecificFiles(id); 
     return fileList; 
    } 

    public void setFileList(List<File> fileList) { 
     this.fileList = fileList; 
    } 

    public Person getPerson() { 
     return person; 
    } 

    public void setPerson(Person person) { 
     this.person = person; 
    } 

    public List<Person> getPersonList() { 
     this.personList = controller.getAllPersons(); 
     return personList; 
    } 

    public void setPersonList(List<Person> personList) { 
     this.personList = personList; 
    } 




    public File getFile() { 
     return file; 
    } 

    public void setFile(File file) { 
     this.file = file; 
    } 

    public File getInfo() { 
     return info; 
    } 

    public void setInfo(File info) { 
     this.info = info; 
    } 


    public void forward() 
    { 
      System.out.println("else"); 

      System.out.println(person); 
      System.out.println(person.getFirstName()); 


     } 

вот Ouput

output: 
else 
[email protected] 
null 

ответ

0

При установке immedaite="true" атрибут для CommandButton вы вынуждаете, чтобы пропустить несколько этапов в JSF pocessi ng жизненного цикла. Один из них - «фаза обновления модели». Удалите атрибут кнопки immediate="true" или установите значение false (по умолчанию).

+0

Я изменил немедленно = "false", а также попытался удалить весь атрибут, но он все еще не работает. Возвращает значение null в value = "# {fileMB.person}". Infact it doesnot take any value .. дает сообщение growl "type not selected: no value in person (label)" – java445

Смежные вопросы