p:dialog update model value error

UI Components for JSF
Post Reply
zsuiqiang
Posts: 146
Joined: 13 Sep 2010, 03:52

26 Oct 2010, 03:36

My page

Code: Select all

<h:form id="form">
            <p:commandButton value="new" action="#{specialityBean.action('add')}" update="form:display" oncomplete="dlg.show()"/>
            <p:commandButton value="edit" action="#{specialityBean.action('edit')}" oncomplete="dlg.show()"/>
            <p:commandButton value="delete" action="#{specialityBean.action('delete')}"/>            
            <p:dataTable id="specialtyList" var="speciality" value="#{specialityBean.specialities}"
                         selection="#{specialityBean.selectedSpecialty}" selectionMode="single">
                <p:column>
                    <f:facet name="header">name</f:facet>
                    <h:outputText value="#{speciality.name}" />
                </p:column>

                <p:column>
                    <f:facet name="header">code</f:facet>
                    <h:outputText value="#{speciality.code}" />
                </p:column>

                <p:column>
                    <f:facet name="header">des</f:facet>
                    <h:outputText value="#{speciality.des}" />
                </p:column>
            </p:dataTable>            
            <p:dialog header="speciality" widgetVar="dlg" width="310" resizable="false" closable="false" showEffect="explode" hideEffect="explode">
                <h:panelGrid id="display" columns="2" style="margin-bottom:10px;white-space: nowrap">
                    <h:outputText  value="name:"/>
                    <h:inputText id="name" value="#{specialityBean.specialty.name}" />
                    <h:outputText value="code:" />
                    <h:inputText id="code" value="#{specialityBean.specialty.code}" />
                    <h:outputText  value="des:" />
                    <h:inputText id="manager" value="#{specialityBean.specialty.des}" />
                </h:panelGrid>
                <p:commandButton value="ok" update="specialtyList" actionListener="#{specialityBean.ok}" oncomplete="dlg.hide()"/>
                <p:commandButton value="cancel" onclick="dlg.hide()"/>
            </p:dialog>
        </h:form>
My bean

Code: Select all

@ManagedBean(name= "specialityBean")
@ViewScoped
public class SpecialityBean implements Serializable
{

    @EJB
    private SpecialityEAO specialityEAO;
    private List<Speciality> specialities;
    private Speciality specialty=new Speciality();
    private Speciality selectedSpecialty;
    public SpecialityBean()
    {
    }

    @PostConstruct
    public void initialize()
    {
        this.specialities = specialityEAO.findSpecialitys();
    }

    public List<Speciality> getSpecialities()
    {
        return specialities;
    }

    public Speciality getSpecialty()
    {
        System.out.println("getSpecialty was called");
        return specialty;
    }

    public void setSpecialty(Speciality specialty)
    {
        System.out.println("setSpecialty was called");
        this.specialty=specialty;
    }

    public Speciality getSelectedSpecialty()
    {
        System.out.println("getSelectedSpecialty() was called");
        return selectedSpecialty;
    }

    public void setSelectedSpecialty(Speciality selectedSpecialty)
    {
        System.out.println("SetSelectedSpecialty:"+selectedSpecialty);
        this.selectedSpecialty = selectedSpecialty;
    }



    private String operation;
    public String action(String operation)
    {
        System.out.println("action:"+operation+"  specialty:"+specialty);
        this.operation = operation;
        return null;
    }

    public void ok(ActionEvent event)
    {

        if (this.operation.equalsIgnoreCase("add"))
        {
            System.out.println("add Specialty:"+specialty);
            return;
        }
        if (this.operation.equalsIgnoreCase("edit"))
        {
            System.out.println("edit Specialty:"+specialty);

            return;
        }
    }
}
I traced the life cycle phase, and i found that getter method instead of setter method was called at "update model value" phase.Here is the result:

before UPDATE_MODEL_VALUES: phase id - UPDATE_MODEL_VALUES 4
getSpecialty was called
getSpecialty was called
getSpecialty was called
after UPDATE_MODEL_VALUES: phase id - UPDATE_MODEL_VALUES 4
primefaces:jakarta:12.0.0.jar,
primefaces-ext:jakarta:12.0.0.jar,
JSF Mojarra 3.0
glassfish-6.2.5,
netbeans 14
IDEA 2022.2.2
Browser: Edge

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

26 Oct 2010, 09:38

DataTable is also updating the model as you have enabled selection. You need to use partial processing feature;

Code: Select all

<p:commandButton value="ok" update="specialtyList" actionListener="#{specialityBean.ok}" oncomplete="dlg.hide()" process="display"/>

zsuiqiang
Posts: 146
Joined: 13 Sep 2010, 03:52

26 Oct 2010, 10:36

Thanks for quick answer!
I try the method you give,the datatable model is't updating. But "setSpecialty(Speciality specialty)" instead of "setSpecialty(Speciality specialty)" is called.

Code: Select all

before UPDATE_MODEL_VALUES: phase id - UPDATE_MODEL_VALUES 4
getSpecialty was called
getSpecialty was called
getSpecialty was called
after UPDATE_MODEL_VALUES: phase id - UPDATE_MODEL_VALUES 4
I think that the result shold be:

Code: Select all

before UPDATE_MODEL_VALUES: phase id - UPDATE_MODEL_VALUES 4
setSpecialty was called
setSpecialty was called
setSpecialty was called
after UPDATE_MODEL_VALUES: phase id - UPDATE_MODEL_VALUES 4
primefaces:jakarta:12.0.0.jar,
primefaces-ext:jakarta:12.0.0.jar,
JSF Mojarra 3.0
glassfish-6.2.5,
netbeans 14
IDEA 2022.2.2
Browser: Edge

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 33 guests