Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 多个ice:SelectOne功能表选择_Java_Jsf_Datatable_Selectonemenu - Fatal编程技术网

Java 多个ice:SelectOne功能表选择

Java 多个ice:SelectOne功能表选择,java,jsf,datatable,selectonemenu,Java,Jsf,Datatable,Selectonemenu,我想知道如何在ice:selectOneMenu中实现多重选择。我有一个玩具列表,它是在启动支持bean时加载的,在UI中我有一个玩具表,其中每行玩具都有一列selectOneMenu,即玩具功能。我的问题是在每一排玩具中显示选定的玩具功能。到目前为止,我能够用下面的代码在SelectOne菜单中显示所选函数,但我不知道如何在不同的行上实现不同的选择,我的意思是我只有一个属性“selectedToyFunction”,它映射到每一行。我需要实现类似java.util.Map的东西。但我不知道如何

我想知道如何在ice:selectOneMenu中实现多重选择。我有一个玩具列表,它是在启动支持bean时加载的,在UI中我有一个玩具表,其中每行玩具都有一列selectOneMenu,即玩具功能。我的问题是在每一排玩具中显示选定的玩具功能。到目前为止,我能够用下面的代码在SelectOne菜单中显示所选函数,但我不知道如何在不同的行上实现不同的选择,我的意思是我只有一个属性“selectedToyFunction”,它映射到每一行。我需要实现类似
java.util.Map
的东西。但我不知道如何以及在哪里处理这样的实施

JSPX

<ice:dataTable border="0" value="#{myBean.toys}" var="toy" scrollable="false"   resizable="false">
    <ice:column id="toyDetailRedirect" styleClass="smallColumn">
        <ice:selectOneMenu styleClass="inputCombo" partialSubmit="true" valueChangeListener="#{myBean.redirectToToyFunctionDetail}" value="#{myBean.selectedToyFunction}">
            <f:attribute name="toy" value="#{toy.id}" />
            <f:selectItems value="#{myBean.toyFunctions}" />
        </ice:selectOneMenu>
        <f:facet name="header">
            <ice:outputText value="Details" />
        </f:facet>
    </ice:column>
<ice:dataTable>

BackingBean

public class MyBean 
{    
    //--- Services ---
    private ToyService toyService;       

    //---- UI -----
    private String selectedToyFunction;
    private List<SelectItem> toyFunctions = new ArrayList<SelectItem>();

    //--- properties
    private List<Toy> toys = new ArrayList<Toy>();
    private static final String DEFAULT_SELECTION ="--- Select ---";
    private static final String FUNCTION_A ="A";
    private static final String FUNCTION_B ="B";
    private static final String FUNCTION_C ="C";

    // ---- Logging ----
    private final Logger logger = Logger.getLogger(MyBean.class);


    public MyBean()
    {
        super();
    }

    @PostConstruct
    public void loadToysAndPopulateToysFunctions( )
    {    
        // loadToys
        try
        {
            this.toys = this.toysService.findAllToys();
        }
        catch (Exception e)
        {
            this.logger.warn(e.getMessage());
            this.logger.debug(e);
        }

        if ((this.toys == null) || this.toys.isEmpty())
        {
            /* Out if not toy has been found */
            logger.debug("No Toy has been found !");
            return;
        }
        // Populate default toy  functions
        this.populateToyFunctions();
    }    

    private void populateToyFunctions( )
    {    
        if ((this.toyFunctions == null) || this.toyFunctions.isEmpty())
        {
            this.toyFunctions = new ArrayList<SelectItem>();
            this.toyFunctions.add(new SelectItem(DEFAULT_SELECTION));
            this.toyFunctions.add(new SelectItem(FUNCTION_A));
            this.toyFunctions.add(new SelectItem(FUNCTION_B));
            this.toyFunctions.add(new SelectItem(FUNCTION_C));             
        }
        //Default selection
        this.selectedToyFunction = DEFAULT_SELECTION;    
    }

    public void redirectToToyFunctionDetail(ValueChangeEvent e)
    {
        FacesContext.getCurrentInstance()
                            .getExternalContext()
                            .redirect("/Store/Details.jspx?id=" +e.getNewValue().toString());    
    }

     // ---- Getters & Setters -----

    public List<Toy> getToys( )
    {
        return this.toys;
    }

    public void setToys(List<Toy> toys)
    {
        this.toys = toys;
    }    

    public List<SelectItem> getToyFunctions( )
    {

      return this.toyFunctions;
    }

    public void setToyFunctions(List<SelectItem> toyFunctions)
    {
        this.toyFunctions = toyFunctions;
    }

    public void setSelectedToyFunction(String selectedToyFunction)
    {
        this.selectedToyFunction = selectedToyFunction;
    }

    public String getSelectedToyFunction()
    {
        return this.selectedToyFunction;
    }    
}
公共类MyBean
{    
//---服务---
私人玩具服务;
//----用户界面-----
私有字符串selectedToyFunction;
private List toyFunctions=new ArrayList();
//---性质
私有列表玩具=新的ArrayList();
私有静态最终字符串默认_SELECTION=“---选择---”;
私有静态最终字符串函数_A=“A”;
私有静态最终字符串函数_B=“B”;
私有静态最终字符串函数\u C=“C”;
//----记录----
私有最终记录器=Logger.getLogger(MyBean.class);
公共MyBean()
{
超级();
}
@施工后
公共void loadToysAndPopulateToysFunctions()
{    
//装载玩具
尝试
{
this.toys=this.toysService.findAllToys();
}
捕获(例外e)
{
this.logger.warn(e.getMessage());
this.logger.debug(e);
}
if((this.toys==null)| | this.toys.isEmpty())
{
/*如果没有找到玩具,我们就出去*/
调试(“没有找到玩具!”);
返回;
}
//填充默认的玩具函数
this.populateToyFunctions();
}    
私有void populateToyFunctions()
{    
if((this.toyFunctions==null)| | this.toyFunctions.isEmpty())
{
this.toyFunctions=newArrayList();
this.toyFunctions.add(新选择项(默认选择));
this.toyFunctions.add(新的SelectItem(FUNCTION_A));
this.toyFunctions.add(新的SelectItem(FUNCTION_B));
this.toyFunctions.add(新的SelectItem(FUNCTION_C));
}
//默认选择
this.selectedToyFunction=默认\u选择;
}
public void redirectToToyFunctionDetail(ValueChangeEvent e)
{
FacesContext.getCurrentInstance()
.getExternalContext()
.redirect(“/Store/Details.jspx?id=“+e.getNewValue().toString());
}
//----getter和setter-----
公共列表getToys()
{
归还这个玩具;
}
公众玩具(列出玩具)
{
这个玩具=玩具;
}    
公共列表getToyFunctions()
{
返回this.toyFunctions;
}
公共void setToyFunctions(列出toyFunctions)
{
this.toyFunctions=toyFunctions;
}
公共void setSelectedToyFunction(字符串selectedToyFunction)
{
this.selectedToyFunction=selectedToyFunction;
}
公共字符串getSelectedToyFunction()
{
返回此.selectedToyFunction;
}    
}
您有两个选项:

  • 只需将值绑定到当前迭代的
    Toy
    对象:

    
    
    并为
    玩具
    类提供适当的属性(如果尚未完成):

    private String function;
    
    这是自然的做法

  • 按照您的建议,将该值绑定到公共
    Map
    bean属性:

    
    
    确保您事先准备好了
    HashMap

    private Map<Long, String> selectedToyFunctions = new HashMap<Long, String>();
    
    私有映射selectedToyFunctions=new HashMap();
    
    这只是一种丑陋的做法。在准备/持久化之前,您可能需要手动将所有更改从真实的
    Toy
    对象复制/移动到其中


  • 谢谢,第二个选择就是我要找的线索。