私はこのメニューを持っています:
<h:selectOneMenu value="#{ApplicationController.settings['SessionTTL']}">
<f:selectItem itemValue="60" itemLabel="1 hour" />
<f:selectItem itemValue="30" itemLabel="30 Minutes" />
<f:selectItem itemValue="20" itemLabel="20 Minutes" />
<f:selectItem itemValue="10" itemLabel="10 Minutes" />
<f:selectItem itemValue="custom" itemLabel="Define custom value" />
<f:ajax render="input" />
</h:selectOneMenu>
<h:panelGroup id="input">
<h:inputText value="#{ApplicationController.settings['SessionTTL']}" rendered="#{ApplicationController.settings['SessionTTL'] == 'custom'}" required="true" />
</h:panelGroup>
問題は、メニュー ラベルに値が表示されないことです。カスタムをクリックして更新すると、常に1 hour
. この方法でメニューを変更すると:
<h:selectOneMenu value="#{ApplicationController.settings['SessionTTL']}">
<f:selectItem itemValue="#{ApplicationController.settings['SessionTTL']}" itemLabel="#{ApplicationController.settings['SessionTTL']}" />
<f:selectItem itemValue="60" itemLabel="1 hour" />
<f:selectItem itemValue="30" itemLabel="30 Minutes" />
<f:selectItem itemValue="20" itemLabel="20 Minutes" />
<f:selectItem itemValue="10" itemLabel="10 Minutes" />
<f:selectItem itemValue="custom" itemLabel="Define custom value" />
<f:ajax render="input" />
</h:selectOneMenu>
<h:panelGroup id="input">
<h:inputText value="#{ApplicationController.settings['SessionTTL']}" rendered="#{ApplicationController.settings['SessionTTL'] == 'custom'}" required="true" />
</h:panelGroup>
私は常に最初の値を menu label に入れます。カスタム値をメニュー ラベルに表示できない理由がわかりましたか?
PSこれは完全なソースコードです:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
<ui:insert name="header">
<ui:include src="header.xhtml"/>
</ui:insert>
</h:head>
<h:body>
<h1><img src="resources/css/images/icon.png" alt="DX-57" /> Settings Center</h1>
<!-- layer for black background of the buttons -->
<div id="toolbar" style="margin: 0 auto; width:1180px; height:30px; position:relative; background-color:black">
<!-- Include page Navigation -->
<ui:insert name="Navigation">
<ui:include src="Navigation.xhtml"/>
</ui:insert>
</div>
<div id="logodiv" style="position:relative; top:35px; left:0px;">
<h:graphicImage alt="General Settings" style="position:relative; top:-20px; left:9px;" value="resources/images/logo_general_settings.png" />
</div>
<div id="main" style="margin: 0 auto; width:1190px; height:700px; position:absolute; background-color:transparent; top:105px">
<div id="mainpage" style="margin: 0 auto; width:1190px; height:500px; position:absolute; background-color:transparent; top:80px">
<h:form id="settingsupdate">
<p:growl id="growl" showDetail="true" sticky="true" />
<div id="settingsdivone" style="width:550px; height:400px; position:absolute; background-color:r; top:20px; left:1px">
<h:panelGrid columns="2">
<h:panelGroup>Application Timestamp Format</h:panelGroup>
<h:panelGroup>
<h:selectOneMenu value="#{GeneralController.settings['TimestampFormat']}">
<f:selectItem itemValue="#{GeneralController.settings['TimestampFormat']}" itemLabel="#{GeneralController.settings['TimestampFormat']}" />
<f:selectItem itemValue="yyyy-MM-dd-HH.mm.ss.ffffff" itemLabel="yyyy-MM-dd-HH.mm.ss.ffffff" />
<f:selectItem itemValue="YYYY-MM-DD HH:MM:SS" itemLabel="YYYY-MM-DD HH:MM:SS" />
<f:selectItem itemValue="YYYY-MM-DDThh:mm:ss.sTZD" itemLabel="YYYY-MM-DDThh:mm:ss.sTZD" />
<f:selectItem itemValue="custom" itemLabel="Define custom value" />
<f:ajax render="timestampformat" />
</h:selectOneMenu>
<h:panelGroup id="timestampformat">
<h:inputText value="#{GeneralController.settings['TimestampFormat']}" rendered="#{GeneralController.settings['TimestampFormat'] == 'custom'}" required="true" />
</h:panelGroup>
</h:panelGroup>
<h:panelGroup>Performance Tuning</h:panelGroup>
<h:panelGroup>
<h:selectOneMenu value="#{GeneralController.settings['PerformTunung']}">
<f:selectItem itemValue="#{GeneralController.settings['PerformTunung']}" itemLabel="#{GeneralController.settings['PerformTunung']}" />
<f:selectItem itemValue="10000" itemLabel="Less than 10000 table rows" />
<f:selectItem itemValue="1000000" itemLabel="More than 1000000 table rows" />
<f:selectItem itemValue="custom" itemLabel="Define custom value" />
<f:ajax render="performtuning" />
</h:selectOneMenu>
<h:panelGroup id="performtuning">
<h:inputText value="#{GeneralController.settings['PerformTunung']}" rendered="#{GeneralController.settings['PerformTunung'] == 'custom'}" required="true" />
</h:panelGroup>
</h:panelGroup>
<h:panelGroup>Application Initialization State</h:panelGroup>
<h:panelGroup>
<h:selectOneMenu value="#{GeneralController.settings['InitState']}">
<f:selectItem itemValue="#{GeneralController.settings['InitState']}" itemLabel="#{GeneralController.settings['InitState']}" />
<f:selectItem itemValue="1" itemLabel="Level 1" />
<f:selectItem itemValue="2" itemLabel="Level 2" />
<f:selectItem itemValue="3" itemLabel="Level 3" />
<f:selectItem itemValue="custom" itemLabel="Define custom value" />
<f:ajax render="initstate" />
</h:selectOneMenu>
<h:panelGroup id="initstate">
<h:inputText value="#{GeneralController.settings['InitState']}" rendered="#{GeneralController.settings['InitState'] == 'custom'}" required="true" />
</h:panelGroup>
</h:panelGroup>
</h:panelGrid>
</div>
<div id="settingsonedivtwo" style="width:350px; height:400px; position:absolute; background-color:transparent; top:20px; left:400px">
</div>
<div id="settingstwodivthree" style="width:150px; height:60px; position:absolute; background-color:transparent; top:380px; left:800px">
<p:commandButton value="Save Settings" id="ajax" actionListener="#{GeneralController.updateDBSettings}" rendered="true" update="growl,settingsupdate"/>
</div>
</h:form>
</div>
</div>
</h:body>
</html>