0

I'm trying to update the values of the bean with a button, like a data preload mechanism, so then the form is updated with the new values. I've visited a bunch of questions about this but those solutions didn't work here.

form.xhtml example code

<p:outputLabel for="name" value="Your name" />
                        <p:inputText value="#{person.name}"
                            id="yourname">
                        </p:inputText>

There are other fields similar to that, asking the user to fill them in order to fill the backing bean with new data instead of the default values preloaded when the page was loaded. Everything is grouped inside a h:panelGrid container with id="grid". Everything is also inside a h:form.

There is a button which somehow modifies the backing bean attributes and tries to reload the form so the input fields have those values on them.

<p:commandButton id="preload" value="Preload Example Data"
                    actionListener="#{controller.preload}">
                </p:commandButton>

And the bean and its method is the following one.

public class Controller implements Serializable {

private static final long serialVersionUID = 5754692548431690216L;

@ManagedProperty(value = "#{person}")
private Person person;

public void preload(ActionEvent event) {

    this.person.setName(...);

    (...)

    System.out.print("[PRELOAD COMPLETED]");        // debug purposes
    RequestContext.getCurrentInstance().update("grid");
}
Niconoid
  • 107
  • 2
  • 12
  • 1
    Is the grid inside or outside `` or any other `NamingContainer`? If inside then `update("grid")` won't work for reasons explained here: http://stackoverflow.com/q/8634156 – BalusC Mar 29 '16 at 20:48
  • 1
    In hindsight, you seem to describe two problems: 1) action not invoked and 2) view not updated. Which one exactly is it? Is the action invoked or not? If action is not invoked at all then there's no point asking how to fix the update. If action is indeed never invoked (i.e. debug breakpoint on method doesn't hit), then this should apply: http://stackoverflow.com/q/2118656 – BalusC Mar 29 '16 at 20:50
  • Thanks for the reply @BalusC , I was having a fight in my mind with update and process attributes confusing them. I've also removed the update("grid") from the action inside the class and instead included inside the button the following signature. `` – Niconoid Mar 29 '16 at 21:40
  • You're still not clear as to describing the concrete problem and whether you already solved it with that line. – BalusC Mar 30 '16 at 07:02
  • @BalusC The concrete problem was that I was seeing how the whole page was processed (h:messages were shown as it was sent to the server, due to another action), and then changing some attributes in the command button would make the action not to work at all, so I was messing the "process" (I was processing "@all", and there is another button in the page) and "update" attributes. Now that I only process the event in that button with "@this", I just refresh the whole page which is just a form and the text fields are updated with the correct data. – Niconoid Mar 30 '16 at 08:20

0 Answers0