我遇到了一些问题,因为我想在一些inputText字段中显示selectedIncident属性中的值存储,以便用户可以编辑当前值。我在其他问题中看到类似的东西,他们使用javascript,我尝试它对我不起作用。
我有一个手风琴面板,当我点击它打开的标签时,该事件的数据存储在selectedIncident中(这很好),在标签内我有一个按钮来编辑数据,当我点击它时打开一个对话框,标题和描述的字段为空。
<h:form id="idFormAllIncidents">
<p:accordionPanel id="panelDetailIncident" value="#{incidentBean.allIncidents}" var="incident" dynamic="true" activeIndex="-">
<p:ajax event="tabChange" listener="#{incidentBean.onTabChange}" immediate="true"/>
<p:tab title="#{incident.title}">
<h:outputText value="#{incident.description}"/>
<p:commandButton id ="editButton" value="Edit Incident" type="button" onclick="PF('dlg2').show();myFunction();"/>
<p:messages id="message" showDetail="true" autoUpdate="true" closable="true" />
</p:tab>
</p:accordionPanel>
<p:dialog id="editIncDialog" header="Edit Incident" widgetVar="dlg2" minHeight="40" >
<p:ajax event="close" listener="#{incidentBean.handleClose}" />
<h:form id="editInc">
<p:outputLabel value="Title:"/>
<h:inputText id="editTitle" value="#{incidentBean.title}" required="true" requiredMessage="Titulo necesarios"/>
<p:outputLabel value="Description: "/>
<p:inputTextarea id="editDescription" value="#{incidentBean.description}" rows="10" cols="50" counter="display" maxlength="200" counterTemplate="{0} caracteres restantes" autoResize="false" required="true" requiredMessage="Descripción necesaria"/>
<p:outputLabel id="display"/>
<p:commandButton value="Send Incident" action="#{incidentBean.editIncident()}" onclick="dlg1.hide()" />
<p:messages id="messages" for="title" showDetail="true" autoUpdate="true" closable="true" />
</h:form>
</p:dialog>
</h:form>
<script type="text/javascript">
function myFunction() {
document.getElementById("editTitle").defaultValue = "#{incidentBean.selectedIncident.title}";
document.getElementById("editDescription").defaultValue = "#{incidentBean.selectedIncident.description}";
}
</script>