tags:

views:

1909

answers:

2

I am using NetBeans and JSF to do my project. Recently I encountered a problem that confused me.

The question: There is a set of check box groups that identify the artifacts from the nature, creator, period and school. And all the artifacts are stored in a table of database. I would like to select the items by nature or creator or something like that, and generate a list for the items selected in the next page.

There are some tables of database for artifacts, nature, creators and school, and the type_ID(this is the nature), creator_ID, school_ID are the foreign keys in artifacts table.

I have bound the tables with respective check boxes. For example, if I want to select nature is painting, creator is Davinci, school is Italian Renaissance, and then I click Search button. It will go to next page that generate a list of artifacts about all Italian Renaissance paintings created by Davinci.

How can I do that? I was confused by JSF, but I have to use JSF to do my project.

Can anyone help me please? Thank you very, very much!

+1  A: 

What you need to do is have a map property that will hold the selected items and you use that with the checkboxes and the value that the check box relates to. Here is a bit of rich faces JSF with a checkbox.

<rich:dataTable id="existingUsersDataTable" value="#{bean.usersForOrgList}" var="user">
    <rich:column>
    <f:facet name="header">
        <h:outputText value="#{msgs.selectPrompt}" />
     </f:facet>
         <h:selectBooleanCheckbox value="#{bean.selectedUsers[user]}" />
</rich:column>
    <rich:column>
    <f:facet name="header">
        <h:outputText value="#{msgs.userNamePrompt}" />
     </f:facet>
         <h:outputText value="#{user.userName}" />
</rich:column>
</rich:dataTable>

And here is the relevant bit of the backing bean

public class bean
{
    // map for selected stuff on the JSF page
    private Map< UserDTO, Boolean >selectedUsers = new HashMap< UserDTO, Boolean >();
    // users to be displayed in the table
    private List< UserDTO >usersForOrgList = new ArrayList< UserDTO >();
    /* this is the list that will have the selected users */
    private UserDTO selectedCurfUserDTO = null;
    /* TODO: add all the other stuff including getters and setters */
}

Use this function to get the selected users

private void prepareSelectedList()
{
    // reset the list
    setSelectedUsersList( new ArrayList< UserDTO >() );
    for( UserDTO userDTO : getSelectedUsers().keySet() )
    {
     if( getSelectedUsers().get( userDTO ) == true )
     {
         // and this is the list of selected users
      getSelectedUsersList().add( userDTO );
     }
    }
}
Martlark
Hi, thank you for your answer, but I still a little confused about the segment of code that you provided, I am fresher here, so i can not insert the pics into my question, so I can not explain my problem very well, can you leave your email address to me plz? so that I can explain my problem with the pics. Thank you very very much.
Alexzzy
A: 

great! TY!!!

Really great!

thankfull