sha4ky
sha4ky

Reputation: 178

selectOneMenu and textEntry in IceFaces

I have problem with IceFaces, i try change ace:textEntry depends on item selected on ice:selectOneMenu.

Also i don't need to go new page, i want it to be AJAX and reflesh everytime i change it. I try do it in that way:

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ice="http://www.icesoft.com/icefaces/component"
xmlns:ace="http://www.icefaces.org/icefaces/components"
xmlns:icecore="http://www.icefaces.org/icefaces/core">

<f:view>

        <ice:selectOneMenu partialSubmit="true" onchange="submit()"
            value="#{testBean.selectedItem}"
            valueChangeListener="#{testBean.selectionChanged}"
            immediate="true">

            <f:selectItems value="#{testBean.standardList}"
                var="itemValue" itemLabel="#{itemValue}"
                itemValue="#{itemValue}" />
        </ice:selectOneMenu>

        <ace:textEntry labelPosition="left" label="Output text: " id="output" value="#{testBean.outputItem}" >  
        <ace:ajax render="@this"/>
        </ace:textEntry>
</f:view>

And bean:

import java.util.Arrays;
import java.util.List;

import javax.faces.bean.CustomScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.event.ValueChangeEvent;
import javax.inject.Inject;

import org.slf4j.Logger;

@ManagedBean
@CustomScoped(value = "#{window}")
public class TestBean {

@Inject
private Logger logger;

private String selectedItem;
private String outputItem;

private List<String> standardList = Arrays.asList("Artur","Adam","Mirek");

public void selectionChanged(ValueChangeEvent e){
    this.outputItem = this.selectedItem;
    logger.info(this.outputItem);
}

public String getSelectedItem() {
    return selectedItem;
}

public void setSelectedItem(String selectedItem) {
    this.selectedItem = selectedItem;
}

public List<String> getStandardList() {
    return standardList;
}

public void setStandardList(List<String> standardList) {
    this.standardList = standardList;
}

public String getOutputItem() {
    return outputItem;
}

public void setOutputItem(String outputItem) {
    this.outputItem = outputItem;
}

But it won't work, any solutions? Big thx.

Upvotes: 0

Views: 2841

Answers (1)

Simon Arsenault
Simon Arsenault

Reputation: 1845

First, your ace:ajax is not at the right place. It should be under ice:selectOneMenu.

Second, I suggest that, instead of using the ice:selectOneMenu, you use h:selectOneMenu. I learned with time that everything works better when you don't use anything from ice. A mix of h and ace works very well.

I created a sample project like yours and I was able to make it work like this:

<h:form>
    <h:selectOneMenu value="#{Bean.valueOutput}">
        <f:selectItems value="#{Bean.values}" />
        <f:ajax event="change" render="output"/>
    </h:selectOneMenu>

    <ace:textEntry labelPosition="left" label="Output text: " id="output" value="#{Bean.valueOutput}" />
</h:form>

Nothing special in the Bean.java, only the normal declarations and get/set.

Tested with ICEfaces 3.2 and JSF 2.1.6.

Upvotes: 3

Related Questions