This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSF dynmaic columns generation  RSS feed

 
Brunda Gundamaraj
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have created a backing bean which will generate a dynamic table with dynamic columns.
I need two scenarios in this

(i) display static text
(ii) display checkboxes

In (i) i am able to generate the static text in the table but am not able to get the row names.
I tried two approches
one -. including a <h:column> tag in the datatable tag
<h:dataTable binding="#{dynamicTableSelectItems.checkBoxTable}" value="#{dynamicTableSelectItems.attendeeTypes}" var="varData" border="2">
<h:column>
<hutputText value="Hee" />
</h:column>
</h:dataTable>

the second approach i am trying to generate it programatically
ie. i create another column and add it to the data table for the row names and create another column and add it to the same data table.
Problem with this is it is only the last value in the list

Can some one please hep me with this ?

The second scenario

I used HtmlSelectManyCheckbox for that.
I am able to display the checkboxes. but am not able to get the selected values and display the selected values again

Can some one please hep me with this ?

Thanks
Brunda
 
Brunda Gundamaraj
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Solved the static text problem.

But am still stuck with the checkbox one.
I can render the checkboxes but i am not able to retian the selected values.

I tried the following approach.

public UIData createTable(ArrayList tracks,ArrayList selectItemsList){
System.out.println("Inside CreateDataTable Method");
HtmlDataTable dataTable = new HtmlDataTable();
HtmlPanelGrid grid = new HtmlPanelGrid();
UIColumn col = null;
HtmlOutputText headers = null;
UIOutput text = null;
HtmlSelectManyCheckbox dynamicCheckBox= null;
UISelectItems selItems;
List attendees = new ArrayList();
List selectItems = new ArrayList();
System.out.println("SelectItems List Size --> "+selectItemsList.size());
dynamicCheckBox = new HtmlSelectManyCheckbox();
dynamicCheckBox.setId("checkBox");
col = new UIColumn();
selItems = new UISelectItems();
Application app = FacesContext.getCurrentInstance().getApplication();
ValueBinding vb = app.createValueBinding("#{hashMapDemo.selectedItemsList}");
ValueBinding vb1 = app.createValueBinding("#{hashMapDemo.selectItemsList}");
System.out.println("Value Binding of Checkbox is --> "+vb.getExpressionString());
System.out.println("Value Binding of SeelctItems is --> "+vb1.getExpressionString());
dynamicCheckBox.setValueBinding("value",vb);
selItems.setValueBinding("value",vb1);
dynamicCheckBox.getChildren().add(selItems);
col.getChildren().add(dynamicCheckBox);
dataTable.getChildren().add(col);
System.out.println("Before exiting the method");
return dataTable;
}

In my JSP page
i have the following

<h:dataTable binding="#{hashMapDemo.data}" value="#{hashMapDemo.tracks}" var="att" border="1">
</h:dataTable>

The problem is on clicking on submit on the page the set method is not being called.
But why it is not being called i am not able to make out.
selectedItemsList and selectItemsList have their setter methods in the bean.

Any help is appreciated.
Thanks
Brunda
 
Brunda Gundamaraj
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can render the checkboxes (for multiple columns)

I wasnt able to get the values because of there was no
checkBox.setSelectedValues(selectedItems);
in my code.

Adding this line allowed me to save the selected values.

But the problem is only the final selected values (ie value in the final row) are being retained that is because the the selectedItems string[] is being overwritten.

Is there any way to append values to the string ?



Any help is appreciated.
Thanks
Brunda
 
Brunda Gundamaraj
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was able to solve my problem.

Thanks
Brunda
 
J At
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you share how you solved the problem of the string being rewritten?
I am trying to insert a dropDown in each row of a jsf table, but then am having problem getting the selected element for each drop-down as I do not know how to differentiate between the drop-downs.
 
Brunda Gundamaraj
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by J At:
Can you share how you solved the problem of the string being rewritten?
I am trying to insert a dropDown in each row of a jsf table, but then am having problem getting the selected element for each drop-down as I do not know how to differentiate between the drop-downs.


i used a HtmlSelectBooleanCheckBox for each of my columns. and retrieved the values from the RequestMap.

Is your requirement dynamic number of columns ???
If yes then you can set the SelectOne id as you want and based on that maybe you can retrieve the selected values.

haven't actually tried with drop downs but hope this works out for you
 
Chris Tiearney
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have a problem adding elements programatically. I have already found another forum post where I posted the problem but nobody has replied yet. Maybe you could take a look at it and let me know what you think?

Here is the URL:
Link to other post
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!