0

我已经集成:

                <p:selectOneMenu value="#{orderListBean.currentItem.displayType}"
                        effect="fade" required="true">
                        <f:selectItem itemLabel="Select Item" itemValue="" />
                        <f:selectItem itemLabel="test1" itemValue="1" />
                        <f:selectItem itemLabel="test" itemValue="1" />
                    </p:selectOneMenu>
                    <h:form>
                    .....
                    </h:form>

我有一个form我的代码。test1如果我的 OneList 菜单上的项目被选中,我只想显示表单。请给我一个关于如何实现这个的提示?

更新

我的后端代码:

@Component
@Scope("session")
public class OrderListBean implements Serializable {  

    /**
     * UUID
     */
    private static final long serialVersionUID = -1780048479982517846L;

    /**
     * log4j
     */
    private static Logger log = LogManager.getLogger(OrderListBean.class);

    /**
     * items list
     */
    private List<TemplateItems> itemList;  

    /**
     * the Name of our Product Specialization form
     */
    private String formName;

    /**
     * the current Item
     */
    private TemplateItems currentItem;

    /**
     * Template Service
     */
    private ITemplateService tempService;

    /**
     * our current Template
     */
    private Template currentTemplate;

    /**
     * key: valueType
     * value: displayType
     */
    private static final Map<Integer, Integer>  displayItemValueMap;

    /**
     * maps our Template Items
     */
    static {
        displayItemValueMap = new HashMap<Integer, Integer>();
        //String Input Text
        displayItemValueMap.put(1, 1);
        //Drag and Drop
        displayItemValueMap.put(2, 1);
        //Text Field
        displayItemValueMap.put(3, 1);
        //Color Picker
        displayItemValueMap.put(4, 1);
        //Date Picker
        displayItemValueMap.put(5, 4);
        //Integer Input Text
        displayItemValueMap.put(6, 2);
        //Double Input Text
        displayItemValueMap.put(7, 3);
    }

    /**
     * Constructor
     */
    public OrderListBean() {  
        currentItem = new TemplateItems();
        tempService = new TemplateService();
        currentTemplate = new Template();
        formName  = "Untitled Form";
        //Strings  
        itemList = new ArrayList<TemplateItems>();
        //      itemList.add(currentItem);

    }

    /**
     * @return the item
     */
    public List<TemplateItems> getItem() {
        return itemList;
    }

    /**
     * @param item the item to set
     */
    public void setItem(List<TemplateItems> item) {
        this.itemList = item;
    }

    /**
     * adds a TemplateItem to our item List
     * @param item
     */
    public void addItem() {
        log.info("enter add item method...");
        this.itemList.add(currentItem);
        currentItem.setValueType(displayItemValueMap.get(currentItem.getDisplayType()));
        currentItem = new TemplateItems();

        log.info(currentItem.toString());
    }

    public void deleteItem(TemplateItems item) {

        if(item != null) {
            itemList.remove(item);
        }
    }

    /**
     * @return the currentItem
     */
    public TemplateItems getCurrentItem() {
        return currentItem;
    }

    /**
     * @param currentItem the currentItem to set
     */
    public void setCurrentItem(TemplateItems currentItem) {
        this.currentItem = currentItem;
    }

    /**
     * @return the itemList
     */
    public List<TemplateItems> getItemList() {
        return itemList;
    }

    /**
     * @param itemList the itemList to set
     */
    public void setItemList(List<TemplateItems> itemList) {
        this.itemList = itemList;
    }

    /**
     * @return the formName
     */
    public String getFormName() {
        return formName;
    }

    /**
     * @param formName the formName to set
     */
    public void setFormName(String formName) {
        this.formName = formName;
    }
4

1 回答 1

1

可能这可以帮助

<h:body>
    <h:form>
        <h:selectOneMenu valueChangeListener="#{test.valuChangeHandler}" onchange="submit()" immediate="true">
            <f:selectItems value="#{test.opList}"/>
        </h:selectOneMenu>
        <h:form id="group" rendered="#{test.visible}">
                <h:outputText value="SHOW FORMMMMMM"/>
        </h:form>
    </h:form>
</h:body>

和此测试的支持 Bean:

@ManagedBean

@ViewScoped public class Test implements Serializable {

private boolean visible = false;
private List<String> opList;

public Test() {

    opList = optionList();
}


public List<String> getOpList() {
    return opList;
}
public void setOpList(List<String> opList) {
    this.opList = opList;
}
public boolean isVisible() {
    return visible;
}
public void setVisible(boolean visible) {
    this.visible = visible;
}

public List<String> optionList(){

    List<String> list = new ArrayList<String>();
    list.add("Select Item");
    list.add("test1");
    list.add("test");
    return list;
}
public void valuChangeHandler(ValueChangeEvent changeEvent){

    if(changeEvent.getNewValue().toString().trim().equalsIgnoreCase("test1"))
        setVisible(true);
}

}

于 2013-06-05T13:25:09.797 回答