0
votes

I am developing a JSF 2.1 project. I am using primefaces 3.5 components. There are two managedbean with viewscoped, WizardBean and CreateInputBean. They are used in wizard component(primefaces). The last point first wizard, I click a button then dialog is opened. There is also wizard in dialog. Here with CreateInputBean a instance of domain object is created. After a instance created again when dialog is opened, there are information last instance because CreateInputBean is life. I want to destroy CreateInputBean with ViewScoped without going another page.

I tried these but they are not working.

@ManagedBean(name = "cbean")
@ViewScoped
public class CreateInputBean {

public void addUsage() {
    ...
    FacesContext.getCurrentInstance().getViewRoot().getViewMap().remove("#{cbean}");
      or
    FacesContext.getCurrentInstance().getViewRoot().getViewMap().remove("cbean");
} 
}

enter image description here

            <p:wizard flowListener="#{wizard.onFlowProcess}">
                <p:tab id="personal" title="Kullanıcı ile ilgili bilgiler">
                    ...
                </p:tab>
                <p:tab id="confirm" title="Kullanım Verileri">
                    <p:panel style="height: 600px;">
                        <p:dataTable id="liste" value="#{ubean.usages}" var="usage">
                            ...
                        </p:dataTable>
                        <p:commandButton value="Ekle" onclick="dlg.show();" type="button" />
                    </p:panel>
                    <p:dialog header="Usage Ekleme" widgetVar="dlg" showEffect="fold"
                        hideEffect="fold" height="600" width="600">
                        <p:wizard flowListener="#{cbean.onFlowProcess}">
                            <p:tab title="Servis Tipi">
                                ...
                            </p:tab>
                            <p:tab title="Kullanim Tipi">
                                ...
                            </p:tab>
                            <p:tab title="İşlem Süresi/Adedi/Miktarı">
                                <p:panel style="height: 500px; width: 500px;">
                                    <h:panelGrid columns="2">
                                        <p:outputLabel value="Term:" />
                                        <p:inputText value="#{cbean.term}" />
                                        <p:commandButton value="Save"
                                            actionListener="#{cbean.addUsage}" oncomplete="dlg.hide()"
                                            update="liste" />
                                    </h:panelGrid>
                                </p:panel>
                            </p:tab>
                        </p:wizard>
                    </p:dialog>
                </p:tab>
            </p:wizard>
1
Your expectation is a little unrealistic IMO. You're expecting to remove a reference to a bean, while you're still within that bean? How's that going to work? The best you could hope for is to postback (navigate) to the same view, to get a new instance of the same bean and take the previous one out of scope. That or use the @RequestScoped and ELFlash to store transient data between ajax requestskolossus
To remove a reference CreateInputBean then I am not still within that bean. Now I am in WizardBean. If I can not destroy viewscoped managed bean, ı want to get first tab in wizard in dialog. This is enough.Burak Dağlı

1 Answers

0
votes

I find a way. But I can not destroy viewscoped managed bean. I can do to get first tab wizard in dialog and clear fields of in wizard.

<script type="text/javascript">  
                function resetWizard() {
                    wiz.loadStep(wiz.cfg.steps[0], true);
                }
     </script>

   ...........................................


 <p:wizard flowListener="#{cbean.onFlowProcess}" widgetVar="wiz">


.............


  <p:commandButton value="Save" actionListener="#{cbean.addUsage}" 
       oncomplete="dlg.hide(), resetWizard()" update="liste" />



 ..........


    public void addUsage(ActionEvent actionEvent) {
    selectedServis = modalService.getServis(selectedServisID);
    selectedKullanimTipi = modalService
            .getKullanimTipi(selectedKullanimTipiID);
    ubean.addUsage(new Call(ubean.getAbone(), selectedServis, term,
            selectedKullanimTipi));

    this.selectedServisID = 1;
    this.selectedKullanimTipiID  = 1 ;
    this.selectedKullanimTipi = null;
    this.selectedTarife = null;
    this.selectedServis = null;
    this.term = null;

}