I have an ajaxEditableLabelWithIcon which is a ajaxEditableLabel with a modified HTML that contain an icon. When the user click this icon, the editor field become editable and when he click again, the content is saved. We did that using JQuery :
function editOrSubmit(element){
panel = element.parentElement;
label = panel.children[0];
if(panel.find){
e = $.Event('keypress');
e.which = 13; // Enter key
label.trigger(e); //submit the FormTester
}
else{
label.click(); //Wich make the label editable
}
}
Now, I want to test it using JUnit. Since I can't directly click on the icon, I tried to create a javascript shortcut to the function, and then create a Robot to trigger the KeyPressed events :
// defining flags
var isCtrl = false;
var isShift = false;
$(document).ready(function() {
// action on key up
$(document).keyup(function(e) {
if(e.which == 17) {
isCtrl = false;
}
if(e.which == 16) {
isShift = false;
}
});
// action on key down
$(document).keydown(function(e) {
if(e.which == 17) {
isCtrl = true;
}
if(e.which == 16) {
isShift = true;
}
// En cas d'appui sur ctrl+Shift+F9 en même temps, la méthode editOrSubmit est appelée
if(e.which == 120 && isCtrl && isShift) {
var icon = document.getElementById("icon");
editOrSubmit(icon);
}
});
});
It work well in a browser, but inside the test nothing happen ? Do you know why ?
unfortunately Wicket and JUnit cannot test JavaScript code but just Java code. However, Wicket itself uses Maven and frontend-maven-plugin to run QUnit tests via Maven. You can take a look at Wicket code inside testing/wicket-js-tests (https://github.com/apache/wicket/tree/master/testing/wicket-js-tests) to see how this is done by Wicket and you can copy the code you need to run your tests.
Related
I have a form and some textfields on it:
TextField taxNumber = new TextField();
taxNumber.setPrefixComponent(VaadinIcon.BARCODE.create());
accountApplicationBinder
.forField(taxNumber)
.withValidator(new StringLengthValidator(....
And I have some validation logic in the Listener:
taxNumber.addBlurListener(event -> {
String localResult = "";
InfoResult ir = ks.loadInfo(taxNumber.getValue());
if ((ir.errorText == null) && (!ir.name.isEmpty())) {
...
} else {
localResult = "";
taxNumber.setInvalid(true);
taxNumber.setErrorMessage("Not valid tax - " + accountApplicationBinder.isValid());
}
taxNumberStatusLabel.setText(localResult);
});
And I want to get a behavior like a ".withValidator... return not valid" in my submit button listener. In other words: I want to have my submit button not working then taxNumber.addBlurListener return not valid result. How I can do that?
it seems to me that your logic in the blurlistener replicates the validation you have already set when you bound the field with .withValidator(new StringLengthValidator()). That Validator is supposed to do exactly that.
When you click your submit button, all you have to do is validate the binder, and if it's not valid, then don't submit. You can customize the error string that it shows under the taxNumber field by providing a customized string into the StringLengthValidator:
.withValidator(new StringLengthValidator("Not valid tax", 4, null))
I just realized that you probably have custom validation in ks.loadInfo(taxNumber.getValue()). If that is the case, then the best way is to replace the StringLengthValidator with a custom Validator that you can write, for example like this
.withValidator(taxNr -> {
InfoResult ir = ks.loadInfo(taxNr);
return ir.errorText == null && !ir.name.isEmpty();
}, "Not valid tax")
I work with camera2API on Samsung S5 and if i try get state of focus i get value 0 which is equals to CaptureResult.CONTROL_AF_STATE_INACTIVE...
There is snip of code :
private void process(CaptureResult result) {
switch (mState) {
case CameraHelper.STATE_PREVIEW: {
// We have nothing to do when the camera preview is working normally.
here i get ---> Integer afState = result.get(CaptureResult.CONTROL_AF_STATE);
if (CaptureResult.CONTROL_AF_TRIGGER_START == afState) {
if (areWeFocused) {
Log.e("---!!! HERE !!!--- :", String.valueOf(areWeFocused));
}else {
}
}
if (CaptureResult.CONTROL_AF_STATE_PASSIVE_FOCUSED == afState) {
areWeFocused = true;
} else {
areWeFocused = false;
}
break;
}
But i also tried to test it on my Meizu MX5 and i get 1 - CaptureResult.CONTROL_AF_TRIGGER_START or 2 - CaptureResult.CONTROL_AF_STATE_PASSIVE_FOCUSED
Question is : what is the difference in my code? Why do i get 0 in one case and 1 or 2 in another?
I know this is an old question, but i just ran into the same issue. Read through the Android docs about ControlAfState (AF = Auto Focus for those who are unaware, like I was). If AutoFocus Mode (afMode) is set to AF_MODE_OFF you will get the ControlAfState of Inactive.
Android CaptureResult.CONTROL_AF_STATE
I decided to use wizard component.link on this component
I have condition that instead of checkbox "Skip to last" I should use button. If I press on this button it's ok, but when I go to penult tab I want generate content of confirmation tab,
public void generatePreview() {
for (CompetitionTypeBean competitionType : competitionTypeList) {
if (competitionType.getId().equals(competitionTypeId)) {
tournamentBean.setCompetitionTypeBean(competitionType);
}
}
if (teamList != null && !teamList.isEmpty()) {
List<TeamBean> teams = new ArrayList<TeamBean>();
for (TeamBean team : teamList) {
for (Long teamId : teamListSelected)
if (team.getId().equals(teamId)) {
teams.add(team);
break;
}
}
tournamentBean.setTeams(teams);
}
}
it means that I should set skip in true for that I decide to write js function which will work on onnext event of wizard
<script type="text/javascript">
function setHiddenValue(formId, componentId, new_value) {
var tabId = 'competitionId';
if (tabId != 'predLast') {
document.getElementsByName('wiz').next();
} else {
var fullComponentId = formId + ":" + componentId;
document.getElementById(fullComponentId).value = new_value;
}
}
</script>
And there I find new problem
First I don't know as I can get current Tab Id. And second I don't how with help js make next event for wizard document.getElementsByName('wiz').next();. I try to see generated html code. Every tab is <li> and when this tab is selected in css style that li add 'ui-state-hightlight'
Maybe I try to develop cycle. But I can't find other solution.
To get the index of the current step in javascript, use the getStepIndex() function. To get name of the current step in the backing bean, you need to obtain a reference to the Wizard in your view and either call getStep()(returns the id property of the next tab) or getStepToProcess()(returns the actual next Tab object, from which you can get the name of the current tab).
<p:wizard/> has onnext and onback event callbacks that you can hook into to process javascript (or backing bean code with <p:remoteCommand/>)
I just add next rows in handler
public String onFlowProcess(FlowEvent event) throws Exception {
if ((skip == true)) {
skip = false; //reset in case user goes back
generatePreview();
return CONFIRM_TAB_ID;
} else {
String newTab = event.getNewStep();
if (CONFIRM_TAB_ID.equals(newTab)) {
generatePreview();
}
return newTab;
}
}
I think that using constant CONFIRM_TAB_ID it's normal, because I never decide to change this tabId.
I am calling this code by this window.onbeforeunload=HandleOnClose;
This is working fine in IE but not in other browsers. This code is specific for IE but this is not working in other browsers. How can we detect close event of browser in all the browser ?
function ConfirmClose()
{
if (isIE7Min) //To check for IE Version 7.0 and above
{
var n = window.event.screenX - window.screenLeft;
var b = n > document.documentElement.scrollWidth-20;
if ((b && window.event.clientY < 0) || window.event.altKey)
{
if (!self.closed)
{
refresh = true;
}
}
}
else //IE Version 6.0 and below
{
if (event.clientY < 0 && event.clientX < 0)
{
if (!self.closed)
{
refresh = true;
}
}
}
}
/*Function for onunload*/
function HandleOnClose()
{
ConfirmClose();
if (isIE7Min)
{
if ((window.event.clientX > 0 && window.event.clientY < 0) || window.event.altKey)
{
if (refresh == true)
{
window.open("/DealPricingJavaUAT/DealPricingJsp/Home/logout.jsf");
//Code That redirects to the Session Invalidation Page
}
}
}
else
{
if (event.clientY < 0 && event.clientX < 0 || window.event.altKey)
{
if (refresh == false)
{
window.open("/DealPricingJavaUAT/DealPricingJsp/Home/logout.jsf");
// Code That redirects to the Session Invalidation Page
}
}
}
}
I don't think it is possible to always log user out. If there is a crash on user's web browser, the client-side code will never get executed. Some web browsers shutdown itself very fast and don't wait to execute the client-side code.
You should find an alternative solution, like logging out on server side if user is not active for certain period of time.
Its not possible to detect when the user closes the browser.
If you are using java and using cookies to check if the user is logged-in, you can
do cookie.setMaxAge(-1).
This will make sure that cookies are deleted when browser closes.
I am new to this forum. I have a doubt about JSP/servlet in my application
I have developed an application in which user may search some data based on some criteria and he will get data from database(through Hibernate to servlet and to JSP). When some data is displayed on screen based on search he/she may try to copy the URL and forward to anyone or If he try to open in different browser it is showing an empty page.
eg: if i try to paste the link given bellow it is showing blank page
example link
but i need to display the data how this can be achieved.
Edited: After clicking on job search in menu bar as mentioned in comments the page will redirect to a servlet
if(action.equals("searchjob")){
String requireskills=request.getParameter("txt_requireSkills");
String location=request.getParameter("txt_locationName");
session.setAttribute("location",location);
String minexp1=request.getParameter("dd_minimum");
String maxexp1=request.getParameter("dd_maximum");
jobsearchDAO = new JobSearchDAOImpl();
List<JobPostInfo> data=jobsearchDAO.jobsearchlist(requireskills,location,minexp1,maxexp1);
if(data!=null && data.size()!=0){
//save data
if(!(session.getAttribute("LoginObject")==null)){
JobSeeker jobSeeker=(JobSeeker)session.getAttribute("LoginObject");
JobSearchCriteria jobsearchcriteria= new JobSearchCriteria();
jobsearchDAO=new JobSearchDAOImpl();
jobsearchcriteria.setKeyWords(requireskills);
jobsearchcriteria.setLocation(location);
JobSeeker jobseeker=(JobSeeker)session.getAttribute("jobseeker");
//
// jobsearchcriteria.setJobSeeker(jobseeker.getJobSeekerSn());
jobsearchcriteria.setJscTs(new Date());
int value=jobsearchDAO.savesearch(jobsearchcriteria);
System.out.println("savesearch value------>"+value);
}
session.setAttribute("jobsearchlist", data);
// session.setAttribute("success","Search Criteria is saved to database.");
response.sendRedirect("jobsearchresult.jsp");
}else
{
session.setAttribute("error","No Records found");
response.sendRedirect("jobsearch.jsp");
}
}
This is the code in DAOIMPL
public List<JobPostInfo> jobsearchlist(String requireskills,String location,String minexp1,String maxexp1) throws Exception{
long minexp;
long maxexp;
try{
session =getSession();
//Criteria Query
Criteria query=session.createCriteria(JobPostInfo.class,"jpost");
// if(minexp1.equals("0") && (maxexp1.equals("") || maxexp1==null)){
if((minexp1.equals("-1") || minexp1=="-1") && maxexp1==null){
}
else if(minexp1.equals("0")){
minexp=Long.parseLong(minexp1);
long min=1;
query.add(Restrictions.lt("jpost.experienceMin",min));
}else if(!(minexp1.equals("") || minexp1==null) && maxexp1.equals("-1")) {
minexp=Long.parseLong(minexp1);
query.add(Restrictions.ge("jpost.experienceMin",minexp));
}else if(!(minexp1==null && maxexp1==null)){
minexp=Long.parseLong(minexp1);
maxexp=Long.parseLong(maxexp1);
query.add(Restrictions.and(Restrictions.ge("jpost.experienceMin",minexp),Restrictions.le("jpost.experienceMax",maxexp)));
}
//For Location
if(!(location==null|| location.equals(""))){
query.createAlias("jpost.location","location");
query.add(Restrictions.like("location.locationName",location).ignoreCase());
}
//For Keyword
if(!(requireskills==null || requireskills.equals(""))){
query.add(Restrictions.like("jpost.requiredSkills","%"+requireskills+"%").ignoreCase());
}//requireskills
List<JobPostInfo> list = query.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list();
if(list.size()==0){
return null;
}else{
return list;
}
}catch(HibernateException e){
e.printStackTrace();
}finally {
close(session);
}
return null;
}
I solved my problem. It's a very basic mistake and I hope this will help others:
response.sendRedirect("jobsearchresult.jsp") is replaced by request.getRequestDispatcher("studentinformation.jsp").forward(request, response)
or include-method. The second thing is, the session is created and initialized with the servlet. When I copy the link in a different browser, a certain block of the servlet will be executed. Example:
action.equals("searchjob")
So at the time the session is not available yet, I initialize it in every block like separating declaration and initialization.