gpt4 book ai didi

java - 选择下拉菜单项时显示 `form`?

转载 作者:行者123 更新时间:2023-12-01 14:29:51 25 4
gpt4 key购买 nike

我已经集成了:

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

我的代码下有一个表单。我只想在选择 OneList 菜单上的项目 test1 时显示表单。请给我一个关于如何实现这个的提示?

更新

我的后端代码:

@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;
}

最佳答案

也许这可以帮助

<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)类测试实现可序列化{

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);
}

}

关于java - 选择下拉菜单项时显示 `form`?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16939604/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com