tags:

views:

301

answers:

1

I am having some trouble with using h:selectOneRadio. I have a list of objects which is being returned which needs to be displayed. I am trying something like this:

<h:selectOneRadio id="selectPlan" layout="pageDirection">
    <f:selectItems value="#{detailsHandler.planList}" />
</h:selectOneRadio>

and planList is a List of Plans. Plan is defined as:

public class Plan {
    protected String id;
    protected String partNumber;
    protected String shortName;
    protected String price;
    protected boolean isService;
    protected boolean isOption;  
    //With all getters/setters
}

The text that must appear for each radio button is actually in a properties file, and I need to insert params in the text to fill out some value in the bean. For example the text in my properties file is:

plan_price=The price of this plan is {0}.

I was hoping to do something like this:

<f:selectItems value="<h:outputFormat value="#{i18n.plan_price}">
    <f:param value="#{planHandler.price}">
</h:outputFormat>" />

Usually if it's not a h:selectOneRadio component, if it's just text I use the h:outputFormat along with f:param tags to display the messages in my .property file called i18n above, and insert a param which is in the backing bean. here this does not work. Does anyone have any ideas how I can deal with this?

I am being returned a list of Plans each with their own prices and the text to be displayed is held in property file. Any help much appreciated.

Thanks!


I am now able to resolve the above issue following the recommendation below. But now I have another question. Each radio button item must display like this:

Click **here**  to see what is included. The cost is XX.

Now the above is what is displayed for each radio button. The "here" needs to be a hyperlink which the user can click and should bring up a dialog box with more info.I can display the sentence above but how do I make the "here" clickable?

Since the above is what is displayed it is the label for SelectItem(Object value, String label) which is returned.

Any ideas much appreciated.

+1  A: 

The value passed to <f:selectItems /> must be a list or array of type javax.faces.model.SelectItem.

You can set the output label in the constructor of the SelectItem. I imagine you can access your properties file from the backing bean. The method to get the SelectItems would look something like this:

public List<SelectItem> getPlanItems() {
  List<SelectItem> list = new ArrayList<SelectItem>();
  for (Plan plan : planList) {
    String label = buildPlanPriceLabel(plan.getPrice());
    list.add(new SelectItem(plan, label));
  }
  return list;
}

Leaving buildPlanPriceLabel as an exercise for the reader.

Naganalf
Correct. However, a `Map<Object, String>` also just works in JSF 1.x. In JSF 2.x you can even use a list or array of javabeans as the OP attempted to use, but you'll have to set the `var`, `itemLabel` and `itemValue` attributes as well which was missing here. Also see [this answer](http://stackoverflow.com/questions/2166934/using-a4jrepeat-or-uirepeat-inside-richdatatable-doesnt-render-radio-buttons/2167025#2167025) for an example.
BalusC
Thank you for your comments I have followed these steps and am able to show the information in my list. However now I face another challenge and I have edited my question above. Please let me know if you have any ideas about it.
msharma
Based on your requirements, h:selectOneRadio is entirely the wrong component to use! You should be using ui:repeat or a4j:repeat.
Naganalf