我想在primefaces对话框中将localstorage值中的值设置为outputtext组件。 对话框是
<p:commandButton id="clickBtn" value="Click to display the Dialog"/>
<p:dialog id="eventDetailDialog" widgetVar="eventDialog"
header="Service Details>
<div>
<h:form id="topForm" prependId="false">
<h:panelGrid id="eventDetails1">
<h:outputText value="Assigned Employee "/>
<h:outputLabel value=":"/>
<h:outputText id="assignedEmpId" value="#{myBean.employee}">
</h:outputText>
</h:panelGrid>
</h:form>
</div>
</p:dialog>
生成的html是
<td class="labelClass">Assigned Employee </td>
<td class="colnClass"><label>:</label></td>
<td class="valueClass"><span id="assignedEmpId"></span></td>
点击按钮
document.getElementById('assignedEmpId').innerHtml = localStorage.myDataEmp;
eventDialog.show();
但是locastorage的值没有设置为组件。 如何将localStorage值设置为jsf / primefaces组件? 使用jsf 2.1和primefaces 4.0。
也在w3schools做过样本
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>
<input type="button" id="clickBtn" value="Click Here"/>
Assigned Employee
<span id="assignedEmpId"></span>
<script>
localStorage.setItem("lastname", "Smith");
$(document).ready(function() {
$("#clickBtn").click(function(){
document.getElementById("assignedEmpId").innerHTML = localStorage.lastname;
});
});
</script>
</body>
</html>
但同样没有使用JSF。为什么呢?
答案 0 :(得分:0)
得到了答案。 :)
变化
document.getElementById('assignedEmpId').innerHtml = localStorage.myDataEmp;
到
document.getElementById('assignedEmpId').innerHTML = localStorage.myDataEmp;
答案 1 :(得分:-2)
<p:commandButton value="Click to display the Dialog"
oncomplete="PF('eventDialog').show()"
update="eventDetailDialog" />