0

here my idea with oneRadio

<h:selectOneRadio value="#{controller.myboolean}">
    <f:selectItem itemValue="#{true}" itemLabel="Yes"/>
    <f:selectItem itemValue="#{false}" itemLabel="No"/>
</h:selectOneRadio>

here the with commandLink:

<h:commandLink value="YES" action="#{controller.setMyboolean(true)}"/>
<br/>
<h:commandLink value="NO" action="#{controller.setMyboolean(false)}"/>

In my application I want to show or disable my table with <h:selectOneRadio>. For example if i have chosen the first radioButton the table is shown. I don't to click a <h:commandButton> to change the value myboolean. Therefore my excepted reaction of my application has to be like a <h:commandLink>. I click on it and the value changes, the table is shown. But in my case I want to use a <h:selectOneRadio>

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
JavaNullPointer
  • 1,199
  • 5
  • 21
  • 43
  • my problem is that the value of myboolean not change sif i have clicked on one of the radiobuttons.... – JavaNullPointer Dec 22 '12 at 15:14
  • 2
    Is this real code or did you attempt to carelessly write from top of head without actually having tested it? The `setmyboolean` is not a valid setter method name and the `{true}` and `{false}` values are not valid EL. In the future questions please post **real** code. – BalusC Dec 22 '12 at 15:19
  • 2
    Hm, [deja vu](http://stackoverflow.com/questions/13934503/jsf-validator-with-parameters-from-input). – BalusC Dec 22 '12 at 15:21
  • i thought it should be more easy for you to understand my prob... but i am going to take more care about it in future,... – JavaNullPointer Dec 22 '12 at 15:49
  • Yes, but it's a potential waste of time. One wouldn't be happy to spend time explaining how `{true}` and `{false}` are wrong and that you should use `#{true}` and `#{false}` or just `true` and `false` and then receive a comment like "sorry typo i fixed question" or something hopelessly disrespectful like that. – BalusC Dec 22 '12 at 16:07
  • i post my edit...just take a look down...but thats not the case here....so calm down! – JavaNullPointer Dec 22 '12 at 16:15

3 Answers3

1

I would advice you to use primefaces extentions. It was some nice components for some boolean values... Like: http://fractalsoft.net/primeext-showcase-mojarra/views/triStateCheckbox.jsf

You could also use primefaces' booleanButton, like: http://www.primefaces.org/showcase/ui/selectBooleanButton.jsf

Anyways, I hope this helps you, if you can be flexible and use another component diferent then selectOneRadio... And also if you have the liberty to add more dependencies into the project..

Bye

Marco Noronha
  • 115
  • 1
  • 9
  • 31
0

Unless you have it set up behind the scenes, the issue is most likely that you need to implement a converter to handle the conversion between the string "true" and "false" to the boolean. In your commandLink, the action specified in the EL passes a boolean to your function. However, in the selectOneRadio example, you are submitting a string.

For more information, take a look at: http://download.oracle.com/otn_hosted_doc/jdeveloper/j2ee101302/jsf_apps/eventvalidate/sf_avc_converters.html

jcern
  • 7,798
  • 4
  • 39
  • 47
  • dont wanna use a string... watch edit... thats not the problem. the function of my command-link is a default constructor – JavaNullPointer Dec 22 '12 at 15:15
  • 1
    I may still not understand what you want to do, but from what I can see it is probably because the form is not being submitted. Clicking on the `commandLink` will submit the value, whereas selecting the radio button will only cause the value to be set when the form is submitted. It seems like you would either need to add an onChange event listener to submit the field, or have a `commandButton` that submits the form. – jcern Dec 22 '12 at 15:27
  • yeah a onChange event listener could be a solution! – JavaNullPointer Dec 22 '12 at 15:44
  • thanks for your idea with the event listener! – JavaNullPointer Dec 22 '12 at 16:15
  • @JavaNullPointer just in case, you should know that this event listener should be handled by an ajax call, otherwise the event won't fire until the form is submitted (using an `UICommand` component like ``). But with that comes another question: do you really need this value to be setted by ajax every time the user changes the radio button selection? If it's just for presentation purposes, the *effect* can be handled by plain JavaScript and set the `true` or `false` value on the form submit for processing your data. – Luiggi Mendoza Dec 22 '12 at 16:32
  • watch my answer... thats was it ! thanks! – JavaNullPointer Dec 22 '12 at 16:44
-1

this works quite nice:

<h:selectOneRadio value="#{controller.myboolean}" valueChangeListener="#{controller.save}" immediate="true" onchange="this.form.submit()">
    <f:selectItem itemValue="#{true}" itemLabel="Yes"/>
    <f:selectItem itemValue="#{false}" itemLabel="No"/>
</h:selectOneRadio>

and with this ChangeEvent method():

public void speichereRadioButtons(ValueChangeEvent vce){
   boolean temp=(Boolean) vce.getNewValue();
   setmyBoolean(temp);
   FacesContext.getCurrentInstance().renderResponse();
}
JavaNullPointer
  • 1,199
  • 5
  • 21
  • 43
  • 2
    It looks that you don't know much about web programming not JSF 2 ``. It would be good to check some pages like the ones mentioned in [JSF wiki page](http://stackoverflow.com/tags/jsf/info). This *could do* what you need, but is a good example of what you don't have to do in real world web apps. – Luiggi Mendoza Dec 22 '12 at 16:44