JSF Required="true" umgehen

Templarthelast

Bekanntes Mitglied
Hallo, ich habe hier ein Einloggformular, das halt
Java:
required="true"
ist. Allerdings würde ich gerne über den Link auf eine andere Seite zugreifen, obwohl in den Feldern nichts steht.

index.xhtml:
Java:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets">

<h:body>
	<ui:composition template="master.xhtml">
		<ui:define name="top">

			<div id="header_logo">Votenetwork</div>
			<div id="login">
				<h:form>
					<table>
						<tr>
							<td>
								<p>Email:</p> <h:message for="login_id"
									id="login_info_required1" /> <h:inputText required="true"
									value="#{vPM.email}" requiredMessage="Email required"
									id="login_id" />
							</td>
							<td>
								<p>Password:</p> <h:message for="login_pw"
									id="login_info_required2" /> <h:inputText required="true"
									value="#{vPM.pw}" requiredMessage="Password required"
									id="login_pw" />
							</td>
						</tr>
						<tr>
							<td><h:commandButton value="login" action="#{vPM.login}" />
							</td>

							<td>Not a Member yet? <h:commandLink
									styleClass="register_link" value="Register"
									action="registration" />
							</td>
						</tr>
					</table>
				</h:form>
			</div>
		</ui:define>

		<ui:define name="leftbar"></ui:define>

		<ui:define name="content">
                Welcome
            </ui:define>
	</ui:composition>

</h:body>
</html>
 

Templarthelast

Bekanntes Mitglied
Eine Idee von mir wäre, dass man das
Java:
required="true"
per javascript und CDI mit "onlick="lPM.register" auf
Java:
required="false"
. Das funktioniert allerdings nicht so richtig.


loginPM.java
Java:
package com.javaee6.votinator;

import java.io.Serializable;

import javax.enterprise.context.RequestScoped;
import javax.inject.Named;

@Named("lPM")
@RequestScoped
public class LoginPM implements Serializable {

	private boolean emailReq = true;
	private boolean pwReq = true;

	public void register() {
		this.emailReq = false;
		this.pwReq = false;
	}

	public boolean isEmailReq() {
		return emailReq;
	}

	public void setEmailReq(boolean emailReq) {
		this.emailReq = emailReq;
	}

	public boolean isPwReq() {
		return pwReq;
	}

	public void setPwReq(boolean pwReq) {
		this.pwReq = pwReq;
	}

}

index.xhtml
Java:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets">

<h:body>
	<ui:composition template="master.xhtml">
		<ui:define name="top">

			<div id="header_logo">Votenetwork</div>
			<div id="login">
				<h:form>
					<table>
						<tr>
							<td>
								<p>Email:</p> <h:message for="login_id"
									id="login_info_required1" /> <h:inputText required="#{lPM.emailReq}"
									value="#{vPM.email}" requiredMessage="Email required"
									id="login_id" />
							</td>
							<td>
								<p>Password:</p> <h:message for="login_pw"
									id="login_info_required2" /> <h:inputText required="#{lPM.pwReq}"
									value="#{vPM.pw}" requiredMessage="Password required"
									id="login_pw" />
							</td>
						</tr>
						<tr>
							<td><h:commandButton value="login" action="#{vPM.login}" />
							</td>

							<td>Not a Member yet? <h:commandLink
									styleClass="register_link" value="Register"
									action="registration" onclick="#{lPM.register}"/>
							</td>
						</tr>
					</table>
				</h:form>
			</div>
		</ui:define>

		<ui:define name="leftbar"></ui:define>

		<ui:define name="content">
                Welcome
            </ui:define>
	</ui:composition>

</h:body>
</html>
 

Neue Themen


Oben