It's not a secret anymore!*
The moose likes JSF and the fly likes Displaying Two Buttons in one Row from HashMap Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "Displaying Two Buttons in one Row from HashMap" Watch "Displaying Two Buttons in one Row from HashMap" New topic
Author

Displaying Two Buttons in one Row from HashMap

Gautam Ry
Ranch Hand

Joined: Dec 30, 2008
Posts: 41
Hi

I am trying to display buttons that are generating dynamically from a HashMap.
And another requirement is that I need to display two buttons in one row and so on.
I am able to display buttons but these are coming one after another i.e. one row contains one button.
My code is as follows:

JSF

<h:form id="contactcenterPr_form">
<h:dataTable border='1' value="#{ccSearchAndCaseProcessMB.processForOutBound}" var='var1' id="datatable1">

<h:column>
<h:commandButton type="button" id="btn" value="#{var1.value}"
onclick="javascript:changeValue1('#{var1.key}');" styleClass="subBtn" />
</h:column>
</h:dataTable>

</h:form>


Backing Bean

public List getProcessForOutBound() {

List prListOutbound = null;
HashMap obj=new HashMap();
obj.put("1","process1");
obj.put("2","process2");
obj.put("3","process3");
prListOutbound =new java.util.ArrayList(obj);
return prListOutbound;
}

Regards
Gautam
Gautam Ry
Ranch Hand

Joined: Dec 30, 2008
Posts: 41
Any update ?
I am really stuck. I need your help.

Regards
Gautam
Ilari Moilanen
Ranch Hand

Joined: Apr 15, 2008
Posts: 198
So is your problem that you have a varying number of buttons? If you would have a constant number of buttons you would not bother with arraylists of datatable and you would just throw it all to a html table (maybe with JSF but that is just details).

Well, if you have a varying number of buttons then maybe I would put a objects that contain both of the buttons in the list instead of map values. Something like this



But that is just in case you have a varying number of buttons.

Oh, BTW why do you use HashMap? It does not quarantee the order of its contents so you get the buttons in random order.
Gautam Ry
Ranch Hand

Joined: Dec 30, 2008
Posts: 41

Thanks for your brilliant response.
It's working as per my requirement.

Regards
Gautam
Ilari Moilanen
Ranch Hand

Joined: Apr 15, 2008
Posts: 198
You are welcome.

By the way, I would remove the id attribute since it is not allowed to have same id on different elements on same page.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Displaying Two Buttons in one Row from HashMap