Skip to main content

JSF 2.0 combo dependencies.

3 replies [Last post]
angelcervera
Offline
Joined: 2003-12-03

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 getItems() {
List items = new ArrayList();

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 getSubItems() {

List items = new ArrayList();

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' ?>

Facelet Title

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Imre Osswald

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@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 getItems() {
> List items = new ArrayList();
>
> 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 getSubItems() {
>
> List items = new ArrayList();
>
> 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:
>
>
> > xmlns:h="http://java.sun.com/jsf/html"
> xmlns:f="http://java.sun.com/jsf/core" >
>
> Facelet Title
>

>
>
>
>
>
>

>
>
>

>

>

>
> [Message sent by forum member 'angelcervera' (angelcervera@silyan.com)]
>
> http://forums.java.net/jive/thread.jspa?messageID=383728
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: webtier-help@glassfish.dev.java.net
>

[smime.p7s]

angelcervera
Offline
Joined: 2003-12-03

Thank for your help.
If wrap combo inside panelGorup:

....

Using this snip code, result is same first example because div is not rendered too.

My solution has been use "disabled" attribute instead of "rendered" and css:

......

......

Imre Osswald

Hi,

the idea was to have always rendered="true" (or omitting rendered) on the panelGroup (and rendered="#{! empty ...}" on the selection only.
This allows ajax to find the id (of the panelGroup) and to insert the html-code for the select into it.
It is important for the id of the part of the page that you want to have rerendered to actually be existent in the html when submitting the partial request, as without it ajax would have no way (at least not an easy/clean way) to know where to put the changed content.

Your solution is ok, as long as it is ok for you to have the selectOneListbox still submitted, validated, etc (as display:none will not prevent it to be part of the form-data)

Imre

Am 01.02.2010 um 19:14 schrieb webtier@javadesktop.org:

> Thank for your help.
> If wrap combo inside panelGorup:
>
> ....
>

> Using this snip code, result is same first example because div is not rendered too.
>
> My solution has been use "disabled" attribute instead of "rendered" and css:
>

> ......
>
> ......
> [Message sent by forum member 'angelcervera' (angelcervera@silyan.com)]
>
> http://forums.java.net/jive/thread.jspa?messageID=384099
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: webtier-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: webtier-help@glassfish.dev.java.net
>

[smime.p7s]