Java 将参数传递给函数JSF
大家好,我需要向actionListener传递一些参数这是我的代码Java 将参数传递给函数JSF,java,hibernate,jsf,Java,Hibernate,Jsf,大家好,我需要向actionListener传递一些参数这是我的代码 <p:dialog id="dialog" header="Acceso Restringido" widgetVar="dlgRegister" modal="true"> <h:form> <h:panelGrid columns="2" cellpadding="5"> <h:outputLabel for="username" value=
<p:dialog id="dialog" header="Acceso Restringido" widgetVar="dlgRegister" modal="true">
<h:form>
<h:panelGrid columns="2" cellpadding="5">
<h:outputLabel for="username" value="Nombre de Usuario:" />
<p:inputText value="#{loginBean.usuario.username}"
id="username" required="true" label="username" />
<h:outputLabel for="password" value="Contraseña:" />
<h:inputSecret value="#{loginBean.usuario.password}"
id="password" required="true" label="password" />
<h:outputLabel for="correo" value="Correo:" />
<h:inputSecret value="#{loginBean.usuario.correo}"
id="correo" required="true" label="correo" />
<f:facet name="footer">
<p:commandButton id="regButton" value="Registrar" update=":growl"
actionListener="#{loginBean.login(actionEvent)}"
oncomplete="handleLoginRequest(xhr, status, args)"/>
</f:facet>
</h:panelGrid>
</h:form>
我需要将svalue=“#{loginBean.usuario.username}”示例传递给actionListener=“#{loginBean.login(actionEvent,---HERE--)}”
{actionEvent}
。JSF已经为action listener方法准备了真正的ActionEvent
参数本身。省略一下:
actionListener="#{loginBean.login}"
JSF将隐式地创建并传递正确的参数
您可以直接在方法内部访问用户名:
public void login(ActionEvent event) {
System.out.println(usario.getUsername()); // Look, it's already been set by JSF.
}
另见:
public void login(ActionEvent event) {
System.out.println(usario.getUsername()); // Look, it's already been set by JSF.
}