What I did is basically added some code in the getters and setters methods that
are bound to the boolean checkbox. I'm pretty sure there's a better way of
doing this, and if anyone knows, please tell me. But I believe this is
probably what jazir had in mind and here's what I implemented a while back:
@Name("testJobList")
| @Stateful
| public class TestBean implements TestLocal {
| @DataModel("JobList")
| private List<JobStatus> statusList = null;
|
| @DataModelSelection("JobList")
| private JobStatus jobSelected;
|
| private Map<String, Boolean> selectedMap = null;
|
| private boolean selected;
|
| @Factory("JobList")
| public final void retrieveJobs() {
| selectedMap = new HashMap<String, Boolean>();
|
| List<JobStatus> jobStatus = ... ; // get jobStatus object
| }
|
| public final String performAction() {
| for (JobStatus tempJob : statusList) {
| // Assuming a JobStatus job has fields (with getters) attr1
| String attr1 = tempJob.getAttr1();
| if (selectedMap.get(attr1)) {
| // perform action code here...
| }
| }
| return "goToPage";
| }
|
| public final boolean isSelected() {
| if (jobSelected != null && selectedMap != null) {
| String key = jobSelected.getAttr1();
| Boolean value = selectedMap.get(key);
| if (value == null) {
| return false;
| } else {
| return value;
| }
| } else {
| return false;
| }
| }
|
| public final void setSelected(final boolean inputSelected) {
| if (selectedMap != null && jobSelected != null) {
| String key = jobSelected.getAttr1();
| selectedMap.put(key, inputSelected);
| }
| }
|
| @Remove
| @Destroy
| public void destroy() {
|
| }
| }
Here's the JSP markup:
<h:form>
| <h:dataTable value="#{JobList}" var="selectJob">
| <h:column>
| <h:selectBooleanCheckbox
value="#{testJobList.selected}" />
| </h:column>
| <h:column>
| <f:facet name="header">
| <h:outputText value="attr1" />
| </f:facet>
| <h:outputText escape="true"
value="#{selectJob.attr1}" />
| </h:column>
| <h:column>
| <f:facet name="header">
| <h:outputText value="attr2" />
| </f:facet>
| <h:outputText value="#{selectJob.attr2}" />
| </h:column>
| <h:commandButton value="performAction"
| action="#{testJobList.performAction}" type="submit" />
| </h:form>
This code for the getters and setters is probably a little muddled because I'm
using the Tomahawk extended datatable to sort things (I took out the Tomahawk
extended datatable JSF markup from the JSP). In this case, my unique
identifier for the object would be attr1. I believe the setters and getters
could probably be simpler (and one should probably use a List instead of a
Map), something like this:
List selectedList;
|
| public final boolean isSelected() {
| return selectedList.contains(jobSelected); // or return
selectedList.contains(jobSelected.getAttr1());
| }
|
| public final void setSelected(final boolean inputSelected) {
| if (inputSelected) {
| selectedList.add(jobSelected); // or
selectedList.add(jobSelected.getAttr1());
| }
| }
But the whole point here is that one needs to add some more code (more than the
usual stuff) in the getters/setters in the value binding for the boolean
checkbox - and make a note that JSF iterates through all the rows of the
datatable - and that one can use this to your advantage in the getters/setters.
This works for me and I didn't have to modify the entity... I was probably
not clear in my explanation (I gotta go to sleep :) ), but I hope this helps.
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3979556#3979556
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3979556
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user