p:selectOneRadio doesn't render default value

UI Components for JSF
Post Reply
martinPrime
Posts: 41
Joined: 11 Oct 2010, 18:26

01 Jun 2011, 13:52

Hi,

p:selectOneRadio always initializes with no radio button activated, although the value attribute is assigned to an existing object of a backed bean.
Here's an example:

Code: Select all

<p:selectOneRadio value="#{registration.selectedEventTypeId}">  
                            <f:selectItem itemLabel="Kurs" itemValue="1" />  
                            <f:selectItem itemLabel="Veranstaltung" itemValue="2" />
                        </p:selectOneRadio>
Here's the code of the backed bean:

Code: Select all

public class Registration {
   
    // eventType
    private Integer selectedEventTypeId;
   
    /** Creates a new instance of registration */
    public Registration() {
        this.selectedEventTypeId = 1;
    }
    
    public Integer getSelectedEventTypeId() {
        return selectedEventTypeId;
    }

    public void setSelectedEventTypeId(Integer selectedEventTypeId) {
        this.selectedEventTypeId = selectedEventTypeId;
    }

}
Apparently, selectedEventTypeId is initialized with "1" in the contructor, but the p:selectOneRadio always shows no button activated until one button is ticked.
It works only when assigned the value attribute directly to e. g. "1" not using the expression language.

Btw, the above mentioned example works perfect when using h:selectOneRadio.

Any ideas?
BR
Martin

barry
Posts: 1
Joined: 07 Jul 2011, 08:48

07 Jul 2011, 08:49

I am encountering the same issue. Any ideas? Known Bug?

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

07 Jul 2011, 09:05

Tried to replicate it locally but it worked for showcase sample;

http://www.primefaces.org/showcase-labs ... eRadio.jsf

Set text as Option 2 and it gets displayed as selected.

If you bind a string value, it will be displayed, I think we also need to do consider converters here, both implicit and explicit ones. Feel free to create an issue ticket for this.

fvdnabee
Posts: 3
Joined: 29 Jul 2011, 16:21

29 Jul 2011, 16:35

I too experienced the same issue using PrimeFaces 3.0.M3-SNAPSHOT.

Like optimus said, when you take into account that the value of the selectItem is a string then it does work. This means editing your backend bean as folows(changes in between literal bold tags):

Code: Select all

 public class Registration {
       
        // eventType
        private Integer selectedEventTypeId;
       
        /** Creates a new instance of registration */
        public Registration() {
            this.selectedEventTypeId = 1;
        }
       
        public [b]String[/b] getSelectedEventTypeId() {
            return selectedEventTypeId[b].toString()[/b];
        }

        public void setSelectedEventTypeId([b]String [/b]selectedEventTypeId) {
            this.selectedEventTypeId = [b]Integer.parseInt[/b](selectedEventTypeId);
        }

    }
When using the standard JSF selectOneRadio component it does work with the backend bean in the OP so maybe there is a converter error in primefaces.

martinPrime
Posts: 41
Joined: 11 Oct 2010, 18:26

29 Jul 2011, 17:54

I created an issue for that, sorry, forgot to mention:
http://code.google.com/p/primefaces/iss ... %20Summary

Thanks for confirming that the error likely has to do something with missing converters.
Martin

swwhyte
Posts: 1
Joined: 01 Nov 2013, 01:07

01 Nov 2013, 01:10

Has this issue been resolved? I am still having this problem.
Radio button initializes with nothing selected though value (which IS a string) is set in backing bean.
This is with PF 3.5

aissa.boulila
Posts: 2
Joined: 06 Jun 2019, 23:45

11 Jun 2019, 21:40

Has this issue been resolved ? It still happens with PF 7.0.

No problem with JSF component (<h:selectOneRadio>)

Thanks

aissa.boulila
Posts: 2
Joined: 06 Jun 2019, 23:45

17 Jun 2019, 22:42

Resolved with some fixes on Converter.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 34 guests