0
votes

I have a p:dataTable where each row has a p:commondButton and an h:outputText to display a project's name. A click on the p:commandButton calls the anfrageErfassenModel.applyProjekt() actionListener and should immediately update the value in the p:inputText for anfrageErfassenModel.anfrage.name.

JSF page - anfrageErfassen.xhtml:

<h:form id="formAnfrageErfassen">

    <p:panelGrid columns="3" id="anfrage">
        <p:outputLabel for="name" value="#{bundle['anfrage.name']}"/>
        <p:inputText id="name" value="#{anfrageErfassenModel.anfrage.name}" required="true" />
        <p:message for="name" id="message4name" display="text"/>
    </p:panelGrid>

    <p:dataTable var="projekt" ...>
        <p:column>
            <p:commandButton icon="fa fa-check"
                title="Apply Project"
                update=":formAnfrageErfassen:anfrage"
                immediate="true"
                actionListener="#{anfrageErfassenModel.applyProjekt(projekt)}"/>
        </p:column>
        <p:column>
            <h:outputText value="#{projekt.name}"/>
        </p:column>
    </p:dataTable>
</h:form>

Bean - AnfrageErfassenModel.java:

@Named
@ViewScoped
public class AnfrageErfassenModel implements Serializable {

    private Anfrage anfrage; // with getter / setter

    public void applyProjekt(final Projekt projekt) {
        logger.entry(projekt);
        anfrage = anfrageRestClient.create();
        anfrage.setName(projekt.getName()); // take name from projekt
        logger.debug("anfrage.name=" + anfrage.getName());
        logger.exit();
    }       
}

The actionListener calls anfrage.setName(projekt.getName()) which results that the model's value is set as expected -> But the p:inputText is not updated!

I know that immediate="true" means, that the APPLY_REQUEST_VALUES phase is followed by the RENDER_RESPONSE phase!

What must I do to get the inputText field's value updated with the current value of the model? Using p:outputText instead of p:inputText works, but I need the inputText because the field must be editable by the user!

I'm using Primefaces 6.0 on WildFly 10.0.0.Final.

Thanks and Regards, Rainer

1
did you try to add <p:ajax listner="#{managedBean.yourMethod()}" update =":Yourcomponante" /> ??? - Yagami Light
@YagamiLight: Ajax is built-in in the p:commandButton. Adding an ajax tag is not needed there. - Kukeltje
@Kukeltje believe me sometimes it does work - Yagami Light
Did you check if the id you use in the update attribute of the commandButton is the right one? E.g. isn't the form by accident nested in a namingcontainer? - Kukeltje
I would believe you if you have an explicit cases where it would be needed . You now say 'sometimes' .... I personally never needed to add an ajax tag in a commandButton to get it to update something. If updates did not work, it was 60% of the time a wrong reference (naming container missing) 20% of the time a typo and 20% of the time an error where the action/actionListener was not called and hence the update should not occur. And keep in mind that an outputText works! That would btw mean my comment about the naming container is invalid to - Kukeltje

1 Answers

0
votes

Thanks to @Kukeltje - adding process="@this" to the commandButton solved the problem!