webtier@glassfish.java.net

Re: [webtier] JSF 2.0 combo dependencies.

From: Imre Osswald <ioss_at_mx.jevelopers.com>
Date: Sat, 30 Jan 2010 16:03:59 +0100

Hi,
for ajax to be able to add combo B to the page you will have to have an element with an id that is rendered at the time the response gets back.
So the easiest solution would probably be to wrap your comboB in a panelGroup or something similar, which you will use as the target to be rerendered.

Hope this helps,
Imre

Am 29.01.2010 um 20:10 schrieb webtier_at_javadesktop.org:

> I'm have a usual issue with combos dependencies.
> One combo items (combo B) has relation with value selected in other one (combo A).
> When change value of first (combo A), change values of the other one (combo B).
> All go ok, but i want hide combo B when no value is selected en combo A.
>
> if i use rendered attribute in combo B, i get this error:
> "malformedXML: During update: testForm:suitems not found"
> testForm = id of form.
> suitems = id of combo B
>
> In first request, nothing selected in combo A, so it's not rendered. But if one element is selected in combo A, it's impossible update combo B because it's not rendered.
> ¿Same suggestion to resolve this issue? ¿Is it a bug of majorra implementation?
>
> Glassfish v3 and Mojarra 2.0.2 (FCS b10).
>
> Test example:
>
> Bean:
> package com.silyan.test.jee6;
>
> import java.util.ArrayList;
> import java.util.List;
> import javax.faces.bean.ManagedBean;
> import javax.faces.bean.SessionScoped;
> import javax.faces.model.SelectItem;
>
> /**
> *
> * @author angel
> */
> @ManagedBean
> @SessionScoped
> public class TestManager {
>
>
> private String selectedItem;
>
> public List<SelectItem> getItems() {
> List<SelectItem> items = new ArrayList<SelectItem>();
>
> items.add(new SelectItem("", "Selecciona uno."));
> items.add(new SelectItem("1", "Uno."));
> items.add(new SelectItem("2", "Dos."));
> items.add(new SelectItem("3", "Tres."));
> items.add(new SelectItem("4", "Cuatro."));
>
> return items;
> }
>
> private String selectedSubItem;
>
> public List<SelectItem> getSubItems() {
>
> List<SelectItem> items = new ArrayList<SelectItem>();
>
> items.add(new SelectItem(selectedItem + ".1", selectedItem + " punto Uno."));
> items.add(new SelectItem(selectedItem + ".2", selectedItem + " punto Dos."));
> items.add(new SelectItem(selectedItem + ".3", selectedItem + " punto Tres."));
> items.add(new SelectItem(selectedItem + ".4", selectedItem + " punto Cuatro."));
>
> return items;
> }
>
> public String getSelectedItem() {
> return selectedItem;
> }
>
> public void setSelectedItem(String selectedItem) {
> this.selectedItem = selectedItem;
> }
>
> public String getSelectedSubItem() {
> return selectedSubItem;
> }
>
> public void setSelectedSubItem(String selectedSubItem) {
> this.selectedSubItem = selectedSubItem;
> }
>
> }
>
> JSF:
> <?xml version='1.0' encoding='UTF-8' ?>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml"
> xmlns:h="http://java.sun.com/jsf/html"
> xmlns:f="http://java.sun.com/jsf/core" >
> <h:head>
> <title>Facelet Title</title>
> </h:head>
> <h:body>
> <h:form id="testForm">
> <h:selectOneListbox value="#{testManager.selectedItem}">
> <f:ajax event="change" render="testForm:suitems"/>
> <f:selectItems value="#{testManager.items}" />
> </h:selectOneListbox>
> <h:selectOneListbox value="#{testManager.selectedSubItem}" id="suitems" rendered="#{ ! empty testManager.selectedItem}">
> <f:selectItems value="#{testManager.subItems}" />
> </h:selectOneListbox>
> </h:form>
> </h:body>
> </html>
> [Message sent by forum member 'angelcervera' (angelcervera_at_silyan.com)]
>
> http://forums.java.net/jive/thread.jspa?messageID=383728
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: webtier-help_at_glassfish.dev.java.net
>