【发布时间】:2013-05-14 04:43:36
【问题描述】:
在两个 JSF 视图 xhtml 之间(都具有视图范围的支持 bean)如果用户单击链接或按钮,我想传递参数。如果我有一个带有 JavaScript 函数的属性 onclick 来打开另一个页面(在此页面中,我想使用第一页中设置的参数)到 commandButton 或 commandLink 我得到 f:param 属性为 \'currentAccess\':\'3\',\'gridNo\':\'5\', 并且如果我没有 onclick 属性我有它的权利'currentAccess':'3','gridNo':'5',
如果我有:
<h:commandButton action="#{statisticsBean.showAccessIncorectAnswers()}" target="_blank"
value="#{strings.whatHaveDoDoneWrong}" rendered="#{o.date != '-' and o.answerNoWrong != 0}">
<f:param name="currentAccess" value="#{o.currentAccess}"/>
<f:param name="gridNo" value="#{o.noGrid}"/>
<f:param name="gridCategory" value="#{o.category}"/>
</h:commandButton>
HTML 呈现如下:
<input type="submit" name="j_idt73:0:j_idt74:j_idt77" value="Ce ai gresit" onclick="mojarra.jsfcljs(document.getElementById('j_idt73:0:j_idt74'),{'j_idt73:0:j_idt74:j_idt77':'j_idt73:0:j_idt74:j_idt77','currentAccess':'1','gridNo':'5','gridCategory':'Drept Procesual Civil'},'');return false" />
这很好,我可以访问参数(f:viewpara或FacesContext,我使用最后一个likeFacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("currentAccess"))
但是 如果我有:
<h:commandButton action="#{statisticsBean.showAccessIncorectAnswers()}" target="_blank"
onclick="confirmGridStatistics('#{strings.doYouWantToSeeTheWrongAnswersInAccessNo} #{o.currentAccess} #{strings.fromDate} #{o.date}?');"
value="#{strings.whatHaveDoDoneWrong}" rendered="#{o.date != '-' and o.answerNoWrong != 0}">
<f:param name="currentAccess" value="#{o.currentAccess}"/>
<f:param name="gridNo" value="#{o.noGrid}"/>
<f:param name="gridCategory" value="#{o.category}"/>
</h:commandButton>
在 onclick 事件中有一个 JavaScript 函数,我得到了渲染:
<input type="submit" name="j_idt73:2:j_idt74:j_idt77" value="Ce ai gresit" onclick="jsf.util.chain(this,event,'confirmGridStatistics(\'Vrei sa vezi raspunsurile gresite in accessul 3 din data de 16-05-2013?\');','mojarra.jsfcljs(document.getElementById(\'j_idt73:2:j_idt74\'),{\'j_idt73:2:j_idt74:j_idt77\':\'j_idt73:2:j_idt74:j_idt77\',\'currentAccess\':\'3\',\'gridNo\':\'5\',\'gridCategory\':\'Drept Procesual Civil\'},\'\')');return false" />
在第二个视图支持 bean 中,我得到了来自 FacesContext 的参数的null。这是为什么呢?
更新 我以为
FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().put("currentAccess", access); 在 action 方法中可以解决它。但它没有,它给了我一个java.lang.UnsupportedOperationException
我不知道为什么会这样。
【问题讨论】:
标签: jsf-2 xhtml onclick html-rendering