If you're not generating the table from the bean, but rather in .jsp then the 
way I got round it (I saw this a discussion board) is to use a 
selectBooleanCheckbox: e.g.


                        <h:selectBooleanCheckbox value="#{item.selected}" 
onclick="selectOne(this.form, this)"  id="selectItemRadio"/>

And then have some javascript to enforce only one box is selected:


            function selectOne(form, button)
            {
                        turnOffRadioForForm(form);
                        button.checked = true;
             }
        
            function turnOffRadioForForm(form)
            {
                for(i=0; i<form.elements.length; i++)
            {
        
                        if(form.elements[i].type=='checkbox')
                        {
                                form.elements[i].checked = false;
                    }
              }
             }


It's not the cleanest solution in the world, but it works. I really think they 
should name JSF - Javascript Server Faces, due to the amount of Javascript you 
have to use to get anything to work.


 

-----Original Message-----
From: Jorge Vásquez [mailto:[EMAIL PROTECTED] 
Sent: 03 August 2006 18:36
To: 'MyFaces Discussion'
Subject: RE: HELP with h:selectOneRadio inside h:dataTable

FINALLY I MADE IT!!!,
In case someone is interested I finally was able to generate a table from the 
bean with a select one radiobutton...
The first thing you have to do is generate the list of radiobuttons as
follows:
                HtmlSelectOneRadio orderRadioButton = (HtmlSelectOneRadio) 
app.createComponent(HtmlSelectOneRadio.COMPONENT_TYPE);
                orderRadioButton.setId("ordenar");
                orderRadioButton.setRendered(false);
                UIComponent component =
FacesUtils.getFacesContext().getViewRoot().findComponent("fieldsForm");
                for (int i = 0; i < dataFieldCollection.getCollCount();
i++){
                UISelectItem selectItem = 
        
(UISelectItem)app.createComponent(UISelectItem.COMPONENT_TYPE);
                        SelectItem item = new SelectItem(i+"", "");
                        selectItem.setValue(item);
                        orderRadioButton.getChildren().add(selectItem);
                }

And then you generate the panel where each radioButton element has the same 
index as the radiobutton option in the past list and in the for attribute they 
reference the HtmlSelectOneRadio component, the code is as follows (The 
important lines are the last ones!!!):

                component.getChildren().add(orderRadioButton);
                for (int i = 0; i < dataFieldCollection.getCollCount();
i++){
                        altDataField fld =
(altDataField)dataFieldCollection.getCollObject(i);
                        HtmlOutputText fieldName = (HtmlOutputText) 
app.createComponent(HtmlOutputText.COMPONENT_TYPE);
                        fieldName.setValue(fld.getField("DESCR"));
                        searchFieldsPanel.getChildren().add(fieldName);
                        HtmlInputText inputText = (HtmlInputText) 
app.createComponent(HtmlInputText.COMPONENT_TYPE);
                        int entryLength =
Integer.parseInt(fld.getField("ENTRYLENGTH"));
        
inputText.setMaxlength(Integer.parseInt(fld.getField("ENTRYLENGTH")));
                        if (entryLength > 40) {
                                inputText.setSize(40);
                        } else {
                                inputText.setSize(entryLength);
                        }
                        searchFieldsPanel.getChildren().add(inputText);
                        HtmlSelectBooleanCheckbox returnCheckBox =
(HtmlSelectBooleanCheckbox)
app.createComponent(HtmlSelectBooleanCheckbox.COMPONENT_TYPE);
                        returnCheckBox.setSelected(true);
                        searchFieldsPanel.getChildren().add(returnCheckBox);
                        HtmlRadio radioButton = (HtmlRadio)
app.createComponent(HtmlRadio.COMPONENT_TYPE);
                        radioButton.setFor("fieldsForm:ordenar");
                        radioButton.setIndex(i);
                        searchFieldsPanel.getChildren().add(radioButton);
                }

COOL!!!

Regards,
JV


-----Mensaje original-----
De: Jorge Vásquez [mailto:[EMAIL PROTECTED] Enviado el: jueves, 03 de agosto de 
2006 10:53
Para: 'MyFaces Discussion'
Asunto: RE: HELP with h:selectOneRadio inside h:dataTable

Hi,
Does somebody know which HtmlSelectOneRadio impl to use in order to allow it to 
force a same id for all the radio buttons in a table?
One appreciation:  I don´t know if I am lost here but I am starting to think 
that JSF has some serious design flaws in respect to this html element?

Regards,
Jorge Vasquez 

-----Mensaje original-----
De: Jorge Vásquez [mailto:[EMAIL PROTECTED] Enviado el: jueves, 03 de agosto de 
2006 9:39
Para: 'MyFaces Discussion'
Asunto: RE: HELP with h:selectOneRadio inside h:dataTable

Thanks Martin,
Due to the nature of the form I decided to use another strategy to solve the 
problem, more based on a binding mechanism with a panel Grid, in this case I am 
having problems when manipulating an HtmlSelectOneRadio component, do you have 
by any chance have an example where a SelectOneRadio component is included into 
a panelGrid from java code and where the selectOneRadio element when rendered 
has the same name for each row but different values.
In case it helps this is my current xhtml code:

<h:panelGrid id="pruebaPanel" binding="#{searchTreeBean.searchFieldsPanel}"
columns="4" border="0" cellspacing="0"/>

And this is my java code where the panelGrid gets created:

        public void initializeFieldsPanel() {
                searchFieldsPanel.getChildren().clear();
                Application app =
FacesUtils.getFacesContext().getApplication();
                HtmlOutputText emptyString = (HtmlOutputText) 
app.createComponent(HtmlOutputText.COMPONENT_TYPE);
                emptyString.setValue("");
                searchFieldsPanel.getChildren().add(emptyString);
                emptyString = (HtmlOutputText)
app.createComponent(HtmlOutputText.COMPONENT_TYPE);
                emptyString.setValue("");
                searchFieldsPanel.getChildren().add(emptyString);
                HtmlOutputText returnStr = (HtmlOutputText) 
app.createComponent(HtmlOutputText.COMPONENT_TYPE);
                returnStr.setValue(Functions.getText("fields", "Return"));
                searchFieldsPanel.getChildren().add(returnStr);
                HtmlOutputText orderStr = (HtmlOutputText) 
app.createComponent(HtmlOutputText.COMPONENT_TYPE);
                orderStr.setValue(Functions.getText("fields", "Order"));
                searchFieldsPanel.getChildren().add(orderStr);
                
                for (int i = 0; i < dataFieldCollection.getCollCount();
i++){
                        altDataField fld =
(altDataField)dataFieldCollection.getCollObject(i);
                        HtmlOutputText fieldName = (HtmlOutputText) 
app.createComponent(HtmlOutputText.COMPONENT_TYPE);
                        fieldName.setValue(fld.getField("DESCR"));
                        searchFieldsPanel.getChildren().add(fieldName);
                        HtmlInputText inputText = (HtmlInputText) 
app.createComponent(HtmlInputText.COMPONENT_TYPE);
                        int entryLength =
Integer.parseInt(fld.getField("ENTRYLENGTH"));
        
inputText.setMaxlength(Integer.parseInt(fld.getField("ENTRYLENGTH")));
                        if (entryLength > 40) {
                                inputText.setSize(40);
                        } else {
                                inputText.setSize(entryLength);
                        }
                        searchFieldsPanel.getChildren().add(inputText);
                        HtmlSelectBooleanCheckbox returnCheckBox =
(HtmlSelectBooleanCheckbox)
app.createComponent(HtmlSelectBooleanCheckbox.COMPONENT_TYPE);
                        returnCheckBox.setSelected(true);
                        searchFieldsPanel.getChildren().add(returnCheckBox);
                        HtmlSelectOneRadio orderRadioButton =
(HtmlSelectOneRadio) app.createComponent(HtmlSelectOneRadio.COMPONENT_TYPE);
                        SelectItem item = new SelectItem(i+"");
                        orderRadioButton.getChildren().add(item);
//                      orderRadioButton.setValue(item);
        
searchFieldsPanel.getChildren().add(orderRadioButton);
                }
        }

Where I am mostly interested is in the last 5 lines of code where the 
HtmlSelectOneRadio component is created...

Regards and thanks again,
Jorge Vásquez

-----Mensaje original-----
De: Martin Grotzke [mailto:[EMAIL PROTECTED]
Enviado el: miércoles, 02 de agosto de 2006 10:48
Para: MyFaces Discussion
Asunto: Re: HELP with h:selectOneRadio inside h:dataTable

Hello,

have a look at
http://wiki.apache.org/myfaces/Display_Radio_Buttons_In_Columns and 
http://myfaces.apache.org/sandbox/tagreference.html#selectOneRow.
You find an example for the last one at
http://irian.at/myfaces-sandbox/selectOneRow.jsf.

Cheers,
Martin


On Wed, 2006-08-02 at 10:38 -0500, Jorge Vásquez wrote:
> Hi, I have no idea on how to include selectOneRadio elements inside a 
> datatable in order for each f:selectItem to be associated to a 
> different row, but all the elements belonging to the same radiobutton 
> group.  I am currently getting independent radiobutton elements for 
> each row but I need all of them to belong to the same group in order 
> to allow only one of the rows to be selected at once.
> 
>  
> 
> In case it helps I am currently using the code:
> 
>  
> 
>                                    <h:dataTable 
> value="#{searchTreeBean.dataFieldList}"var="dataField">
> 
>                                          <h:column>
> 
>                                                <h:outputText 
> value="#{dataField.description}"/>
> 
> 
> <f:verbatim>&amp;nbsp;&amp;nbsp;&amp;nbsp;</f:verbatim>
> 
>                                          </h:column>
> 
>                                          <h:column>
> 
>                                                <h:inputText 
> value="#{dataField.searchString}"maxlength="#{dataField.entryLength}"
> size="#{dataField.entrySize}"/>
> 
> 
> <f:verbatim>&amp;nbsp;&amp;nbsp;&amp;nbsp;</f:verbatim>
> 
>                                          </h:column>
> 
>                                          <h:column>
> 
> 
> <h:selectBooleanCheckboxvalue="#{dataField.returnSelected}" />
> 
>                                          </h:column>
> 
>                                          <h:column>
> 
> 
> <h:selectOneRadioid="myRadioButton">
> 
>                                                      <f:selectItem 
> itemValue="#{dataField.orderBySelected}"/>
> 
> 
> </h:selectOneRadio>     
> 
> 
> </h:column>                                    
> 
>                                    </h:dataTable>
> 
>  
> 
> Any ideas?  
> 
>  
> 
> Regards,
> 
> JV
> 
> 

Reply via email to