I am using html tags and I have written some code on code behind but it is not picking the values given to id. Infact it says the 'FileUpload1' does not exist in the current context. I do not want to use asp controls at all. I have heard adding runat = "server" does the thing but still cannot find the id's. What am I doing wrong?
<div id="mainContent">
<div class="column" id="colFull">
<div class="contentSection">
<div id="progress" style="display: none">
<img alt="Loading .." src="../../../Images/ajax.gif" />
</div>
<table width="100%">
<tr>
<td class="label" style="width:15%">
Upload File
</td>
<td class="description" >
<input type="file" id="FileUpload1" runat="server"
class="largeTextField" onclick="Upload" multiple="multiple"
style="width:260px;"/>
<input type="button" id="btnUpload"
runat="server" value="Upload" />
</td>
</tr>
</table>
mycodebehind:
public partial class PgPracFileUploader : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Upload(object sender, EventArgs e)
{
string filename = Path.GetFileName(FileUpload1.PostedFile.FileName);
string contentType = FileUpload1.PostedFile.ContentType;
using (Stream fs = FileUpload1.PostedFile.InputStream)
{
using (BinaryReader br = new BinaryReader(fs))
{
byte[] bytes = br.ReadBytes((Int32)fs.Length);
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
string query = "insert into tblFiles values (#Name, #ContentType, #Data)";
using (SqlCommand cmd = new SqlCommand(query))
{
cmd.Connection = con;
cmd.Parameters.AddWithValue("#Name", filename);
cmd.Parameters.AddWithValue("#ContentType", contentType);
cmd.Parameters.AddWithValue("#Data", bytes);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
}
}
Response.Redirect(Request.Url.AbsoluteUri);
}
}
It says FileUpload1 does not exist in the current context.
Try to change:
<input type="file" id="FieUpload1" runat="server" class="largeTextField" onclick="Upload" multiple="multiple" style="width:260px;"/>
to
Id Must be same as you are using in the .cs page
\/\/\/\/
<input type="file" ID="FileUpload1" runat="server" class="largeTextField" onclick="Upload" multiple="multiple" style="width:260px;"/>
As stated here your id attribute is case sensitive so you are using id then the server will just serve it up as it is in your page, but if you used ID then the server will be serve that control as a asp.net control.
Related
Recently i am working on a web-form written in asp.net framework. I have kept in mind to include !IsPostBack() but yet my form is not accepting the responses and updating the database accordingly.
The body of the .aspx code which basically contains 4 RadioButtonList and one textbox. Here is the code for one of the RadioButtonList and the textBox, the submit button and and a link button:
<li class="form-line jf-required" data-type="control_scale" id="id_24">
<label class="form-label form-label-top form-label-auto" id="label_24" for="input_24">
Do you feel the training provided value for money/time?
<span class="form-required">*
</span>
</label>
<asp:RadioButtonList ID="RadioButtonList4" runat="server" AutoPostBack="True" CellPadding="10" CellSpacing="10" RepeatDirection="Horizontal" Font-Names="Comic Sans MS" Font-Size="Large" Height="50px">
<asp:ListItem Value="1" class="radiobuttonlist1">Worse</asp:ListItem>
<asp:ListItem Value="2" class="radiobuttonlist2">Boring</asp:ListItem>
<asp:ListItem Value="3" class="radiobuttonlist3">Satisfactory</asp:ListItem>
<asp:ListItem Value="4" class="radiobuttonlist4">good</asp:ListItem>
<asp:ListItem Value="5" class="radiobuttonlist5">Fantastic</asp:ListItem>
</asp:RadioButtonList>
</li>
<li id="cid_27" class="form-input-wide" data-type="control_head">
<div class="form-header-group header-default">
<div class="header-text httal htvam">
<h2 id="header_27" class="form-header" data-component="header">Final Thoughts?
</h2>
</div>
</div>
</li>
<li class="form-line" data-type="control_textarea" id="id_45">
<label class="form-label form-label-top form-label-auto" id="label_45" for="input_45">REMARKS / SUGGESTIONS</label>
<div id="cid_45" class="form-input-wide" data-layout="full">
<asp:TextBox ID="TextBox1" runat="server" style="width: 40px; height: 6px"></asp:TextBox>
</div>
</li>
<li id="cid_28" class="form-input-wide" data-type="control_head">
<div align="center">
<asp:Button ID="Button1" runat="server" Text="Submit" Text-align="center" CssClass="btn btn-primary" OnClick="Button1_Click" BackColor="#66FFCC" Height="40px" Width="80px" />
</div>
<div>
<asp:LinkButton ID="LinkButton1" runat="server" CssClass="btn btn-link" OnClick="LinkButton1_Click">Go back to Home Page</asp:LinkButton>
<br />
<br />
</div>
Here is the .aspx.cs of Page_Load:
public MySqlConnection mycon;
public MySqlCommand MyCm, cmd1;
public MySqlDataAdapter myad;
string userId;
protected void Page_Load(object sender, EventArgs e)
{
userId= Session["newFeedback"].ToString();
try
{
mycon = new MySqlConnection("server=localhost;database=feedbackform;user id=abcd;password=abcdabcd;");
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}
}
Here is the .aspx.cs code for Button_Click:
protected void Button1_Click(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Check_feedback_Exists())
{
Response.Write("<script>alert('You have already filled feedback form')</script>");
}
else
{
try
{
if (mycon.State == ConnectionState.Closed)
{
mycon.Open();
}
MySqlCommand cmd = new MySqlCommand("insert into feedback (Reference_Number, Feed1,Feed2,Feed3,Feed4,Remarks_Suggestion)values(userId, RadioButtonList1.SelectedItem.Text,RadioButtonList2.SelectedItem.Text,RadioButtonList3.SelectedItem.Text,RadioButtonList4.SelectedItem.Text,Textbox1.Text);", mycon);
cmd.ExecuteNonQuery();
mycon.Close();
Response.Write("<script> alert ('hello success'); </Script>");
}
catch (Exception ex)
{
Response.Write("<script> alert ('" + ex.Message + "'); </Script>");
}
}
}
}
Here is the code for the Check_feedback_exists:
bool Check_feedback_Exists()
{
try
{
if (mycon.State == ConnectionState.Closed) //checking that the connection between database and our project is open or not if not then open it
{
mycon.Open();
}
MySqlCommand cmd = new MySqlCommand("select * from feedback where Reference_Number = '" + userId + "' ; ", mycon);
MySqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
Response.Write("<script> alert ('" + ex.Message + "'); </script>");
return false;
}
}
The check_feedback_exists function is working well since if i submit for an already existing feedback, it gives the alert message: 'You have already filled feedback form' as coded in the Button1_click function. But if i enter a new feedback for a new user and click on submit, it doesn't enter the database, neither shows the success alert. Here is the database description in which I am inserting these values:
Makes no sense to check !IsPostBack in a button click. Such a button click will ALWAYS be a post-back. So, that's confusing.
And same goes for your sql insert. Your trying to insert the "text" of the control.
eg this:
string strSQL =
"insert into feedback (Reference_Number, Feed1, Feed2, Feed3, Feed4, Remarks_Suggestion) " +
"VALUES (#userId, #RB1,#RB2,#RB3,#RB4,#TBOX1"
SqlCommand cmd = new SqlCommand(strSQL, conn);
cmd.Parameters.Add("#usewrId", SqlDbType.Int).Value = userid;
cmd.Parameters.Add("#RB1", SqlDbType.NVarChar).Value = RadioButtonList1.SelectedItem.Text;
cmd.Parameters.Add("#RB2", SqlDbType.NVarChar).Value = RadioButtonList2.SelectedItem.Text;
etc. etc. etc.
Now, I used the sql provider, - it looks like your using MySQL. But, the sytnax should be simular to above. So, for your insert, you can't use a string of
string strSQL = "textBox1.Text, TextBox2.Text"
Since that string will have the above textbox names as string.
You would need
string strSQL = "VALUES ('" + TextBox1.Text + "','" + TextBox2.Text + "')"
But, the above is dangerous - due to sql injection. So use the above parameters approach.
And remove the !IsPostBack from your button stubb - not required, and a button click is ALWAYS a post-back anyway.
I am trying to pass an array of ints from my HTML back to my controller.
My flow is as follows:
I am retrieving data from an API and converting it to an Entity. All works fine.
However, I pass this to my HTML (Thymeleaf) and display some of the values to the User.
They then select one of the options and this is passed back to my Controller.
It is at this stage I lose the data I need.
In my Entity, I get the following data which I pass to the View (Example Below):
#Id
#GeneratedValue(strategy = GenerationType.IDENTITY)
#Column(name = "MOVIE_ID")
private long movieId;
#JsonProperty("title")
#Column(name = "TITLE")
private String title;
#JsonProperty("overview")
#Column(name = "OVERVIEW", length = 2000)
private String overview;
#JsonProperty("popularity")
#Column(name = "POPULARITY")
private float popularity;
#JsonProperty("release_date")
#Column(name = "RELEASE_DATE")
private String releaseDate;
#JsonProperty("genre_ids")
private int[] genreIds;
Then in my view, I display some values and hide the ids I dont need to display so that I can pass them back to my controller:
<form action = "#" th:action="#{/saveMovie}" method="post" th:object="${movie}">
<tr>
<td th:text="${movie.title}"></td>
<td th:text="${movie.releaseDate}"></td>
<td th:text="${movie.overview}"></td>
<input type="hidden" id="title" name="title" th:value="*{title}"/>
<input type="hidden" id="overview" name="overview" th:value="*{overview}"/>
<input type="hidden" id="popularity" name="popularity" th:value="*{popularity}"/>
<input type="hidden" id="releaseDate" name="releaseDate" th:value="*{releaseDate}"/>
<input type="hidden" id="genreIds" name="genreIds" th:value="*{genreIds}"/>
<td>
<div class="col-auto">
<button class="btn btn-primary" type="submit">Add</button>
</div>
</td>
</tr>
</form>
Controller to handle the call:
#PostMapping("/saveMovie") public String saveMovie(#ModelAttribute(value = "movie") Movie movie)
UPDATE***
Adding the GET/POST controllers that currently interact with this page:
#GetMapping("/searchMovie")
public String searchMovie(final Model model){
List<Movie> returnedMovies = new ArrayList<>();
model.addAttribute("movies", returnedMovies);
return "Search";
}
#PostMapping("/searchMovie")
public String searchMovieInTMDB(#RequestParam(value = "movieName", required = true) String movieName,
Model model){
List<Movie> returnedMovies = service.searchMovies(movieName);
model.addAttribute("movies", returnedMovies);
return "Search";
}
#PostMapping("/saveMovie")
public String saveMovie(#ModelAttribute(value = "movie") Movie movie){
service.storeMovie(movie);
return "WORK_IN_PROGRESS";
}
However, when I pass the values back to the controller I get the conversion error:
[Failed to convert property value of type 'java.lang.String' to required type 'int[]' for property 'genreIds']
I have changed it to String[] to test this works and error goes away but then I am presented with another problem in that it is converted to :
String Value Image
The only way I have found to pass the object back is by using the input tag and hiding them.
It converts the float fine, but can't handle the array of ints.
Is there a better way to pass objects back and forth between the controller using Thymeleaf or is there another attribute I can use to pass the array back and forth?
Thanks in advance
Conor
<form action="#" th:action="#{/saveMovie}" method="post"
th:object="${movie}">
<tr>
<td th:text="${movie.title}"></td>
<td th:text="${movie.releaseDate}"></td>
<td th:text="${movie.overview}"></td>
<input type="hidden" id="title" name="title" th:value="*{title}" />
<input type="hidden" id="overview" name="overview"
th:value="*{overview}" />
<input type="hidden" id="popularity" name="popularity"
th:value="*{popularity}" />
<input type="hidden" id="releaseDate" name="releaseDate"
th:value="*{releaseDate}" />
<input type="hidden" name="genreIds" th:field="*{genreIds}" />
<td>
<div class="col-auto">
<button class="btn btn-primary" type="submit">Add</button>
</div>
</td>
</tr>
</form>
#PostMapping("/saveMovie")
public String saveMovie(#ModelAttribute Movie movie) {
System.err.println(movie);
return "redirect:/movies";
}
#GetMapping("/movies")
public String getBooks(Model model) {
Movie movie = new Movie();
movie.setGenreIds(new int[] {4,5,6,7,8});
model.addAttribute("movie", movie);
return "movie";
}
Maybe You should send numbers as List to the controller.
#PostMapping("/saveMovie")
public String saveMovie(#RequestBody List<Movie> movies){
movieService.function_name(movies);
return "movies";
}
Another way to do this is using AJAX call to the controller. Just need to collect numbers as list in javascript and through ajax you should send array as json to controller. In controller you will parse them
I have a table with 3 columns.Last column has 4 radio buttons in each row.I am not able to fetch all the values of radio buttons checked after submitting the form.I always get only one value which is the value of radio button checked in the first row.
Here is the code of jsp page:
<form action = "SaveData" method = "POST" target = "_blank">
<h1>LIST</h1>
<%
try {
/* Create string of connection url within specified format with machine
name, port number and database name. Here machine name id localhost and
database name is student. */
String connectionURL = "jdbc:mysql://localhost:3306/sample";
// declare a connection by using Connection interface
Connection connection = null;
/* declare object of Statement interface that is used for executing sql
statements. */
Statement statement = null;
// declare a resultset that uses as a table for output data from tha table.
ResultSet rs = null;
// Load JBBC driver "com.mysql.jdbc.Driver"
Class.forName("com.mysql.jdbc.Driver").newInstance();
/* Create a connection by using getConnection() method that takes parameters
of string type connection url, user name and password to connect to database.*/
connection = DriverManager.getConnection(connectionURL, "root", "password");
/* createStatement() is used for create statement object that is used for
sending sql statements to the specified database. */
statement = connection.createStatement();
// sql query to retrieve values from the secified table.
String QueryString = "SELECT * from data";
rs = statement.executeQuery(QueryString);
%>
<table class="comparison-table">
<tr>
<th>LIST</th>
<th>Y/N</th>
<th>OPTIONS</th>
</tr>
<div>
<tr>
<%
while (rs.next()) {
String slist=rs.getString(1);
%>
<td name="list"><%= slist%></td>
<td>
<select id="choose" name="choose">
<option>Yes</option>
<option>No</option>
</select>
</td>
<td>
<form>
<input type="radio" name="option" value="a" checked> A
<input type="radio" name="option" value="b" >B
<input type="radio" name="option" value="c" > C
<input type="radio" name="option" value="d"> D
</form>
</td>
</tr>
</div>
<% } %>
<%
// close all the connections.
rs.close();
statement.close();
connection.close();
}
catch (Exception ex) {
%>
<%
out.println("Unable to connect to database."+ex);
}
%>
</table>
<button value="Submit" id="button">Submit</button>
</form>
Here is the Servlet code:
import javax.servlet.annotation.WebServlet;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
//Extend HttpServlet class
#WebServlet("/SaveData")
public class SaveData extends HttpServlet {
// Method to handle GET method request.
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// Set response content type
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String title = "Reading All Form Parameters";
String docType =
"<!doctype html public \"-//w3c//dtd html 4.0 " +
"transitional//en\">\n";
out.println(docType +
"<html>\n" +
"<head><title>" + title + "</title></head>\n" +
"<body bgcolor = \"#f0f0f0\">\n" +
"<h1 align = \"center\">" + title + "</h1>\n" +
"<table width = \"100%\" border = \"1\" align = \"center\">\n" +
"<tr bgcolor = \"#949494\">\n" +
"<th>Param Name</th>"+
"<th>Param Value(s)</th>\n"+
"</tr>\n"
);
Enumeration paramNames = request.getParameterNames();
while(paramNames.hasMoreElements()) {
String paramName = (String)paramNames.nextElement();
out.print("<tr><td>" + paramName + "</td>\n<td>");
String[] paramValues = request.getParameterValues(paramName);
// Read single valued data
if (paramValues.length == 1) {
String paramValue = paramValues[0];
if (paramValue.length() == 0)
out.println("<i>No Value</i>");
else
out.println(paramValue);
} else {
// Read multiple valued data
out.println("<ul>");
for(int i = 0; i < paramValues.length; i++) {
out.println("<li>" + paramValues[i]);
}
out.println("</ul>");
}
}
out.println("</tr>\n</table>\n</body></html>");
}
}
Output after submitting the form would be values of two parameters "choose" and "option". I get proper output for "choose" parameter ie. all the selected Yes/No options in a cloumn,whereas for "option" parameter i would get only the value of first row selected radio button ie if i select 'c' in the first row radio buttons only 'c' will be displayed with rest of the rows ignored.
Please help me out in fetching data of all the columns of the radio buttons selected in a String array.
I also want to fetch the value of "slist" which is from database using servlet. This is under td tag with name="list".
First you sould not nest form tag, remove the form tag before radio button.
From MDN web docs :
elements of type radio are generally used in radio
groups—collections of radio buttons describing a set of related
options. Only one radio button in a given group can be selected at the
same time.
You should add a variable to differentiate lines like this for example :
<tr>
<%! int lineNumber = 0 %>
<%
while (rs.next()) {
String slist=rs.getString(1);
%>
<td name="list"><%= slist%></td>
<td>
<select id="choose" name="choose">
<option>Yes</option>
<option>No</option>
</select>
</td>
<td>
<input type="radio" name="option<%= lineNumber %>" value="a" checked> A
<input type="radio" name="option<%= lineNumber %>" value="b" >B
<input type="radio" name="option<%= lineNumber %>" value="c" > C
<input type="radio" name="option<%= lineNumber %>" value="d"> D
</td>
</tr>
<% lineNumber++ %>
I am developing my first web application. I am trying to get the GPS location and save it for further processing. This is the code:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="CreatePlace.aspx.cs" Inherits="BeeMaster.CreatePlace" %>
<!DOCTYPE html>
<html style="background-image:url('images/background.png'); background-repeat:repeat-x">
<head runat="server">
<title>Create new Place</title>
<link href="CreatePlace.css" rel="stylesheet" type="text/css" />
<style type="text/css">
#taComment {
height: 142px;
width: 339px;
}
</style>
</head>
<body>
<img src="Images/CNP.png" id="logo"/>
<br />
<br />
<br />
<br />
<br />
<br />
<div>
<p id="Comment" style="font-size: large">Click the button to get your position.</p>
<button onclick="getLocation()" style="font-size: xx-large; width: 380px; height: 50px;">
Get current location
</button>
<br />
<asp:Label ID="lblCoordinates" runat="server"></asp:Label><asp:Label ID="lblLat" runat="server"></asp:Label>,<asp:Label ID="lblLon" runat="server"></asp:Label>
<br />
<iframe
height="600"
style="border:0"
id="iFrame">
</iframe>
</div>
<form runat="server">
<br style="font-size: x-large" />
<br style="font-size: x-large" />
<asp:Label ID="lblName" runat="server" Text="Name:" Font-Size="X-Large"></asp:Label>
<br style="font-size: x-large" />
<asp:TextBox ID="tbName" runat="server" Font-Size="X-Large"></asp:TextBox>
<br style="font-size: x-large" />
<asp:Label ID="lblNameComment" runat="server" Text="It is recommended to give a name for the place." Font-Size="Medium"></asp:Label>
<br style="font-size: x-large" />
<br style="font-size: x-large" />
<asp:Label ID="lblComment" runat="server" Text="Comment:" Font-Size="X-Large"></asp:Label>
<br style="font-size: x-large" />
<textarea id="taComment" ></textarea>
<br style="font-size: x-large" />
<asp:Label ID="lblCommentComment" runat="server" Text="Comment specific for the physical place" Font-Size="Medium"></asp:Label>
<br style="font-size: x-large" />
<br style="font-size: x-large" />
<asp:Button ID="btSaveLocation" runat="server" Text="Save current location as new place" OnClick="btSaveLocation_Click" Font-Size="XX-Large" Height="50px" />
</form>
<script hidden="hidden">
var x = document.getElementById("Comment");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition, showError);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
var latlon = position.coords.latitude + "," + position.coords.longitude;
document.getElementById("lblCoordinates").textContent += "Your location in Coordinates is: ";
document.getElementById("lblLat").innerHTML = position.coords.latitude;
document.getElementById("lblLon").innerHTML = position.coords.longitude;
document.getElementById("iFrame").src = "https://www.google.com/maps/embed/v1/place?key=<key>&q=" + latlon + "&maptype=satellite";
document.getElementById("iFrame").hidden = "";
}
function showError(error) {
switch (error.code) {
case error.PERMISSION_DENIED:
x.innerHTML = "User denied the request for Geolocation."
break;
case error.POSITION_UNAVAILABLE:
x.innerHTML = "Location information is unavailable."
break;
case error.TIMEOUT:
x.innerHTML = "The request to get user location timed out."
break;
case error.UNKNOWN_ERROR:
x.innerHTML = "An unknown error occurred."
break;
}
}
</script>
</body>
</html>
When I click the first button, the two labels are getting filled out with the latitude and longitude as they are expected to.
When I click the button "Save current location as new place" it executes the following code in C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data.OleDb;
using System.Data.Odbc;
namespace BeeMaster
{
public partial class CreatePlace : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btSaveLocation_Click(object sender, EventArgs e)
{
string lat = lblLat.Text;
string lon = lblLon.Text;
}
}
}
As you see, there is nothing in the Page_Load function, but still it seems to somehow reset the labels to their inital state because when I debug the application during run time and set a breakpoint at the beginning of the btSaveLocation_Click function then I see that the text of the two labels is blank already.
Does anybody know please what the problem is here?
Thanks
The content of a label is not part of a postback and thus will not be updated in the viewstate. Put your values in two hidden fields and use those to communicate with the server logic.
I found the solution. There were actually two problems:
The two labels that I was referring to in the codebehind file were not part of the form, they were in fact outside the form.
In the codebehind file I had to request their value in the Page_Load function and not in the function of the button.
This actually solved the problem.
Thanks everybody
actually i have to learn wicket for a practical course and I have some problems. i tried to combine two of the wicket examples from the wicket library, but it failed and i dont know why.
The error message says:
Last cause: Unable to find component with id 'form' in [BorderBodyContainer [Component id = navomaticBorder_body]]
Expected: 'navomaticBorder:navomaticBorder_body:form'.
Found with similar names: 'form'
There are two examples i want to combine: the navomatic side-bar to have some links between my sites and a simple password validator.
NavomaticBorder.java
public NavomaticBorder(final String id) {
super(id);
addToBorder(new BoxBorder("navigationBorder"));
addToBorder(new BoxBorder("bodyBorder"));
}
NavomaticBorder.html
<html>
<head>
<title>Wicket Examples - navomatic</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
<wicket:border>
<p>
<table height = "100%">
<tr>
<td height = "100%" valign = "top">
<div wicket:id = "navigationBorder">
<b>Navigation Links</b>
<p>
<wicket:link>
Seite1<br/>
Seite2<br/>
Seite3
</wicket:link>
</p>
</div>
</td>
<td valign = "top">
<span wicket:id = "bodyBorder">
<wicket:body/>
</span>
</td>
</tr>
</table>
</p>
</wicket:border>
</body>
</html>
Page1.html
<html>
<head>
<title>Wicket Examples - navomatic</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
<span wicket:id = "navomaticBorder">
<h1>Registration 1</h1>
<form wicket:id="form">
<p><label>Username</label>:<input wicket:id="username"
type="text" size="20"></p>
<p><label>Password</label>:<input wicket:id="password1"
type="password" size="20"></p>
<p><label>Confirm Password</label>:<input wicket:id="password2"
type="password" size="20"></p>
<input type="submit" value="Register">
</form>
<div wicket:id="feedback"></div>
</span>
</body>
</html>
Page1.java
public class Page1 extends WebPage {
/**
*
*/
private static final long serialVersionUID = 8070623982828503750L;
public Page1() {
add(new NavomaticBorder("navomaticBorder"));
add(new FeedbackPanel("feedback"));
final TextField<?> username = new TextField<String>("username",
Model.of(""));
username.setRequired(true);
FormComponent<String> password1 = new PasswordTextField("password1",
Model.of(""));
password1.setLabel(Model.of("Password"));
password1.add(StringValidator.minimumLength(8));
password1.add(new PasswordPolicyValidator());
FormComponent<String> password2 = new PasswordTextField("password2",
Model.of(""));
Form<?> form = new Form<Void>("form") {
private static final long serialVersionUID = -8653853765358238769L;
#Override
protected void onSubmit() {
info("Form submitted");
}
};
form.add(new EqualPasswordInputValidator(password1, password2));
add(form);
form.add(username);
form.add(password1);
form.add(password2);
}
}
I think thats the code parts who may cause the error, when i let all of them working alone theres no problem, just when i combine this in the last html file, its throwing an error.
I have no real experience with Html, maybe thats the cause but i hope its enough data to help me :)
Richie
It's looking for your form in the element navomaticBorder. So you should add the form to the navomaticBorder.
Try changing your code to this:
public class Page1 extends WebPage {
/**
*
*/
private static final long serialVersionUID = 8070623982828503750L;
public Page1() {
NavomaticBorder nav = new NavomaticBorder("navomaticBorder");
add(nav);
add(new FeedbackPanel("feedback"));
final TextField<?> username = new TextField<String>("username",
Model.of(""));
username.setRequired(true);
FormComponent<String> password1 = new PasswordTextField("password1",
Model.of(""));
password1.setLabel(Model.of("Password"));
password1.add(StringValidator.minimumLength(8));
password1.add(new PasswordPolicyValidator());
FormComponent<String> password2 = new PasswordTextField("password2",
Model.of(""));
Form<?> form = new Form<Void>("form") {
private static final long serialVersionUID = -8653853765358238769L;
#Override
protected void onSubmit() {
info("Form submitted");
}
};
form.add(new EqualPasswordInputValidator(password1, password2));
nav.add(form);
form.add(username);
form.add(password1);
form.add(password2);
}
}