Mr.J4mes
Mr.J4mes

Reputation: 9266

PrimeFaces: <p:inline> inside <p:dataTable> not function properly on ajax call

In my application, I use PrimeFaces's <p:inline> inside <p:dataTable> component to implement update feature as following:

<p:dataTable var="m" value="#{mrBean.menu}">

   <p:column headerText="Name" >
      <p:inplace editor="true" >
         <p:ajax event="save" listener="#{mrBean.changeName}" update="button" />  
         <p:inputText value="#{m.name}" />  
      </p:inplace>
   </p:column>

</p:dataTable>

<p:commandButton id="button" value="Confirm" actionListener="#{mrBean.confirm}"
                 disabled="#{not mrBean.canConfirm}"/> 

And this is my Managedbean:

@ManagedBean(name = "mrBean")
@ViewScoped
public class MrBean {
   private List<Meal> menu;
   private boolean    canConfirm;

   public void changeName() {
      this.canConfirm = true;
   }

   public void confirm() {
      System.out.println("Updated database!");
   }
}

When I finished editing name and clicked Save, my Eat button was not enabled.

I'd be very grateful if you could show me what I have done wrong here. I am using PrimeFaces 3.0.RC2.

Upvotes: 1

Views: 1503

Answers (3)

Mr.J4mes
Mr.J4mes

Reputation: 9266

The problem is that <p:inline> cannot be used inside <p:dataTable> to edit. What I should use instead is <p:cellEditor>.

Upvotes: 1

Damian
Damian

Reputation: 3050

You must have boolean isReadyToEat() {return readyToEat;} method in your bean (and String getSomeText() , void setSomeText(String text)). You also need to place commandButton and inplace inside form tag.

If the button becomes enabled after refreshing page in browser you probably need

<f:ajax execute="@form" render="button" />

within inplace tag.

Upvotes: 0

Daniel
Daniel

Reputation: 37061

Works just fine for me,

I guess you omitted some code from the one you posted on purpose, but if not, will post the one I generated beside the one you posted...

private String  someText ="xxx";


public String getSomeText() {
    return someText;
}

public void setSomeText(String someText) {
    this.someText = someText;
}

 public boolean isReadyToEat() {
    return readyToEat;
 }

public void setReadyToEat(boolean readyToEat) {
    this.readyToEat = readyToEat;
}

and wrapped the code of the xhtml with <h:form>

and it works 100%

output is

Ready to eat: true

YUMMY!

Upvotes: 1

Related Questions