0
  <p:column>  
    <p:commandButton id="selectButton" update="@(form)" oncomplete="userDialog.show()" icon="ui-icon-search" title="View">  
      <f:setPropertyActionListener value="#{book}" target="#{CreateBookBean.selectedUser}" />  
    </p:commandButton>  
    </p:column>  
  </p:dataTable>  
</p:outputPanel>

<p:dialog header="User Detail" modal="true" widgetVar="userDialog" width="200" height="175">                                                                          
  <h:panelGrid  columns="2" cellpadding="5">
    <h:outputLabel for="fname" value="First Name: " />
    <h:outputText id="fname" value="#{CreateBookBean.selectedUser.fname}" />
    <h:outputLabel for="lname" value="Last Name: " />
    <h:outputText id="lname" value="#{CreateBookBean.selectedUser.lname}" />
    <h:outputLabel for="mobileno" value="mobile no: " />
    <h:outputText id="mobileno" value="#{CreateBookBean.selectedUser.mobileno}" />
  </h:panelGrid>
</p:dialog>

i came across this example recently. the datatable is properly getting updated with the values i enter. but when i want to display it in the dialog box its not displaying anything. and i actually don understand why value="#{CreateBookBean.selectedUser.fname}" is used instead of value="#{CreateBookBean.fname}".

here is my java code

public class CreateBookBean {  

    private Book book = new Book();  
    private List<Book> books = new ArrayList<Book>();  
    private Book selectedUser;
    public String reinit() {  
        book = new Book();  

        return null;
    }

 setters and getters are included here  
}
Pramoth
  • 29
  • 1
  • 11
  • 1
    Is your question answered and thus is your problem really solved? I see that you accepted the answer of Manual, but I also see in the comments that you kept complaining that it didn't work. I do not see any feedback in that answer that your problem is really solved. The acceptance of the answer is therefore very confusing. – BalusC Jul 25 '13 at 13:30
  • well got the answer for my second question. not for the first. – Pramoth Jul 26 '13 at 04:16
  • i have still not got the answer for my first ques. can you help me with that? – Pramoth Jul 26 '13 at 05:44
  • Use firebug (or something equivalent) to check your request when you open the dialog the first time, and the response you get from the server. Post both, request and responses in your answer. What is your `form` wrapping? Both the `p:outputPanel` and the `p:dialog`? We can't see it in your code! Add it. – Manuel Jul 30 '13 at 06:33

2 Answers2

0

Use the Update attribute in the button your using to display the dialog box, for example, <p:commandButton update="dialogBoxId" . . ./> in order to display the items from your datatable.

van
  • 139
  • 2
  • the value "book" doesnt reach its target. hence on opening dialog box it shows no value! – Pramoth just now edit – Pramoth Jul 25 '13 at 12:03
0

Lets split this question in two parts.

First:

When you want to display updated values (e.g. with a h:outputText), you need to update this element. Updating this element means, it will fetch the current value of it's backing bean. Do it like this:

<p:commandButton ... update="idToUpdate1, idToUpdate2, ..." >

In order to get the idToUpdate check Naming Container in JSF2/PrimeFaces.

If you have many components which need an update, I would recomment grouping them into one NamingContainer (e.g. p:outputPanel). So you only have to update the NamingContainer, and not every single component.



Second:

#CreateBookBean.selectUser.fname means: "Fetch the CreateBookBean, fetch it's property selectUser and fetch the property of selectUser called fname". In this case you would have these class layouts:

public class CreateBookBean {
  private Book selectedUser;
  ....
  public Book getSelectedUser() {
    return this.selectedUser;
  }
}

public class Book {
  private String fname;
  ....
  public String getFname() {
    this.fname;
  }
}

#CreateBookBean.fname means: "Fetch the CreateBookBean, fetch it's property fname". In this case you would have this class layout:

public class CreateBookBean {
  private String fname;
  ....
  public String getFname() {
    return this.fname;
  }
}

According to this code you posted, i guess that the CreateBookBean has a property called selectedUser (the code reveals it: target="#{CreateBookBean.selectedUser}"), and the selectUser has a property fname.

Community
  • 1
  • 1
Manuel
  • 3,828
  • 6
  • 33
  • 48
  • the value "book" doesnt reach its target. hence on opening dialog box it shows no value! – Pramoth Jul 25 '13 at 12:01
  • Is "book" of type `User`? If so, you need to add additional code in your question in order to see the problem. Are there any exceptions/error messages during the processing? Post them as well! – Manuel Jul 25 '13 at 12:06
  • book is the var name for the datatable i use. – Pramoth Jul 25 '13 at 12:22
  • Show us some more code! xhtml and java. Otherwise we won't be able to help you! Maybe you should read [SSCCE](http://sscce.org/) as well. – Manuel Jul 25 '13 at 12:27
  • .. i have lot more code. if yu can be specific about what i want to post here? – Pramoth Jul 25 '13 at 12:46
  • 1. Everything which could be necessary to solve your problem! 2. So `book` is an element from the `createBookBean.books` list - so `book` must be some kind of `Book` class. But you assign `book` the `selectedUser`. So you are trying to assign an object which is of type `Book` to a variable which is of type `User` - that cannot work. 3. Post the code in your question, NOT in a comment! 4. Why is it `createBookBean` instead of `CreateBookBean`? (capital letter 'C') – Manuel Jul 25 '13 at 12:51
  • book is of type Book and not User. SelectedUser is also of tpye Book. still im not able to assign. – Pramoth Jul 25 '13 at 13:13
  • As long as you dont post your complete xhtml and java code which is RELEVANT for the problem, we cant help you. Add the code to your question, NOT as a comment. Please read the [http://stackoverflow.com/help] page! – Manuel Jul 25 '13 at 13:15
  • i suppose i posted the full code needed there. check it out . – Pramoth Jul 30 '13 at 05:25