Jsf f:setPropertyActionListener仅在视图中工作,而不在支持bean中工作
我试图在Jsf f:setPropertyActionListener仅在视图中工作,而不在支持bean中工作,jsf,primefaces,Jsf,Primefaces,我试图在中获取有关单击按钮的信息,但它不起作用 我的看法是: <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://p
中获取有关单击按钮的信息,但它不起作用
我的看法是:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui" template="/WEB-INF/template.xhtml">
<ui:define name="head">
<title>Hash Generator</title>
</ui:define>
<ui:define name="content">
<h:form id="hashForm">
<p:dataList id="hashList" value="#{hashGeneratorBean.hashList}" var="entry" rowIndexVar="idx" itemType="none">
<p:column>
<h:outputText value="#{idx + 1}" />
<h:inputText value="#{entry.clearText}" />
<h:inputText value="#{entry.hashedText}" readonly="true" disabled="true" size="#{entry.hashedText.length() + 15}"/>
<p:commandButton id="addRow" actionListener="#{hashGeneratorBean.addRow}" icon="ui-icon-plus" title="Icon Only" update="hashList">
<f:setPropertyActionListener value="#{entry}" target="#{hashGeneratorBean.selectedRow}" />
</p:commandButton>
<p:commandButton id="debugBtn" icon="ui-icon-disc" title="Icon Only" update=":hashForm:display" oncomplete="PF('dlg').show()">
<f:setPropertyActionListener value="#{entry}" target="#{hashGeneratorBean.selectedRow}" />
</p:commandButton>
</p:column>
</p:dataList>
<p:commandButton actionListener="#{hashGeneratorBean.hash}" value="Generate Hashes" update="hashList" />
<p:dialog modal="true" widgetVar="dlg">
<h:panelGrid id="display" columns="2">
<f:facet name="header">
<h:outputText value="#{hashGeneratorBean.selectedRow.clearText}" />
</f:facet>
<h:outputText value="#{hashGeneratorBean.selectedRow.hashedText}" />
</h:panelGrid>
</p:dialog>
</h:form>
</ui:define>
</ui:composition>
散列生成器
我的控制器:
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.event.ActionEvent;
import com.google.common.base.Charsets;
import com.google.common.hash.Hashing;
@ManagedBean
@ViewScoped
public class HashGeneratorBean {
private List<HashDTO> hashList = new ArrayList<HashDTO>();
private HashDTO selectedRow = new HashDTO();
@PostConstruct
public void init() {
hashList.add(new HashDTO());
}
public void addRow(ActionEvent ae){
hashList.add(new HashDTO());
}
public void hash(ActionEvent ae){
for (HashDTO entry : hashList){
entry.setHashedText(generateHash(entry.getClearText()));
}
}
/**
* Hashes the given password with SHA-256
* @param password
* @return passwordHash
*/
public static String generateHash(String password) {
return Hashing.sha256().hashString(password, Charsets.UTF_8).toString();
}
public List<HashDTO> getHashList() {
return hashList;
}
public void setHashList(List<HashDTO> hashList) {
this.hashList = hashList;
}"
public HashDTO getSelectedRow() {
return selectedRow;
}
public void setSelectedRow(HashDTO selectedRow) {
this.selectedRow = selectedRow;
}
}
import java.util.ArrayList;
导入java.util.List;
导入javax.annotation.PostConstruct;
导入javax.faces.bean.ManagedBean;
导入javax.faces.bean.ViewScoped;
导入javax.faces.event.ActionEvent;
导入com.google.common.base.charset;
导入com.google.common.hash.Hashing;
@ManagedBean
@视域
公共类HashGeneratorBean{
私有列表hashList=newarraylist();
private HashDTO selectedRow=new HashDTO();
@施工后
公共void init(){
add(新的HashDTO());
}
公共无效添加行(ActionEvent ae){
add(新的HashDTO());
}
公共无效哈希(ActionEvent ae){
for(HashDTO条目:hashList){
setHashedText(generateHash(entry.getClearText());
}
}
/**
*使用SHA-256散列给定密码
*@param密码
*@returnpasswordhash
*/
公共静态字符串生成器哈希(字符串密码){
返回Hashing.sha256().hashString(密码,Charsets.UTF_8).toString();
}
公共列表getHashList(){
返回哈希表;
}
公共void setHashList(列表hashList){
this.hashList=hashList;
}"
公共哈希到getSelectedRow(){
返回selectedRow;
}
公共无效设置selectedRow(哈希到selectedRow){
this.selectedRow=selectedRow;
}
}
如果单击“debugBtn”按钮,将弹出对话框并显示有关该行的正确信息。但是如果单击“addRow”按钮,则托管bean中的数据填充不正确。selectedRow属性始终存储hashList属性中最后添加的行。我找到了解决方案
在ActionListener之后调用PropertyActionListener
解决办法是使用“行动”“或者将ActionListener注册到,一个扩展的ActionListener删除了我的答案,因为我误解了这个问题。你能更详细地解释什么不起作用吗?正在发生什么,以及您希望发生什么?我需要用户单击按钮的行的信息,以便在用户单击的行的正下方添加一行。我的期望是应该填充propertyActionListener所指向的属性。