This is my yesNoPanel class, extending Panel :
public class YesNoPanel extends Panel {
/**
*
*/
private String password = "Password";
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
private static final long serialVersionUID = -8356163236155431543L;
public String getPw()
{
String pw=ConfigurationHelper.getConfigurationProperty("REFRESH_CACHE_PASSWORD", "");
return pw;
}
public YesNoPanel(String id, String message, final ModalWindow modalWindow, final ConfirmationAnswer answer) {
super(id);
final Form yesNoForm = new Form("yesNoForm");
final String wrongPw = "Wrong Password";
final TextField<String> passwordString = new RequiredTextField<String>("password", new PropertyModel(this, password));
passwordString.add(new AjaxFormComponentUpdatingBehavior("onchange") {
#Override
protected void onUpdate(AjaxRequestTarget target) {
}
});
MultiLineLabel messageLabel = new MultiLineLabel("message", message);
yesNoForm.add(messageLabel);
final Label wrongPW = new Label("WrongPassword", wrongPw );
modalWindow.setTitle("Please confirm");
modalWindow.setInitialHeight(200);
modalWindow.setInitialWidth(350);
AjaxButton yesButton = new AjaxButton("yesButton", yesNoForm) {
private static final long serialVersionUID = -3827487963204274386L;
#Override
protected void onSubmit(AjaxRequestTarget target, Form form) {
if (target != null && password.equals(getPw())) {
answer.setAnswer(true);
modalWindow.close(target);
}else if(target != null && !password.equals(getPw())){
answer.setAnswer(false);
wrongPW.setVisible(true);
target.add(wrongPW);
}
}
};
AjaxButton noButton = new AjaxButton("noButton", yesNoForm) {
#Override
protected void onSubmit(AjaxRequestTarget target, Form form) {
if (target != null) {
answer.setAnswer(false);
modalWindow.close(target);
wrongPW.setVisible(false);
}
}
};
yesNoForm.add(yesButton);
yesNoForm.add(noButton);
yesNoForm.add(passwordString);
add(yesNoForm);
wrongPW.setOutputMarkupPlaceholderTag(true);
wrongPW.setVisible(false);
add(wrongPW);
}
}
and the HTML in question :
<?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:wicket>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title></title>
</head>
<body>
<wicket:panel>
<form wicket:id="yesNoForm" action="">
<span wicket:id="message">Are you sure?</span>
<table style="width: 65%;" align="center">
<tr>
<td align="left">
<input type="submit" wicket:id="noButton" value="No" />
</td>
<td align="right">
<input type="text" wicket:id="password" size = "20" />
</td>
<td align="right">
<input type="submit" wicket:id="yesButton" value="Yes" />
</td>
</tr>
</table>
</form>
<font color="red"><p align="center" wicket:id="WrongPassword"></p> </font>
</wicket:panel>
</body>
As it is now, when the user opens the modal window the input box is filled with the wicket id password - which is simply the string "Password". The Yes or No buttons don't do anything if the input if left blank (or a placeholder is used, which is preferable). Why is this and how can I work around it?
You should use a TextField rather than a RequiredTextField.
Using a RequiredTextField with blank input, the buttons don't do anything.
Related
I've to create a modal dialog which contains a AjaxBootstrapTabbedPanel with two or more tabs. All tabs belong to the same form.
Each tab contains required input fields, select boxes or drop down choices. Until now,
I don't use own validators, but this is a future task.
I was able to trigger the validation when switching between the tabs.
When I use the dialog like variant A and B, I get proper feedback from validation.
Variant A
open the dialog
closing the dialog via submit button immediately results in feedback message "please enter a value in field..."
Variant B
open the dialog
switch to another tab without filling required fields on initial tab gives
also "please enter a value in ..."
Variant C - validation problem
But using the dialog in this way doesn't result in feedback messages:
open the dialog
enter all required values on the initial tab
don't enter values in required fields on another tab
use the submit button to close the diaolg: no feedback message!!, but there has to be one or more
In Variant C, no logging output from the method BootstrapAjaxButton#onError() is printed.
I'm using Wicket 7.6.0 and Wicket-Bootstrap 0.10.11
Class for modal dialog
public abstract class OwsDetailsDialog extends Modal<Ows>
{
private static final long serialVersionUID = -8110788978602397064L;
private BootstrapAjaxButton createOwsBtn;
private BootstrapForm<Ows> owsForm;
public OwsDetailsDialog(String id,
IModel<Ows> owsModel)
{
super(id, owsModel);
setOutputMarkupPlaceholderTag(true);
setDefaultModel(owsModel);
owsForm = new BootstrapForm<>("owsForm");
owsForm.setOutputMarkupId(true);
add(owsForm);
List<ITab> tabs = createTabs(owsModel);
MyAjaxTabbedPanel tabbedPanel = new MyAjaxTabbedPanel("tabbedPanel", tabs);
owsForm.add(tabbedPanel);
createOwsBtn = new BootstrapAjaxButton("submitOws",
Model.of("Create"), Buttons.Type.Default)
{
#Override
protected void onError(AjaxRequestTarget target, Form<?> form)
{
super.onError(target, form);
target.add(form, tabbedPanel);
System.out.println("onError() at form ID " + form.getId() + " target.getPage() "
+ target.getPage());
}
#Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form)
{
super.onSubmit(target, form);
System.out.println("click on create");
createOws(target, owsModel);
}
};
owsForm.add(createOwsBtn);
BootstrapAjaxButton cancelBtn = new BootstrapAjaxButton("cancelOws",
Model.of("Cancel"), Buttons.Type.Default)
{
#Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form)
{
super.onSubmit(target, form);
cancel(target);
}
};
cancelBtn.setDefaultFormProcessing(false);
owsForm.add(cancelBtn);
//FeedbackPanel feedbackOwsDialog = new FeedbackPanel("feedbackOwsDialog");
//add(feedbackOwsDialog);
}
private List<ITab> createTabs(IModel<Ows> owsModel)
{
List<ITab> tabs = new ArrayList<>();
tabs.add(new AbstractTab(Model.of("Data 1"))
{
private static final long serialVersionUID = -9107223557866453561L;
#Override
public WebMarkupContainer getPanel(String panelId)
{
return new OwsMainInfoContainer(panelId, owsModel);
}
});
tabs.add(new AbstractTab(Model.of("Data 2"))
{
private static final long serialVersionUID = -7323530522820254738L;
#Override
public WebMarkupContainer getPanel(String panelId)
{
return new OwsSecondaryInfoContainer(panelId, owsModel);
}
});
return tabs;
}
protected class OwsMainInfoContainer extends Panel
{
private static final long serialVersionUID = -2965824809083715016L;
public OwsMainInfoContainer(
String panelId, IModel<Ows> owsModel)
{
super(panelId, owsModel);
add(new RequiredTextField<>("title"));
add(new RequiredTextField<>("url"));
List<OwsType> types = Arrays.asList(OwsType.values());
DropDownChoice<OwsType> dropDownChoice = new DropDownChoice<>("category", types,
new ChoiceRenderer<OwsType>()
{
private static final long serialVersionUID = 8139757791037487164L;
#Override
public Object getDisplayValue(OwsType owsType)
{
return owsType.getName();
}
});
add(dropDownChoice.setRequired(true));
add(new FeedbackPanel("feedbackMain"));
}
}
protected class OwsSecondaryInfoContainer extends Panel
{
private static final long serialVersionUID = -7396160769731997541L;
public OwsSecondaryInfoContainer(
String panelId, IModel<Ows> owsModel)
{
super(panelId, owsModel);
add(new DateTextField("firstPublished"));
add(new TextField<>("provider").setRequired(true));
add(new TextField("price").setRequired(true));
add(new FeedbackPanel("feedbackSecondary"));
}
}
protected abstract void createOws(AjaxRequestTarget target
, IModel<Ows> owsWithUtilDateIModel);
protected abstract void cancel(AjaxRequestTarget target);
// http://www.volkomenjuist.nl/blog/2009/12/01/ajaxtabbedpanel-store-state-when-switching-tabs/
class MyAjaxTabbedPanel extends AjaxBootstrapTabbedPanel<ITab>
{
private static final long serialVersionUID = 1513951445901529991L;
public MyAjaxTabbedPanel(String id, List<ITab> tabs)
{
super(id, tabs);
}
#Override
protected WebMarkupContainer newLink(String linkId, final int index)
{
return new AjaxSubmitLink(linkId, owsForm)
{
private static final long serialVersionUID = 7049548660275591812L;
#Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form)
{
setSelectedTab(index);
if (target != null)
{
target.add(form);
}
onAjaxUpdate(target);
System.out.println("onSubmit() on target.getPage(): " + target.getPage());
}
#Override
protected void onError(AjaxRequestTarget target, Form<?> form)
{
MyAjaxTabbedPanel component = MyAjaxTabbedPanel.this;
target.add(component);
System.out.println("in onError() , target.add() on " + component.getId());
}
};
}
}
}
Class extending WebPage
public class MyPage extends WebPage
{
private static final long serialVersionUID = 6826446949682313116L;
public MyPage()
{
Form<Void> form = new Form<Void>("buttonForm");
add(form);
form.setOutputMarkupId(true);
OwsDetailsDialog owsDialog = new OwsDetailsDialog("owsDialog"
, new CompoundPropertyModel<Ows>(new Ows()))
{
#Override
protected void createOws(AjaxRequestTarget target,
IModel<Ows> model)
{
Ows ows = model.getObject();
System.out.println("object: "+ ows);
close(target);
}
#Override
protected void cancel(AjaxRequestTarget target)
{
System.out.println("click auf abbrechen");
close(target);
}
};
add(owsDialog);
BootstrapAjaxButton createOwsButton = new BootstrapAjaxButton("createOwsButton",
Model.of("OWS neu"), Buttons.Type.Default)
{
#Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form)
{
super.onSubmit(target, form);
owsDialog.setDefaultModelObject(new Ows());
target.add(owsDialog);
TabbedPanel tabbedPanel = (TabbedPanel) owsDialog.get("owsForm:tabbedPanel");
tabbedPanel.setSelectedTab(0);
owsDialog.show(target);
}
};
form.add(createOwsButton);
}
}
PoJo
package example.tryOut.ows;
import java.util.Date;
public class Ows
{
private Integer index=0;
private String title = "";
private String provider = "";
private String url = "";
private OwsType category;
private Date firstPublished =null;
private Double price=0.0;
public Integer getIndex()
{
return index;
}
public void setIndex(Integer index)
{
this.index = index;
}
public String getTitle()
{
return title;
}
public void setTitle(String title)
{
this.title = title;
}
public String getProvider()
{
return provider;
}
public void setProvider(String provider)
{
this.provider = provider;
}
public String getUrl()
{
return url;
}
public void setUrl(String url)
{
this.url = url;
}
public OwsType getCategory()
{
return category;
}
public void setCategory(OwsType category)
{
this.category = category;
}
public Date getFirstPublished()
{
return firstPublished;
}
public void setFirstPublished(Date firstPublished)
{
this.firstPublished = firstPublished;
}
public Double getPrice()
{
return price;
}
public void setPrice(Double price)
{
this.price = price;
}
#Override
public String toString()
{
return "Ows{" +
"index=" + index +
", title='" + title + '\'' +
", provider='" + provider + '\'' +
", url='" + url + '\'' +
", category=" + category +
", firstPublished=" + firstPublished +
", price=" + price +
'}';
}
}
Markup
Page
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<head>
<meta charset="UTF-8">
</head>
<body>
<form wicket:id="buttonForm">
<button wicket:id="createOwsButton"></button>
</form>
<div wicket:id="owsDialog"></div>
</body>
</html>
Dialog
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<head>
<meta charset="UTF-8">
</head>
<body>
<wicket:extend>
<form wicket:id="owsForm">
<div wicket:id="tabbedPanel" class="container" style="width: inherit"></div>
<button type="submit" wicket:id="submitOws" class="btn btn-main">Anlegen</button>
<button type="reset" wicket:id="cancelOws" class="btn btn-main">Abbrechen</button>
</form>
</wicket:extend>
</body>
</html>
<!DOCTYPE html>
<html lang="en" xmlns:wicket="http://wicket.apache.org">
<head>
<meta charset="UTF-8">
</head>
<body>
<wicket:panel>
<div class="form-group">
<label wicket:for="url">URL</label>
<div class="controls">
<input type="text" wicket:id="url" class="form-control"/>
</div>
</div>
<div class="form-group">
<label wicket:for="title">Title</label>
<div class="controls">
<input type="text" wicket:id="title" class="form-control"/>
</div>
</div>
<div class="form-group">
<label wicket:for="category">OWS Category</label>
<div class="controls">
<select wicket:id="category">
<option value="">dummy1</option>
<option value="">dummy2</option>
</select>
</div>
</div>
<div wicket:id="feedbackMain"></div>
</wicket:panel>
</body>
</html>
<!DOCTYPE html>
<html lang="en" xmlns:wicket="http://wicket.apache.org">
<head>
<meta charset="UTF-8">
</head>
<body>
<wicket:panel>
<div class="form-group">
<label wicket:for="price">Price</label>
<div class="controls">
<input type="text" wicket:id="price" class="form-control"/>
</div>
</div>
<div class="form-group">
<label wicket:for="provider">Provider</label>
<div class="controls">
<input type="text" wicket:id="provider" class="form-control"/>
</div>
</div>
<div class="form-group">
<label wicket:for="firstPublished">First published</label>
<div class="controls">
<input type="date" wicket:id="firstPublished" class="form-control"/>
</div>
</div>
<div wicket:id="feedbackSecondary"></div>
</wicket:panel>
</body>
</html>
I have two text boxes to read input. Once the page is submitted, I would like to display the data in a table. I am facing issue while load the widget; it says dataView is not defined and also the table id is not defined. However, I defined this inside the submit method. The code is below. Please help me.
HomePage.java
public class HomePage extends WebPage {
private String memberNumber,lossNumber;
ArrayList <AssignmentDB> list = new ArrayList<AssignmentDB>(); int flag=0;
public HomePage(){
list.add(new AssignmentDB("1234","001","1678","10/june//2013"));
PropertyModel memberIdModel=new PropertyModel(this,"memberNumber");
PropertyModel lossIdModel=new PropertyModel(this,"lossNumber");
TextField memberIdField = new TextField("memberId",memberIdModel);
TextField lossIdField = new TextField("lossId",lossIdModel);
Form form=new Form("form1"){
public void onSubmit(){
list.add(new AssignmentDB("1234","001","1678","10/june//2013"));
list.add(new AssignmentDB("1235","003","1678","13/june//2013"));
DataView<List<AssignmentDB>> dataView = new DataView<List<AssignmentDB>>("AssignmentList", new ListDataProvider(list)) {
public void populateItem(Item<List<AssignmentDB>> item) {
AssignmentDB lists = (AssignmentDB) item.getModelObject();
if (lists.getMemberId().equals(memberNumber)){
if(lists.getLossId().equals(lossNumber)){
flag=1;
item.add(new Label("AOmemberId", lists.getMemberId()));
item.add(new Label("AOlossId", lists.getLossId()));
item.add(new Label("AOassignmentId", lists.getAssignmentId()));
item.add(new Label("AOdol", lists.getDOL()));
}
}
}
};
if (flag==0)
System.out.println("no matches");
form.add(dataView);
form.add(memberIdField);
form.add(lossIdField);
add(form);
}
public void setMemberNumber(String x)
{
this.memberNumber=x;
}
public void setLossNumber(String x)
{
this.lossNumber=x;
}
public String getMemberNumber(){
return this.memberNumber;
}
public String getLossNumber(){
return this.lossNumber;
}
}
homepage.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>EstimateSearcher</title>
</head>
<body>
<form wicket:id="form1">
Member Number <input type="text" wicket:id="memberId"><br/>
Loss Number <input type="text" wicket:id="lossId"><br/>
<input type="submit" value=search>
<table border="1">
<tr>
<th>MemberNo</th>
<th>LossNo</th>
<th>AssignmentNo</th>
<th>dol</th>
</tr>
<div wicket:id="AssignmentList">
<tr>
<td wicket:id="AOmemberId"></td>
<td wicket:id="AOlossId"></td>
<td wicket:id="AOassignmentId"></td>
//<td> <span wicket:id="AOassignmentId">[Address]</span> </td>
<td wicket:id="AOdol"></td>
</tr>
</div>
</table>
</form>
</body>
</html>
You need to add the table outside your submit function because all html wicket:id's should be filled when page is rendered (except the ones with an invisible parent). What you can do is create and add the dataview with an empty list and then use ajax to update your list and the rerender the list:
form.add(new AjaxButton("ajax-button", form)
{
#Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form)
{
list.add(new AssignmentDB("1234","001","1678","10/june//2013"));
list.add(new AssignmentDB("1235","003","1678","13/june//2013"));
// repaint the dataView
target.add(dataView);
}
#Override
protected void onError(AjaxRequestTarget target, Form<?> form)
{
// error handling
}
});
Second easier thing you can do is create a constructor with the list you want to show and do setResponsPage(new HomePage(listYouWantToUse)); in you forms onSubmit().
i have a jsp page that gets two parameters 1 for adding another for viewing.this jsp page is named as sucessAdmin.jsp. I have another jsp page admin1.jsp which calls sucessadmin.jsp. admin1.jsp has a form view and add.so if i press the view button it calls sucessAdmin.jsp and displays datas. when i press the add button then it displays a form to enter data but its not adding values to the mysql DB. when i call the same page again,it does not add the data.Please tell me where i have mistake
this is the bean
package sucessAdmin;
import java.sql.*;
import java.io.*;
import java.util.*;
public class sucessAdmin {
private String question;
private String answer;
private String questionNo;
private String opt1;
private String opt2;
private String opt3;
private String opt4;
public sucessAdmin()
{
}
public void setQuestion(String question)
{
this.question=question;
}
public String getQuestion()
{
return question;
}
public void setAnswer(String answer)
{
this.answer=answer;
}
public String getAnswer()
{
return answer;
}
public void setQuestionNo(String questionNo)
{
this.questionNo=questionNo;
}
public String getQuestionNo()
{
return questionNo;
}
public void setOpt1(String opt1)
{
this.opt1=opt1;
}
public String getOpt1()
{
return opt1;
}
public void setOpt2(String opt2)
{
this.opt2=opt2;
}
public String getOpt2()
{
return opt2;
}
public void setOpt3(String opt3)
{
this.opt3=opt3;
}
public String getOpt3()
{
return opt3;
}
public void setOpt4(String opt4)
{
this.opt4=opt4;
}
public String getOpt4()
{
return opt4;
}
public Vector getDetails()
{
int x=0;
Vector v= new Vector();
try
{
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost:3306/Ontest";
Connection con=DriverManager.getConnection(url,"root","spanwave");
ResultSet rs=null;
Statement st=con.createStatement();
rs=st.executeQuery("select * from questions");
String quer="SELECT * FROM questions";
rs=st.executeQuery(quer);
ResultSetMetaData rsmd = rs.getMetaData();
int NumOfCol=0;
NumOfCol=rsmd.getColumnCount();
System.out.println("Query Executed!! No of Colm="+NumOfCol);
while(rs.next())
{
for(int i=1;i<NumOfCol+1;i++)
{
if(i==NumOfCol)
{System.out.print(rs.getString(i));System.out.println();}else
System.out.print(rs.getString(i)+" ");
v.addElement(rs.getString(i));
}
}
}
catch(Exception e)
{
System.out.println(e);
}
return v;
}
public void addDetails(String question,String opt1,String opt2,String opt3,String opt4,String questionNo,String answer)
//public void addDetails()
{
int qnNo=0;
try
{
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost:3306/Ontest";
Connection con=DriverManager.getConnection(url,"root","spanwave");
ResultSet rs=null;
qnNo=Integer.parseInt(questionNo);
PreparedStatement ptst=con.prepareStatement("insert into questions values(?,?,?,?,?,?,?)");
ptst.setString(1,question );
ptst.setString(2,opt1 );
ptst.setString(3,opt2 );
ptst.setString(4,opt3 );
ptst.setString(5,opt4 );
ptst.setInt(6, qnNo);
ptst.setString(7,answer);
ptst.executeUpdate();
int NumOfCol=0;
System.out.println("Query Executed!! No of Colm="+NumOfCol);
}
catch(Exception e)
{
System.out.println(e);
}
}
}
this is the calling page
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<jsp:useBean id="admin" scope="request" class="admin.adminBean">
<jsp:getProperty property="userId" name ="admin"/>
</jsp:useBean>
<jsp:useBean id="sucessAdmin" scope ="request" class="sucessAdmin.sucessAdmin"></jsp:useBean>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title><jsp:getProperty property="userId" name ="admin"/></title>
</head>
<body bgcolor="pink">
<form action="details.jsp" method="get">
view questions<input type="radio" name="details" value="view"><br>
edit questions
<input type="radio" name="details" value="edit"><br>
add questions
<input type="radio" name="details" value="add"><br>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
this is the called page
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# page import="java.util.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head><jsp:useBean id="sucessAdmin" scope ="request" class="sucessAdmin.sucessAdmin">
</jsp:useBean>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Details</title>
</head>
<body>
<%String input; %>
<%=input=request.getParameter("details") %>
<%if (input.equals("view")) {
%><%Vector v; %>
<%v=(Vector)sucessAdmin.getDetails();
out.println(sucessAdmin.getDetails()); }
%><%
if(input.equals("add"))
{out.println("addds");
%>
<form method="POST" action="details.jsp">
<table>
<tr>
<td>question<input type="text" name="question" value="" /></td>
</tr>
<tr>
<td>opt1<input type="text" name="opt1" value="" /></td>
</tr>
<tr>
<td>opt2<input type="text" name="opt2" value="" /></td>
</tr>
<tr>
<td>opt3<input type="text" name="opt3" value="" /></td>
</tr>
<tr>
<td>opt4<input type="text" name="opt4" value="" /></td>
</tr>
<tr>
<td>questionNumber<input type="text" name="questionNo" value="" /></td>
</tr>
<tr>
<td>answer<input type="text" name="answer" value="" /></td>
</tr>
</table><br><input type="hidden" name="details"/>
<br><input type="submit" name="submit" value="submit"/>
<%sucessAdmin.addDetails("question","opt1","opt2","opt3","opt4","questionNo","answer");%>
</form>
<%out.println("adding");}
%>
</body>
</html>
replace <%sucessAdmin.addDetails("question","opt1","opt2","opt3","opt4","questionNo","answer");%>
with
<%
String question = request.getParameter("question");
String opt1= request.getParameter("opt1");
String opt2 = request.getParameter("opt2");
String opt3 = request.getParameter("opt3");
String opt4 = request.getParameter("opt4");
String questionNo = request.getParameter("questionNo");
String answer = request.getParameter("answer");
if(question!=null && opt1!=null && opt2 != null
opt3!=null && opt4 !=null && questionNo!=null && answer!=null)
{
sucessAdmin.addDetails(question,opt1,opt2,opt3,opt4,questionNo,answer);
}
%>
Try this and let's hope it works..
Its my jsp page from where i'm sending the data to javabean:
<%# page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%#taglib uri="/struts-tags" prefix="s" %>
<%#taglib uri="/struts-dojo-tags" prefix="sx" %>
<%#page session="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<sx:head parseContent="true" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Set the Leaves </title>
<script language="JavaScript" src="../Advance_Academic_ERP/css/Ck_Effect.js"></script>
<link rel="stylesheet" type="text/css" media="all"
href="../Advance_Academic_ERP/css/jsDatePick_ltr.min.css" />
<script type="text/javascript"
src="../Advance_Academic_ERP/css/jsDatePick.min.1.3.js"></script>
<script type="text/javascript">
window.onload = function(){
new JsDatePick({
useMode:2,
target:("fromDate"),
dateFormat:"%d-%m-%Y"
});
new JsDatePick({
useMode:2,
target:("toDate"),
dateFormat:"%d-%m-%Y"
});
};
</script>
<script type="text/javascript">
function display(val) {
var o = document.getElementById('name1');
var b = document.getElementById('leaveNo1');
(parseInt(val) == '5' || parseInt(val)=='6')? o.style.display = 'block' : o.style.display = 'none';
(parseInt(val) == '5' || parseInt(val)=='6')? b.style.display = 'block' : b.style.display = 'none';
}
</script>
</head>
<body>
<s:form action="LeaveSetterAction" name="leave" validate="true">
<s:select label="Type Of Holiday/Leave*"
headerKey="-1" headerValue="Select Type"
list="#{'1':'National Holidays', '2':'Weekly Holidays', '3':'Local Holidays', '4':'Situational Holidays', '5':'Seek Leaves', '6':'Personal Leaves'}"
name="leaveType" id="leaveType" onchange="display(this.value);"/>
<table id="name1" style="display: none;">
<tr>
<td>Name</td>
<td><input type="text" name="name" id="name"></td>
</tr>
</table>
<table id="leaveNo1" style="display: none;">
<tr>
<td>No Of Alloted Leaves</td>
<td><input type="text" name="leaveNo" id="leaveNo"></td>
</tr>
</table>
<s:textfield name="fromDate" label="From date*" key="fromDate" id="fromDate"></s:textfield>
<s:textfield name="toDate" label="To date*" key="toDate" id="toDate"></s:textfield>
<s:textfield name="difference" label="Duration" key="difference" id="difference" readonly="readonly"></s:textfield>
<s:textarea name="desc" label="Description*" key="desc" onmouseover="setDifference(this);"></s:textarea>
<s:submit align="center"></s:submit> <s:reset align="center"></s:reset>
</s:form>
</body>
</html>
Its mine javabean page where i'm supposed to get the data:
package abc.Model;
public class SetLeave {
String leaveType;
String name;
String leaveNo;
String fromDate;
String toDate;
String difference;
String desc;
public String getLeaveType() {
return leaveType;
}
public void setLeaveType(String leaveType) {
this.leaveType = leaveType;
}
public String getName() {
System.out.println(name);
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLeaveNo() {
System.out.println(leaveNo);
return leaveNo;
}
public void setLeaveNo(String leaveNo) {
this.leaveNo = leaveNo;
}
public String getFromDate() {
return fromDate;
}
public void setFromDate(String fromDate) {
this.fromDate = fromDate;
}
public String getToDate() {
return toDate;
}
public void setToDate(String toDate) {
this.toDate = toDate;
}
public String getDifference() {
return difference;
}
public void setDifference(String difference) {
this.difference = difference;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
}
I'm using javascript on some textfields which are getting null values
Please help me out.
Thanks in advance.
<s:textfield name="difference" label="Duration" key="difference" id="difference" disabled="true"></s:textfield>
In this field you have disabled="true", so the value that would be send to the Model/Bean would be null obviously.
<s:textfield name="difference" label="Duration" key="difference" id="difference" disabled="true"></s:textfield>
<s:hidden name="difference"/>
If you want to send value to your bean. If you still get error, then reply.
Ok , Get this done and reply..
<table id="name" style="display: none;">
<tr>
<td>Name</td>
<td><input type="text" name="name" id="name"></td>
</tr>
</table>
<table id="leaveNo" style="display: none;">
<tr>
<td>No Of Alloted Leaves</td>
<td><input type="text" name="leaveNo" id="leaveNo"></td>
</tr>
</table>
You are using same id's for table and textfield in both the above cases change the id of table to name1 and leaveNo1 and try. I guess this is the only problem.
Your solution is there in the below code paste it and enjoy.
<s:textfield name="difference" label="Duration" key="difference" id="difference" readonly="readonly"></s:textfield>
I have been trying with limited success to code a JSF application. In one section of the application, I need users to select from a select menu which displays a list of selectable status values. The Status class (presented below), which is used to populate the List that is displayed in the select menu, is a simple class made up of two Strings: one is the code used to look up the description in the database, the other is the human-readable description. I am trying to find out if I need a converter here at all, and if so, how best to implement the converter. This is a JSF 1.1 project using Java 1.5
I am using the following code in the JSP:
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%# taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<f:view>
<html>
<h:graphicImage id="image" url="/images/appname.jpg"
alt="app name" />
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<jsp:include page="/jsp/menu.jsp" />
</head>
<body>
<h:outputText
value="Add Value"
style="font-size:20px;" />
<h:messages errorStyle="color: red" infoStyle="color: green"
layout="table" />
<h:form id="statusReasonEditForm">
<table>
<tr>
<td><h:outputText id="txtvalue" value="Status" /></td>
<td><h:selectOneMenu id="selectStatus"
value="#{pc_statusReasonBacker.status}"
binding="#{pc_statusReasonBacker.selectItem}">
<f:selectItems value="#{pc_statusReasonBacker.selectStatuses}" />
<f:converter converterId="statusConverter" />
</h:selectOneMenu>
<td><h:outputText id="txtvaluereason" value="Status Reason" /></td>
<td><h:inputText id="txtinputreason"
value="#{pc_statusReasonBacker.statusReason.statusReason}"
maxlength="100" size="40" /></td>
<td><h:outputText id="txtvaluereasondesc"
value="Status Reason Desc" /></td>
<td><h:inputText id="txtinputreasondesc"
value="#{pc_statusReasonBacker.statusReason.statusReasonDesc}"
maxlength="100" size="40" /></td>
</tr>
</table>
<tr>
<td><h:commandButton id="savebutton" value="Save"
action="#{pc_statusReasonBacker.save}" /></td>
<td><h:commandButton id="cancelbutton" value="Cancel"
action="#{pc_statusReasonBacker.cancel}" /></td>
</tr>
</h:form>
<hr />
</body>
</html>
</f:view>
The backing bean is shown here (some non-related sections, such as paging, removed for clarity):
public class StatusReasonBacker {
private List<StatusReason> statusReasonList;
private List<Status> statusList;
private List<SelectItem> selectStatuses;
private StatusReason statusReason;
private StatusDao sDao;
private Status status;
private UIData statusReasonTable;
private HtmlSelectOneMenu selectItem;
private String selectedStatus = "";
public StatusReasonBacker() {
sDao = new StatusDao();
statusReason = new StatusReason();
selectStatuses = new ArrayList<SelectItem>();
status = new Status();
selectItem = new HtmlSelectOneMenu();
}
public String insert() {
status.setStatusCde("");
statusReason.setStatus(status);
statusReason.setStatusReason("");
statusReason.setStatusReasonCde("");
statusReason.setStatusReasonDesc("");
return "success";
}
public String edit() {
this.statusReason = (StatusReason) statusReasonTable.getRowData();
selectItem.setValue(statusReason.getStatus().getStatusCde());
return "success";
}
public String update() {
if ("".equalsIgnoreCase(statusReason.getStatusReason().trim())) {
Message
.addErrorMessage("You must enter a value for the status reason.");
return "failure";
} else if (("".equalsIgnoreCase(statusReason.getStatusReasonDesc()
.trim()))) {
Message
.addErrorMessage("You must enter a value for the status reason description.");
return "failure";
}
sDao.updateStatusReason(statusReason);
return "statusreasons";
}
public String delete() {
StatusReason statReason = (StatusReason) statusReasonTable.getRowData();
sDao.deleteStatusReason(statReason);
return "statusreasons";
}
public String cancel() {
return "statusreasons";
}
public String save() {
statusReason.setStatus(status);
sDao.insertStatusReason(statusReason);
return "statusreasons";
}
...
public StatusDao getSDao() {
return sDao;
}
public void setSDao(StatusDao dao) {
sDao = dao;
}
public List<StatusReason> getStatusReasonList() {
statusReasonList = sDao.getStatusReasons();
return statusReasonList;
}
public void setStatusReasonList(List<StatusReason> statusReasonList) {
this.statusReasonList = statusReasonList;
}
public UIData getStatusReasonTable() {
return statusReasonTable;
}
public void setStatusReasonTable(UIData statusReasonTable) {
this.statusReasonTable = statusReasonTable;
}
public StatusReason getStatusReason() {
return statusReason;
}
public void setStatusReason(StatusReason statusReason) {
this.statusReason = statusReason;
}
public List<Status> getStatusList() {
statusList = sDao.getStatuses();
return statusList;
}
public void setStatusList(List<Status> statusList) {
this.statusList = statusList;
}
public List<SelectItem> getSelectStatuses() {
selectStatuses.clear();
if (statusList == null) {
statusList = this.getStatusList();
}
for (Status sr : statusList) {
SelectItem si = new SelectItem();
si.setValue(sr.getStatusCde());
si.setLabel(sr.toString());
si.setDescription(sr.toString());
selectStatuses.add(si);
}
return selectStatuses;
}
public void setSelectStatuses(List<SelectItem> selectStatuses) {
this.selectStatuses = selectStatuses;
}
public String getSelectedStatus() {
selectedStatus = statusReason.getStatusDesc();
return selectedStatus;
}
public void setSelectedStatus(String selectedStatus) {
this.selectedStatus = selectedStatus;
}
public Status getStatus() {
return status;
}
public void setStatus(Status status) {
this.status = status;
}
public HtmlSelectOneMenu getSelectItem() {
return selectItem;
}
public void setSelectItem(HtmlSelectOneMenu selectItem) {
this.selectItem = selectItem;
}
}
Thanks!
I am trying to find out if I need a converter here at all, and if so, how best to implement the converter.
You need a converter whenever you want to pass non-standard Java Objects from a HTTP request to another HTTP request. With non-standard I mean not a String, Number or Boolean. This all simply because HTTP request parameters can only be Strings. That Number and Boolean works is because EL can recognize them and has built-in coercions for it.
For non-standard Java Objects you need to implement a javax.faces.convert.Converter which converts the Object to a String (or a Number so you want, for example a Long id which can be the PK of the associated row in database table) inside the getAsString() method before displaying in HTML. You do the other way round in the getAsObject() method during processing of the request parameters (e.g. get the associated object from DAO by its id).
You can find here an example of how to use a Converter for a h:selectOneMenu. You see that this article also contains an alternative, but you'll need to do a bit more work in the backing bean to convert (map) the objects yourself.