Saturday, 31 August 2013

Null Pointer Exception when method is invoked too many times

Null Pointer Exception when method is invoked too many times

I have a page where I set date and specialization:
<form>
<p:panel header="Szukaj wizyty">
<p:panelGrid columns="2">
<p:outputLabel for="Od"
value="Od"></p:outputLabel>
<p:calendar id="Od" label="Od"
value="#{visitPatientMB2.start}" effect="fold"
locale="pl" pattern="dd/MM/yyyy"
mindate="#{visitPatientMB2.actualDate}"
required="true">
<p:ajax event="dateSelect"
listener="#{visitMB.enableCalendar()}"
update="cal" />
</p:calendar>
<p:outputLabel for="Do"
value="Do"></p:outputLabel>
<p:calendar id="Do" label="Do"
value="#{visitPatientMB2.end}" effect="fold"
locale="pl" pattern="dd/MM/yyyy"
disabled="#{visitMB.flag}"
mindate="#{visitPatientMB2.actualDate}"
required="true"/>
<p:outputLabel
value="Specjalizacja"></p:outputLabel>
<p:selectOneMenu id="specialization"
value="#{visitPatientMB2.user.specializationId}"
effect="fade" style="width:200px"
converter="#{specializationConverter}">
<f:selectItems
value="#{visitPatientMB2.allSpecialization}"
var="specialization"
itemValue="#{specialization}"
itemLabel="#{specialization.name}"/>
</p:selectOneMenu>
<center><p:commandButton
action="#{visitPatientMB2.searchStart()}"
value="Szukaj" /></center>
</p:panelGrid>
</p:panel>
</form>
this page causes method: visitPatientMB2.searchStart()
VisitPatientMB2 RequestBean:
@ManagedBean
@RequestScoped
public class VisitPatientMB2 {
@EJB
private VisitDaoLocal visitDao;
@EJB
private SpecializationDaoLocal specializationDao;
@EJB
private UserDaoLocal userDao;
private Specialization specialization;
private Visit visit;
private User user;
private Date actualDate = new Date();
private Date start;
private Date end;
private boolean flag = true;
private Integer myId;
public VisitPatientMB2() {
}
public void enableCalendar() {
if (start != null) {
flag = false;
}
}
public String searchStart() {
System.out.println("SEARCH START");
if (start.after(end)) {
sendErrorMessageToUser("Data zakoñczenie nie mo¿e byæ
wczeœniejsza ni¿ rozpoczêcia");
return null;
}
if (start.before(actualDate)) {
sendErrorMessageToUser("Data wizyty nie mo¿e byæ wczeœniejsza
ni¿ aktualna data");
return null;
}
return "searchStart";
}
public String visitRegister() {
System.out.println("visitRegister");
myId = (Integer) session.getAttribute("myId");
visit.setPatientId(userDao.find(myId));
try {
visitDao.update(visit);
sendInfoMessageToUser("Wizyta zosta³a dodana");
return "addVisit";
} catch (EJBException e) {
sendErrorMessageToUser("B³¹d zapisu na wizyte do bazy");
return null;
}
}
public List<Visit> getVisitFound() {
System.out.println("start" + start);
System.out.println("end" + end);
System.out.println("name" + user.getSpecializationId().getName());
myId = (Integer) session.getAttribute("myId");
return visitDao.visitSearch(start, end,
user.getSpecializationId().getName(), myId);
}
public List<Specialization> getAllSpecialization() {
return specializationDao.findAllSpecialization();
}
Method return searchStart and go to page searchResult, no redirect
<navigation-rule>
<from-view-id>/protected/patient/visitSearch.xhtml</from-view-id>
<navigation-case>
<from-outcome>home</from-outcome>
<to-view-id>/protected/patient/home.xhtml</to-view-id>
<redirect/>
</navigation-case>
<navigation-case>
<from-outcome>about</from-outcome>
<to-view-id>/protected/patient/about.xhtml</to-view-id>
<redirect/>
</navigation-case>
<navigation-case>
<from-outcome>gallery</from-outcome>
<to-view-id>/protected/patient/gallery.xhtml</to-view-id>
<redirect/>
</navigation-case>
<navigation-case>
<from-outcome>contact</from-outcome>
<to-view-id>/protected/patient/contact.xhtml</to-view-id>
<redirect/>
</navigation-case>
<navigation-case>
<from-outcome>myAccount</from-outcome>
<to-view-id>/protected/patient/patientPanel.xhtml</to-view-id>
<redirect/>
</navigation-case>
<navigation-case>
<from-outcome>visitList</from-outcome>
<to-view-id>/protected/patient/myVisits.xhtml</to-view-id>
<redirect/>
</navigation-case>
<navigation-case>
<from-outcome>visitRegister</from-outcome>
<to-view-id>/protected/patient/visitRegister.xhtml</to-view-id>
<redirect/>
</navigation-case>
<navigation-case>
<from-outcome>visitSearch</from-outcome>
<to-view-id>/protected/patient/visitSearch.xhtml</to-view-id>
<redirect/>
</navigation-case>
<navigation-case>
<from-outcome>history</from-outcome>
<to-view-id>/protected/patient/myHistory.xhtml</to-view-id>
<redirect/>
</navigation-case>
<navigation-case>
<from-outcome>logout</from-outcome>
<to-view-id>/home.xhtml</to-view-id>
<redirect/>
</navigation-case>
<navigation-case>
<from-outcome>editMyAccount</from-outcome>
<to-view-id>/protected/patient/myAccount.xhtml</to-view-id>
<redirect/>
</navigation-case>
<navigation-case>
<from-outcome>searchStart</from-outcome>
<to-view-id>/protected/patient/searchResult.xhtml</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>addVisit</from-outcome>
<to-view-id>/protected/patient/home.xhtml</to-view-id>
<redirect/>
</navigation-case>
</navigation-rule>
and when I in the page searchResult i click save to visit and run the
method visitPatientMB2.visitRegister() but I have a error...
WARNING: /protected/patient/searchResult.xhtml @55,227
value="#{visitPatientMB2.visitFound}": java.lang.NullPointerException
javax.el.ELException: /protected/patient/searchResult.xhtml @55,227
value="#{visitPatientMB2.visitFound}": java.lang.NullPointerException
at
com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:114)
at
javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
at
javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
at javax.faces.component.UIData.getValue(UIData.java:731)
at
org.primefaces.component.datatable.DataTable.getValue(DataTable.java:867)
at org.primefaces.component.api.UIData.getDataModel(UIData.java:579)
at org.primefaces.component.api.UIData.setRowModel(UIData.java:409)
at org.primefaces.component.api.UIData.setRowIndex(UIData.java:401)
at org.primefaces.component.api.UIData.processPhase(UIData.java:258)
at org.primefaces.component.api.UIData.processDecodes(UIData.java:227)
at javax.faces.component.UIForm.processDecodes(UIForm.java:225)
at
javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1176)
at
javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1176)
at javax.faces.component.UIViewRoot.processDecodes(UIViewRoot.java:933)
at
com.sun.faces.lifecycle.ApplyRequestValuesPhase.execute(ApplyRequestValuesPhase.java:78)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at
org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at pl.ePrzychodnia.filter.FilterLogin.doFilter(FilterLogin.java:49)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
at
org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at
com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
at
com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at
com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
at
com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
at
com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at
com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at
com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at
com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at
com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at
com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at
com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at
com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.NullPointerException
at
pl.ePrzychodnia.mb.VisitPatientMB2.getVisitFound(VisitPatientMB2.java:215)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:363)
at
com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at
com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at com.sun.el.parser.AstValue.getValue(AstValue.java:138)
at com.sun.el.parser.AstValue.getValue(AstValue.java:183)
at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:224)
at
com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
... 46 more
Why i have null? I not redirect page, my bean is a request, why filed is
null?
I set in the method:
public List<Visit> getVisitFound() {
System.out.println("start" + start);
System.out.println("end" + end);
System.out.println("name" + user.getSpecializationId().getName());
myId = (Integer) session.getAttribute("myId");
return visitDao.visitSearch(start, end,
user.getSpecializationId().getName(), myId);
}
and I see, when i go the page search result. This method is invoked twice.
Why?
And when I run visitPatientMB2.visitRegister() in page searchResult method
starts the third time... This time fields have null. Example:
INFO: startSun Sep 01 00:00:00 CEST 2013
INFO: endSun Sep 29 00:00:00 CEST 2013
INFO: nameKardiolog
INFO: startSun Sep 01 00:00:00 CEST 2013
INFO: endSun Sep 29 00:00:00 CEST 2013
INFO: nameKardiolog
INFO: startnull
INFO: endnull
WARNING: /protected/patient/searchResult.xhtml @55,227
value="#{visitPatientMB2.visitFound}": java.lang.NullPointerException

MySQL select daterange data from two coloms

MySQL select daterange data from two coloms

This is my tables
ut_period
id | month | year | name
1 | 9 | 2013 | dddd
2 | 2 | 2017 | eeee
I want select rows witch in 2013-8 and 2018-9. So i wrote following query.
But it is not successful.
SELECT * FROM `ut_period` p
WHERE `p`.`status` = 4
AND `p`.`year` >= '2013'
AND `p`.`mont` >= '8'
AND `p`.`year` <= '2018'
AND `p`.`month` <= '9'
How can i do it?

Find member of set with minimizing total distance property

Find member of set with minimizing total distance property

I'm looking for efficient solution of following problem: For given set of
points in n-dimensional euclidian space find such member of this set that
minimizes total distance to other points in set.
The obvious naïve approach is quadratic, so I'm looking for something less
than quadratic.
My first thought was that all I need is just to find the center of
bounding sphere and then, find the closest point in set to this point. But
this is actually not true, imagine right triangle - all its vertices are
equidistant from such center, nevertheless, exactly one vertice meets our
requirements.
It would be nice it one will shed some light on this issue.

Friday, 30 August 2013

Any alternatives or ways to make this script faster?

Any alternatives or ways to make this script faster?

I have this script which displays the terminal type being used. So for
instance if you were running konsole it would display konsole. The script
needs to go into another program that runs when a terminal is opened so it
has to be very fast. Here's what I have so far
#!/bin/bash
shopt -s extglob
SHELLTTY=$(exec ps -p "$$" -o tty=)
P=$$
while read P < <(exec ps -p "$P" -o ppid=) && [[ $P == +([[:digit:]]) ]]; do
if read T < <(exec ps -p "$P" -o tty=) && [[ $T != "$SHELLTTY" ]]; then
ps -p "$P" -o comm=
break
fi
done
When the script is saved into a file it takes this long for it to run.
[~]$ time ./termgrab
konsole
real 0m0.063s
user 0m0.017s
sys 0m0.040s
The whole program itself takes .04 seconds so this slows it down
considerably. Does anyone have any suggestions to make the script any
faster or any alternative ways to achieve the same thing?

Thursday, 29 August 2013

Taking the count of number of 'table' tags using jquery

Taking the count of number of 'table' tags using jquery

This is my HTML code

<div class="tableStyle myWebsiteTable">
<table cellspacing="0" cellpadding="0" id="site0" class="site active">
<thead>
<tr>
</tr>
</thead>
<tbody>
<tr class="websiteDetails">
<td colspan="5">
<div id="websiteDetails0" class="divWebsiteDetails"
style="display: block;">
<table>
<tbody>
<tr id="190">
<td>index</td>
<td></td>
<td></td>
</tr>
<tr class="addPage">
<td align="center" colspan="5"></td>
</tr>
</tbody>
</table>
</div>
</td>
</tr><!--Website Details-->
</tbody>
</table>
<table id="addNewSiteTable">
<thead>
<tr>
</tr>
</thead>
</table>
</div>`<br/>
Now table get added dynamically to this structure.I want to write some
logic based on the no of table inside the first div.I tried doing this but
did not work $('myWebsiteTable').children('table').length)
PLease suggest the correct way to achieve it Thank you

lightswitch deployment in VS 2012

lightswitch deployment in VS 2012

I have created a lightswitch extension using VS 2012 say project name as
SampleLSExtension. Builded the created lightswitch project.
Then, instead of installing SampleLSExtension.vsix file i have shipped
SampleLSExtension.lspkg and extension.vsixmanifest file to the following
location.
*C:\Program Files (x86)\Microsoft Visual Studio
11.0\Common7\IDE\Extensions{Company Name}{Control Name}{Version}*. After
this i opened VS 2012 and checked, this extension is not configured VS
2012. I am not able to see my extension in Extension manager {Tools->
Extension manager and updates}.
While installing SampleLSExtension.vsix file it is configured in VS 2012.
Whether my way is correct or not? Could you please tell anyone, where i
did the mistake? Is any further settings needed for configuring this in VS
IDE?

Vb.net Exporting Richtextbox formated content to Excel Cell

Vb.net Exporting Richtextbox formated content to Excel Cell

Further to my first question regarding that issue, here are my progress:
First : using the function: sheet.Cells(X, X).Value = RichTextBox1.Rtf, I
find this kind of cell content:
"rtf1\ansi\ansicpg1252\deff0\deflang1036\deflangfe1036{\fonttbl{\f0\fswiss\fprq2\fcharset0
Calibri;}{\f1\fnil\fcharset0 Calibri;}{\f2\froman\fprq2\fcharset0 Times
New Roman;}} {\colortbl ;\red255\green0\blue0;\red0\green0\blue139;}
\viewkind4\uc1\pard\f0\fs22 XXXXXXXXXXX\par \cf1\strike\f1
XXXXXXXXXXX\par"
I can however manually use the excel function "keep the original
formatting" to paste some rtf doc content into a cell.
Could you help me find a way to use this function in the VB.net code if
possible?
Thanks.