无法使用primefaces实现更新功能

时间:2013-12-25 15:37:13

标签: jsf primefaces

我想基于在同一页面中显示内容细节来实现更新功能。现在我可以看到内容细节了。但是我无法在同一页面中更新消息。我调试它,我在java中得到null对象。我无法获得任何输入值         有人帮我查一下吗?这是什么原因?谢谢。

 <pe:dynaForm id="dynaForm" value="#{anotherDynaFormController.model}" var="data"  
                 openExtended="true" widgetVar="dynaFormWidget">  
        <pe:dynaFormControl styleClass="pe-dynaform-label">  
            <h:outputText value="#{data}"/>  
        </pe:dynaFormControl>  
        <pe:dynaFormControl type="separator" styleClass="separator ui-state-disabled">  
            <h:panelGrid columns="2" style="width:100%;" columnClasses="separatorText">  
                <h:outputText value="#{data}"/>  
                <p:separator/>  
            </h:panelGrid>  
        </pe:dynaFormControl> 
        <!--   
        <pe:dynaFormControl type="name" for="autocompl">  
            <p:autoComplete id="autocompl" value="#{anotherDynaFormController.name}" required="#{data.required}"  
                            dropdown="true" completeMethod="#{anotherDynaFormController.complete}" style="width:280px;align:left;"/>  
        </pe:dynaFormControl>  
        -->
        <pe:dynaFormControl type="name" for="txt">  
            <h:inputText id="nametxt" value="#{anotherDynaFormController.name}" required="#{data.required}" style="width:320px;align:left;" rendered="#{anotherDynaFormController.editable}" />
            <h:outputText id="nametxt2" value="#{anotherDynaFormController.name}"  style="width:320px;align:left;" rendered="#{not anotherDynaFormController.editable}" />    
        </pe:dynaFormControl>

        <pe:dynaFormControl type="description" for="txt">  
            <h:inputText id="descriptiontxt" value="#{anotherDynaFormController.description}"  style="width:320px;align:left;" rendered="#{anotherDynaFormController.editable}" />
            <h:outputText id="descriptiontxt2" value="#{anotherDynaFormController.description}"  style="width:320px;align:left;" rendered="#{not anotherDynaFormController.editable}" /> 
        </pe:dynaFormControl> 

        <pe:dynaFormControl type="givenstories" for="txt">  
            <h:inputText id="givenstoriestxt" value="#{anotherDynaFormController.givenStories}"  style="width:320px;align:left;" rendered="#{anotherDynaFormController.editable}"/>  
            <h:outputText id="givenstoriestxt2" value="#{anotherDynaFormController.givenStories}"  style="width:320px;align:left;" rendered="#{not anotherDynaFormController.editable}" />          
        </pe:dynaFormControl>

        <pe:dynaFormControl type="parent" for="txt">  
            <h:inputText id="parenttxt" value="#{anotherDynaFormController.parent}"  style="width:320px;align:left;" rendered="#{anotherDynaFormController.editable}" /> 
            <h:outputText id="parenttxt2" value="#{anotherDynaFormController.parent}"  style="width:320px;align:right;" rendered="#{not anotherDynaFormController.editable}" /> 
        </pe:dynaFormControl>

        <pe:dynaFormControl type="meta" for="txt">  
            <h:inputText id="metatxt" value="#{anotherDynaFormController.meta}"  style="width:320px;align:left;" rendered="#{anotherDynaFormController.editable}"  />  
            <h:outputText id="metatxt2" value="#{anotherDynaFormController.meta}"  style="width:320px;text-align:right;" rendered="#{not anotherDynaFormController.editable}" />         </pe:dynaFormControl>        
        <pe:dynaFormControl type="tag" for="txt">  
            <h:inputText id="tagtxt" value="#{anotherDynaFormController.tag}"  style="width:320px;align:left;" rendered="#{anotherDynaFormController.editable}" />  
            <h:outputText id="tagtxt2" value="#{anotherDynaFormController.tag}"  style="width:320px;align:left;" rendered="#{not anotherDynaFormController.editable}" />   
        </pe:dynaFormControl>        
        <pe:dynaFormControl type="stepnumber" for="txt" style="float:right;text-align:right;">  
            <h:outputText id="txtstepnumber" value="#{data.value}" style="float:right;width:80px;text-align:right;"/>
        </pe:dynaFormControl>  
        <pe:dynaFormControl type="steptype" for="txt" style="float:left;text-align:left;">  
            <p:inputText id="txtsteptype" value="#{data.value}" style="width:80px;align:left;" required="#{data.required}"/>
        </pe:dynaFormControl>
        <pe:dynaFormControl type="step" for="txt" style="float:left;text-align:left;">  
            <p:inputText id="txtstep" value="#{data.value}" style="width:600px;align:left;" required="#{data.required}"/>
        </pe:dynaFormControl>

        <f:facet id="facetcommand" name="buttonBar">  
            <p:commandButton value="Edit" action="#{anotherDynaFormController.editAction}" rendered="#{not anotherDynaFormController.editable}" process="dynaForm" update=":mainForm:dynaFormGroup" />
            <p:commandButton value="Save" action="#{anotherDynaFormController.submitForm}"  
                             process="dynaForm" 
                             oncomplete="handleComplete(xhr, status, args)"/> 
        </f:facet>  
        </pe:dynaForm>         
         <p:messages id="messages" showSummary="true"/>         
        </p:panel>
        </h:panelGroup>            
        <p:dialog header="Input values" widgetVar="inputValuesWidget">  
        <h:panelGroup id="inputValues" layout="block" style="margin:10px;">  
           <h:outputText value="#{anotherDynaFormController.formFields}" escape="false"/>  
        </h:panelGroup>  
        </p:dialog>   

支持Bean:

@ManagedBean  
@ViewScoped  
public class AnotherDynaFormController implements Serializable {
    private static final long serialVersionUID = 20120423L;        
    private DynaFormModel modelOne;    
    private DynaFormModel modelTwo;  
    private boolean showModelOne = true;         
    private String tabTitle;   
    private Integer selectedItemId;    
    private Integer selectedItemType = 0;        
    private String name;    
    private String description;    
    private String meta;   
    private String tag;  
    private String givenStories;
    private String parent;       
    private Integer stepNumber = 1;    
    private String stepType = "";;    
    private String step = "";               
    private ProjectTreeDao projectTreeDao;
    private ScenarioMetaDao scenarioMetaDao;
    private ScenarioDao scenarioDao;
    private StepDao stepDao;
    private MetaDao metaDao;       
    boolean editable = false;       
//    Scenariob scenariob = new Scenariob();

    AnotherDynaFormController anotherDynaFormController; 
    public AnotherDynaFormController() {

    }
    public AnotherDynaFormController (String name, String description, String meta, String tag, String givenStories, String parent) {
        this.name = name;
        this.description = description;
        this.meta = meta;
        this.tag = tag;
        this.givenStories = givenStories;
        this.parent = parent;
    }

    public DynaFormModel getModel() {  

        projectTreeDao = new ProjectTreeDao();
        scenarioMetaDao = new ScenarioMetaDao();
        scenarioDao = new ScenarioDao();
        stepDao = new StepDao();        
        metaDao = new MetaDao();            
        System.out.println("selected item id   ==================== "+selectedItemId);
        System.out.println("selected item type ==================== "+selectedItemType);
        if (selectedItemType == 0) {
//            return (showModelOne ? getModelOne() : getModelTwo()); 
            if (showModelOne) {
                 return getModelOne();
            } else {
                 return getModelTwo();
            }
        } else {
            return getModelOne();
        }

    }  

    public DynaFormModel getModelOne() {  

        if (modelOne != null) {  
            return modelOne;  
        }  

        modelOne = new DynaFormModel();   
        DynaFormRow row = modelOne.createRegularRow();        
        DynaFormLabel label11 = row.addLabel("Name", 1, 1);  
        DynaFormLabel label12 = row.addLabel("Description", 2, 1);        
        row = modelOne.createRegularRow();        
        DynaFormControl control21 = row.addControl(new FormField(true), "name", 1, 1);  
        DynaFormControl control22 = row.addControl(new FormField(false), "description", 2, 1);        
        label11.setForControl(control21);  
        label12.setForControl(control22);  

        row = modelOne.createRegularRow();       
        DynaFormLabel label51 = row.addLabel("GivenStories", 1, 1); 
        DynaFormLabel label52 = row.addLabel("Parent", 2, 1); 

        row = modelOne.createRegularRow(); 

        DynaFormControl control61 = row.addControl(new FormField(true), "givenstories", 1, 1);  
        DynaFormControl control62 = row.addControl(new FormField(true), "parent", 2, 1);            
        label51.setForControl(control61);  
        label52.setForControl(control62);                  

        row = modelOne.createRegularRow();        
        DynaFormLabel label31 = row.addLabel("Meta", 1, 1);  
        DynaFormLabel label32 = row.addLabel("Tag", 2, 1);        
        row = modelOne.createRegularRow();        
        DynaFormControl control41 = row.addControl(new FormField(true), "meta", 1, 1);  
        DynaFormControl control42 = row.addControl(new FormField(true), "tag", 2, 1);        
        label31.setForControl(control41);  
        label32.setForControl(control42);              
        return modelOne;  
    }  

    enter code here
    public DynaFormModel getModelTwo() {  

        /*... some code */            
        return modelTwo;  
    }  

    public String switchModel() {  
        showModelOne = !showModelOne;  

        // reset models (simulate new loading)  
        if (showModelOne) {  
            if (selectedItemType == 0)
               setTabTitle("Scenario");
            modelOne = null;  
        } else {  
            if (selectedItemType == 0)
               setTabTitle("Step");
            modelTwo = null;  
        }  

        return null;  
    }  

    public List<String> complete(String query) {  
        List<String> results = new ArrayList<String>();  

        char letter;  
        for (letter = 'a'; letter <= 'm'; letter++) {  
            results.add(query + letter);  
        }  

        return results;  
    }  

    public String getFormFields() {  
        DynaFormModel model = (showModelOne ? getModelOne() : getModelTwo());  

        if (model == null) {  
            return null;  
        }  

        StringBuilder sb = new StringBuilder();  
        for (DynaFormControl dynaFormControl : model.getControls()) {  
            if (dynaFormControl.getData() instanceof FormField) {  
                FormField ff = (FormField) dynaFormControl.getData();  
                if (ff.getValue() != null && StringUtils.isNotBlank(ff.getValue().toString())) {  
                    sb.append(ff.getValue());  
                    sb.append("<br/>");  
                }  
            }  
        }  

        return sb.toString();  
    }  

    public String editAction() {

        setEditable(true);
        return null;
    }  


        public String submitForm() {  
 FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
System.out.println("########## selectedItemId: "+selectedItemId);
/* I want to get the param from update pages, such as name description, id etc */
         System.out.println("########## anotherDynaFormController: "+anotherDynaFormController);
         System.out.println("########## name: "+name);
         System.out.println("########## description: "+description);
        FacesMessage.Severity sev = FacesContext.getCurrentInstance().getMaximumSeverity();  
        boolean hasErrors = (sev != null && (FacesMessage.SEVERITY_ERROR.compareTo(sev) >= 0));
RequestContext requestContext = RequestContext.getCurrentInstance();  
        requestContext.addCallbackParam("isValid", !hasErrors);  

        return null;  
    }  

    public void onRowSelect(SelectEvent event) {  
        FacesMessage msg = new FacesMessage("Scenario anotherDynaFormController Selected", ((Scenariob) event.getObject()).getName());  

        if (((Scenariob)event.getObject()).getItemType() == 0) {
             if (tabTitle == null || (tabTitle != null && !tabTitle.equals("Step")) ) 
               setTabTitle("Scenario");
        } else if (((Scenariob)event.getObject()).getItemType() == 1) {

             if (((Scenariob)event.getObject()).getLevel() == 2) 
                setTabTitle("Product");
             else if (((Scenariob)event.getObject()).getLevel() == 3) 
                setTabTitle("Capability");
             else 
                setTabTitle("Feature");

        }

        Integer selectedItemId = ((Scenariob) event.getObject()).getId();
        Integer selectedItemType = ((Scenariob) event.getObject()).getItemType();
        setSelectedItemId(selectedItemId);
        setSelectedItemType(selectedItemType);     

//      setName(((Scenariob)event.getObject()).getName());
//      setDescription(((Scenariob)event.getObject()).getDescription());
        List<ScenarioMeta> scenariometaList = scenarioMetaDao.searchScenarioMetabyScenario(selectedItemId);
        String metaString = "";
        for (ScenarioMeta scenarioMeta : scenariometaList) {
             Meta meta = metaDao.findMeta(Integer.valueOf(scenarioMeta.getMetaId()));
             metaString += meta.getName();
        }
//      setMeta(metaString);
        Integer givenstoriesid = ((Scenariob) event.getObject()).getGivenStories();
//      String scenarionameString = "";
        String givenstorieString = "";
        if (givenstoriesid != null) {
          Scenario scenario =  scenarioDao.findScenario(givenstoriesid);
          givenstorieString = scenario.getName();

//        setGivenStories(givenstorieString);
        }
        Integer parentId = ((Scenariob) event.getObject()).getParent();
        String parentnameString = "";
        if (parentId != null) {
              ProjectTree projectTree =  projectTreeDao.findNode(parentId);
              parentnameString = projectTree.getName();
//            setParent(parentnameString);
         }
//      AnotherDynaFormController (String name, String description, String meta, String tag, String givenStories, String parent)
        anotherDynaFormController = new AnotherDynaFormController(((Scenariob)event.getObject()).getName(),((Scenariob)event.getObject()).getDescription(), metaString,"", givenstorieString, parentnameString);        
        setEditable(false);     
        System.out.println("&&&&&&& "+event.getSource() +"    id : "+((Scenariob) event.getObject()).getId()+"  "+((Scenariob) event.getObject()).getItemType());
        System.out.println("*** 22222   onRowSelect onRowSelect!!!! **** "+"    "+((Scenariob) event.getObject()).getName());
        FacesContext.getCurrentInstance().addMessage(null, msg);  
    }  

    public void onRowUnselect(UnselectEvent event) {  
        FacesMessage msg = new FacesMessage("Car anotherDynaFormController Unselected", ((Scenariob) event.getObject()).getName());  
        System.out.println("*** 2222  onRowUnselect onRowUnselect!!!! **** ");
        FacesContext.getCurrentInstance().addMessage(null, msg);  
    }  

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getMeta() {
        return meta;
    }

    public void setMeta(String meta) {
        this.meta = meta;
    }

    public String getTag() {
        return tag;
    }

    public void setTag(String tag) {
        this.tag = tag;
    }

    public String getGivenStories() {
        return givenStories;
    }

    public void setGivenStories(String givenStories) {
        this.givenStories = givenStories;
    }   

    public String getParent() {
        return parent;
    }

    public void setParent(String parent) {
        this.parent = parent;
    }

    public String getTabTitle() {
        return tabTitle;
    }

    public void setTabTitle(String tabTitle) {
        this.tabTitle = tabTitle;
    }   

    public Integer getSelectedItemId() {
        return selectedItemId;
    }

    public void setSelectedItemId(Integer selectedItemId) {
        this.selectedItemId = selectedItemId;
    }

    public Integer getSelectedItemType() {
        return selectedItemType;
    }

    public void setSelectedItemType(Integer selectedItemType) {
        this.selectedItemType = selectedItemType;
    }

    public boolean isShowModelOne() {
        return showModelOne;
    }

    public void setShowModelOne(boolean showModelOne) {
        this.showModelOne = showModelOne;
    }

    public Integer getStepNumber() {
        return stepNumber;
    }

    public void setStepNumber(Integer stepNumber) {
        this.stepNumber = stepNumber;
    }

    public String getStepType() {
        return stepType;
    }

    public void setStepType(String stepType) {
        this.stepType = stepType;
    }

    public String getStep() {
        return step;
    }

    public void setStep(String step) {
        this.step = step;
    }

    public boolean isEditable() {
        return editable;
    }

    public void setEditable(boolean editable) {
        this.editable = editable;
    }

    public AnotherDynaFormController getAnotherDynaFormController() {
        if (anotherDynaFormController == null)
            anotherDynaFormController = new AnotherDynaFormController();
        return anotherDynaFormController;
    }

    public void setAnotherDynaFormController(
            AnotherDynaFormController anotherDynaFormController) {
        this.anotherDynaFormController = anotherDynaFormController;
    }       

}  

0 个答案:

没有答案