ClassCastException on JBoss deploy - exception

EDIT: When renaming ProfileService.class to ProfileService2.class, it worked... Name clash somewhere?
When trying to deploy my application, I get the following exception:
2012-03-20 11:38:51,433 ERROR [org.jboss.kernel.plugins.dependency.AbstractKernelController] (HDScanner) Error installing to Start: name=jboss.j2ee:jar=career-portal.war,name=ProfileService,service=EJB3,type=nointerface-view-jndi-binder state=Create: java.lang.ClassCastException: org.jboss.aop.generatedproxies.AOPProxy$2 cannot be cast to javax.naming.Context
at org.jboss.util.naming.Util.createSubcontext(Util.java:70) [jboss-common-core.jar:2.2.17.GA]
at org.jboss.util.naming.NonSerializableFactory.rebind(NonSerializableFactory.java:222) [jboss-common-core.jar:2.2.17.GA]
at org.jboss.ejb3.nointerface.impl.jndi.SessionlessBeanNoInterfaceViewBinder.bind(SessionlessBeanNoInterfaceViewBinder.java:91) [:6.0.0.Final]
at org.jboss.ejb3.nointerface.impl.jndi.AbstractNoInterfaceViewBinder.start(AbstractNoInterfaceViewBinder.java:77) [:6.0.0.Final]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_24]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [:1.6.0_24]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [:1.6.0_24]
at java.lang.reflect.Method.invoke(Method.java:597) [:1.6.0_24]
at org.jboss.reflect.plugins.introspection.ReflectionUtils.invoke(ReflectionUtils.java:60) [jboss-reflect.jar:2.2.0.GA]
at org.jboss.reflect.plugins.introspection.ReflectMethodInfoImpl.invoke(ReflectMethodInfoImpl.java:168) [jboss-reflect.jar:2.2.0.GA]
at org.jboss.joinpoint.plugins.BasicMethodJoinPoint.dispatch(BasicMethodJoinPoint.java:66) [jboss-reflect.jar:2.2.0.GA]
at org.jboss.kernel.plugins.dependency.KernelControllerContextAction$JoinpointDispatchWrapper.execute(KernelControllerContextAction.java:257) [jboss-kernel.jar:2.2.0.GA]
at org.jboss.kernel.plugins.dependency.ExecutionWrapper.execute(ExecutionWrapper.java:47) [jboss-kernel.jar:2.2.0.GA]
at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.dispatchExecutionWrapper(KernelControllerContextAction.java:125) [jboss-kernel.jar:2.2.0.GA]
at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.dispatchJoinPoint(KernelControllerContextAction.java:72) [jboss-kernel.jar:2.2.0.GA]
at org.jboss.kernel.plugins.dependency.LifecycleAction.installActionInternal(LifecycleAction.java:202) [jboss-kernel.jar:2.2.0.GA]
at org.jboss.kernel.plugins.dependency.InstallsAwareAction.installAction(InstallsAwareAction.java:54) [jboss-kernel.jar:2.2.0.GA]
at org.jboss.kernel.plugins.dependency.InstallsAwareAction.installAction(InstallsAwareAction.java:42) [jboss-kernel.jar:2.2.0.GA]
at org.jboss.dependency.plugins.action.SimpleControllerContextAction.simpleInstallAction(SimpleControllerContextAction.java:62) [jboss-dependency.jar:2.2.0.GA]
at org.jboss.dependency.plugins.action.AccessControllerContextAction.install(AccessControllerContextAction.java:71) [jboss-dependency.jar:2.2.0.GA]
at org.jboss.dependency.plugins.AbstractControllerContextActions.install(AbstractControllerContextActions.java:51) [jboss-dependency.jar:2.2.0.GA]
at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:379) [jboss-dependency.jar:2.2.0.GA]
at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:2044) [jboss-dependency.jar:2.2.0.GA]
at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:1083) [jboss-dependency.jar:2.2.0.GA]
at org.jboss.dependency.plugins.AbstractController.executeOrIncrementStateDirectly(AbstractController.java:1322) [jboss-dependency.jar:2.2.0.GA]
at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1246) [jboss-dependency.jar:2.2.0.GA]
at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1139) [jboss-dependency.jar:2.2.0.GA]
at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:939) [jboss-dependency.jar:2.2.0.GA]
at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:654) [jboss-dependency.jar:2.2.0.GA]
at org.jboss.deployers.plugins.deployers.DeployersImpl.change(DeployersImpl.java:1983) [:2.2.0.GA]
at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployersImpl.java:1076) [:2.2.0.GA]
at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:679) [:2.2.0.GA]
at org.jboss.system.server.profileservice.deployers.MainDeployerPlugin.process(MainDeployerPlugin.java:106) [:6.0.0.Final]
at org.jboss.profileservice.dependency.ProfileControllerContext$DelegateDeployer.process(ProfileControllerContext.java:143) [:0.2.2]
at org.jboss.profileservice.deployment.hotdeploy.HDScanner$HDScanAction.deploy(HDScanner.java:240) [:0.2.2]
at org.jboss.profileservice.deployment.hotdeploy.HDScanner$HDScanAction.complete(HDScanner.java:192) [:0.2.2]
at org.jboss.profileservice.management.TwoPCActionWrapper.doComplete(TwoPCActionWrapper.java:57) [:0.2.2]
at org.jboss.profileservice.management.actions.AbstractTwoPhaseModificationAction.complete(AbstractTwoPhaseModificationAction.java:74) [:0.2.2]
at org.jboss.profileservice.management.actions.AbstractTwoPhaseModificationAction.prepare(AbstractTwoPhaseModificationAction.java:95) [:0.2.2]
at org.jboss.profileservice.management.ModificationSession.prepare(ModificationSession.java:87) [:0.2.2]
at org.jboss.profileservice.management.AbstractActionController.internalPerfom(AbstractActionController.java:234) [:0.2.2]
at org.jboss.profileservice.management.AbstractActionController.performWrite(AbstractActionController.java:213) [:0.2.2]
at org.jboss.profileservice.management.AbstractActionController.perform(AbstractActionController.java:150) [:0.2.2]
at org.jboss.profileservice.management.AbstractActionController.perform(AbstractActionController.java:135) [:0.2.2]
at org.jboss.profileservice.deployment.hotdeploy.HDScanner.scan(HDScanner.java:146) [:0.2.2]
at org.jboss.profileservice.deployment.hotdeploy.HDScanner.run(HDScanner.java:90) [:0.2.2]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441) [:1.6.0_24]
at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317) [:1.6.0_24]
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150) [:1.6.0_24]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98) [:1.6.0_24]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:180) [:1.6.0_24]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:204) [:1.6.0_24]
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_24]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_24]
at java.lang.Thread.run(Thread.java:662) [:1.6.0_24]
ProfileService.java
package com.xdin.competence.service;
import com.xdin.competence.dao.ProfileDAO;
import com.xdin.competence.dao.UserDAO;
import com.xdin.competence.entities.User;
import com.xdin.competence.entities.competence.*;
import com.xdin.competence.tree.ProfileCompetenceTreeNode;
import org.apache.log4j.Logger;
import org.primefaces.model.TreeNode;
import javax.ejb.Stateless;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.List;
#Stateless
public class ProfileService {
private static final Logger log = Logger.getLogger(ProfileService.class.getName());
#Inject private ProfileDAO profileDAO;
#Inject private UserDAO userDAO;
public ProfileService() {
}
public User saveCompetenceProfile(User user, Template template, List<TreeNode> trees, List<CustomCompetence> customCompetences, String comment) {
Profile p = new Profile(user, template);
for(TreeNode node : trees){
p.getProfileCompetences().addAll(getProfileCompetencesFromTree(node, p));
}
p.setUserComment(comment);
for(CustomCompetence cc : customCompetences){
cc.setProfile(p);
}
p.setCustomCompetences(customCompetences);
profileDAO.create(p);
user.setActiveCompetenceProfile(p);
return userDAO.save(user);
}
private List<ProfileCompetence> getProfileCompetencesFromTree(TreeNode root, Profile parent){
// Add profileCompetences
ArrayList<ProfileCompetence> pcList = new ArrayList<ProfileCompetence>();
for(TreeNode group : root.getChildren()){
for(TreeNode pcNode : group.getChildren()){
ProfileCompetence pc = ((ProfileCompetenceTreeNode)pcNode.getData()).getPc();
if(pc.getLevel() > 0 || (pc.getLevelGoal() != null && pc.getLevelGoal() > 0) || (pc.getComments() != null && !pc.getComments().isEmpty())){
pc.setProfile(parent);
pcList.add(pc);
}
}
}
return pcList;
}
}
As you can see, nothing is weird with ProfileService, just a very normal session bean. It's also worth to mention that I can still use the application, regardless of the exception.
What could be the cause?
Using JBoss 6 with Weld.

Seems like a bug in JBoss, Naming a class ProfileService was apparently not allowed. Renaming the class solved the problem.

Related

How to Update a record in spring boot and mysql

I am a newbie to spring boot.I have created a crud operation and the insert operation is working properly. I have a challenge on the update operation , the program is giving an error on the web page
Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback.Wed Jul 22 20:39:03 CAT 2020 There was an unexpected error (type=Bad Request, status=400)
and the following error from the console
Resolved [org.springframework.web.method.annotation.MethodArgumentTypeMismatchException: Failed to convert value of type 'java.lang.String' to required type 'long'; nested exception is java.lang.NumberFormatException: For input string: "saveEmployee"]
how can I solve the problem?
my code is below
Controller Class
```
package com.zimprogrammer.springboot.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import com.zimprogrammer.springboot.model.Employee;
import com.zimprogrammer.springboot.service.EmployeeService;
#Controller
public class EmployeeController {
#Autowired
private EmployeeService employeeService;
#GetMapping("/")
public String vieHomePage(Model model) {
// this shows a list of employees
model.addAttribute("listEmployees", employeeService.getAllEmployees());
return "index";
}
#GetMapping("/showEmployeeForm")
public String showEmployeeForm(Model model){
//request for the form to enter the data
Employee employee =new Employee();
model.addAttribute("employee", employee);
return "new_employee";
}
#PostMapping("/saveEmployee")
public String saveEmployee(#ModelAttribute("employee") Employee employee) {
//save data to the database
employeeService.saveEmployee(employee);
return "redirect:/";
}
#GetMapping("/showFormForUpdate/{id}")
public String showFormForUpdate(#PathVariable( value="id") long id, Model model) {
//get the employee from the service
Employee employee =employeeService.getEmployeeById(id);
// set the employee to pre-populate the form
model.addAttribute("employee", employee);
return "update_employee";
}
}```
Employee Service Interface
```package com.zimprogrammer.springboot.service;
import java.util.List;
import com.zimprogrammer.springboot.model.Employee;
public interface EmployeeService {
List<Employee> getAllEmployees();
void saveEmployee(Employee employee);
Employee getEmployeeById(long id);
}
```
Employee Service Class
```
package com.zimprogrammer.springboot.service;
import java.util.List;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zimprogrammer.springboot.model.Employee;
import com.zimprogrammer.springboot.repository.EmployeeRepository;
#Service
public class EmployeeServiceImpl implements EmployeeService{
#Autowired
private EmployeeRepository employeeRepository;
#Override
public List<Employee> getAllEmployees() {
return employeeRepository.findAll();
}
#Override
public void saveEmployee(Employee employee) {
this.employeeRepository.save(employee);
}
#Override
public Employee getEmployeeById(long id) {
Optional<Employee> optional=employeeRepository.findById(id);
Employee employee=null;
if(optional.isPresent()) {
employee=optional.get();
}else {
throw new RuntimeException("User not found for id::" + id);
}
return employee;
}
}
```
Employee Repository Interface
```
package com.zimprogrammer.springboot.repository;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import com.zimprogrammer.springboot.model.Employee;
#Repository
public interface EmployeeRepository extends JpaRepository<Employee, Long>{
}
```
Update Form : Thymeleaf and bootstrap
```
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="ISO-8859-1">
<title>Employee Management System</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</head>
<body>
<div class="container" style="width:40%; height:40%;">
<h1>Employee Management system</h1>
<hr>
<h2>Update Employee</h2>
<form action="#" th:action="#{saveEmployee}" th:object="${employee}"
method="POST">
<input type="hidden" th:field="*{id}" />
<input type="text" th:field="*{firstName}"
class="form-control mb-4 col-4">
<input type="text" th:field="*{lastName}"
class="form-control mb-4 col-4">
<input type="text" th:field="*{email}"
class="form-control mb-4 col-4">
<button type="submit" class="btn btn-info col-2">Update
Employee</button>
</form>
<hr>
<a th:href = "#{/}"> Back to Employee List</a>
</div>
</body>
</html>
```
Can you also post you entity class?
From the error it is telling that the required type is long but it is getting it as string? It may be possible that you have mentioned your id as string instead of long.
Also try to add th:action="#{/saveEmployee}" to be exact as that of your /saveEmployee endpoint
Add "/" in form th:action, like so -> th:action="#{/saveEmployee}"
Also check your crud repository, insted of long use Long.
I solved the problem
I added a / to make th:action="#{/saveEmployee}" and changed long to Long in my controller Class in the following request
#GetMapping("/showFormForUpdate/{id}")
public String showFormForUpdate(#PathVariable( value="id") Long id, Model model) {
//get the employee from the service
Employee employee =employeeService.getEmployeeById(id);
// set the employee to pre-populate the form
model.addAttribute("employee", employee);
return "update_employee";
}
and this solved the problem

If using formGroup in angular 6 some errors are showing

By using this in reactive forms
<form #branchForm [formGroup]='branchForm'>
I got some errors as
Error: Uncaught (in promise): Error: Template parse errors:
Can't bind to 'formGroup' since it isn't a known property of 'form'. ("
<div class="box">
<div class="box-body">
<form #branchForm [ERROR ->][formGroup]='branchForm'>
<div class="row">
<div class="form-group" [ngClass]="): ng:///BranchManagementRoutingModule/BranchManagementComponent.html#63:26
Error: Template parse errors:
Can't bind to 'formGroup' since it isn't a known property of 'form'. ("
<div class="box">
<div class="box-body">
<form #branchForm [ERROR ->][formGroup]='branchForm'>
<div class="row">
<div class="form-group" [ngClass]="): ng:///BranchManagementRoutingModule/BranchManagementComponent.html#63:26
at syntaxError (compiler.js:1021)
at TemplateParser.push../node_modules/#angular/compiler/fesm5/compiler.js.TemplateParser.parse (compiler.js:14830)
at JitCompiler.push../node_modules/#angular/compiler/fesm5/compiler.js.JitCompiler._parseTemplate (compiler.js:24018)
at JitCompiler.push../node_modules/#angular/compiler/fesm5/compiler.js.JitCompiler._compileTemplate (compiler.js:24005)
at compiler.js:23948
at Set.forEach (<anonymous>)
at JitCompiler.push../node_modules/#angular/compiler/fesm5/compiler.js.JitCompiler._compileComponents (compiler.js:23948)
at compiler.js:23858
at Object.then (compiler.js:1012)
at JitCompiler.push../node_modules/#angular/compiler/fesm5/compiler.js.JitCompiler._compileModuleAndComponents (compiler.js:23857)
at syntaxError (compiler.js:1021)
at TemplateParser.push../node_modules/#angular/compiler/fesm5/compiler.js.TemplateParser.parse (compiler.js:14830)
at JitCompiler.push../node_modules/#angular/compiler/fesm5/compiler.js.JitCompiler._parseTemplate (compiler.js:24018)
at JitCompiler.push../node_modules/#angular/compiler/fesm5/compiler.js.JitCompiler._compileTemplate (compiler.js:24005)
at compiler.js:23948
at Set.forEach (<anonymous>)
at JitCompiler.push../node_modules/#angular/compiler/fesm5/compiler.js.JitCompiler._compileComponents (compiler.js:23948)
at compiler.js:23858
at Object.then (compiler.js:1012)
at JitCompiler.push../node_modules/#angular/compiler/fesm5/compiler.js.JitCompiler._compileModuleAndComponents (compiler.js:23857)
at resolvePromise (zone.js:814)
at resolvePromise (zone.js:771)
at zone.js:873
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:421)
at Object.onInvokeTask (core.js:3811)
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:420)
at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:188)
at drainMicroTaskQueue (zone.js:595)
I have imported all the necessary modules such as ReactiveFormsModule,Fromgroup etc
import { FormsModule, ReactiveFormsModule } from '#angular/forms';
and included these in imports also
import ReactiveFormsModule from #angular/formsĀ 
Is needed to be imported into your components module and added to your imports as well.
import { ReactiveFormsModule } from '#angular/forms';
#NgModule({
imports: [
// other imports ...
ReactiveFormsModule
],
})
export class AppModule { }
To fix this error, you just need to import ReactiveFormsModule from #angular/forms in your module.

Getting NPE while redirecting to the same JSP page after submitting a form

After submitting a form on the profile page it goes to the controller where it then updates a database to then redirect back to the same page that the form was on. However i get an error trying to return to the same page. I can however redirect to another page without any issues?
Any help would be great.
The Form
<form action="controller" method="post">
Link Name:<br>
<input type="text" name="createLinkName">
<br>
Link Content:<br>
<input type="text" name="createLinkContent">
<br>
<input type="hidden" name="command" value="createLink" />
<input type="submit" value="Submit">
</form>
Catching The Form Request
else if (command.equals("createLink"))
{
String linkName = request.getParameter("createLinkName");
String linkContent = request.getParameter("createLinkContent");
User sessionU = new User();
sessionU = (User)request.getSession().getAttribute("user");
int userID = sessionU.getId();
System.out.println(userID);
createLink(request, response, linkName, linkContent, userID);
}
createLink()
protected void createLink(HttpServletRequest request, HttpServletResponse response, String name, String content, int userID) throws IOException, ServletException
{
profileHandler ph = new profileHandler();
ph.createLink(request, response, name, content, userID);
request.getRequestDispatcher("profilePage.jsp").forward(request, response);
}
Handler that deals with the sql
public class profileHandler {
private final DatabaseManager dbMgr;
public profileHandler()
{
this.dbMgr = new DatabaseManager();
}
public void createLink(HttpServletRequest request, HttpServletResponse response, String name, String content, int userID)
{
dbMgr.establishConnection();
String CREATE_LINK = "INSERT INTO linkedaccounts (linkname, linkaddress, userid) VALUES ('" + name + "', '" + content + "', " + userID + ")";
dbMgr.prepareStatement(CREATE_LINK);
dbMgr.executePreparedStatement();
dbMgr.releaseConnection();
}
There isn't a problem with the sql as it is updated the Database just fine. Just wont allow me to eith stay on the same page as the form or just redirect back to it!
Thanks Again.
edit-
ERROR LOG:
Warning: StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
at org.apache.jsp.profilePage_jsp._jspService(profilePage_jsp.java:66)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
at java.lang.Thread.run(Thread.java:745)

Select tag always returns null

I am trying to create a search module to search shop details from database based on the criteria in select that user chooses
index.scala.html
#import helper._
#import helper.twitterBootstrap._
#main(Html("Home")) {
<!-- Main component for a primary marketing message or call to action -->
<div class="jumbotron">
<h1>Shop Directory</h1>
<p>Lets you search a nearby Shop and get to know their location</p>
<p>Search Shop by Product or Shop name</p>
<form class="form-inline" action="#routes.SearchController.search()" method="post">
<input type="text" class="form-inline input-lg" placeholder="Product/Shop name" name="keyword" required="keyword required">
<select class="form-inline input-lg" id="Select1" name="criteria">
<option value="">-:Select Criteria:- </option>
<option value="shop">Shop</option>
<option value="product">Product</option>
</select>
<button class="btn btn-lg btn-primary" role="button">Search</button>
</form>
</div>
}
Search.java
package viewmodels;
public class Search {
public String keyword;
public String criteria;
}
SearchResult.java
package viewmodels;
import models.Shop;
import play.mvc.Controller;
import java.util.ArrayList;
import java.util.List;
public class SearchResult extends Controller {
public String criteria;
public String keyword;
public List<Shop> shops;
public SearchResult() {
shops = new ArrayList();
}
}
SearchController.java
package controllers;
import models.Product;
import models.Shop;
import play.data.DynamicForm;
import play.data.Form;
import play.mvc.Controller;
import viewmodels.Search;
import viewmodels.SearchResult;
import java.util.List;
import play.mvc.Result;
import static play.data.Form.*;
public class SearchController extends Controller {
public static Result search() {
Form<Search> requestData = form(Search.class).bindFromRequest();
Search datatosearch = requestData.get();
// String criteria="shop";
String criteria = datatosearch.criteria;
SearchResult result = new SearchResult();
result.criteria = criteria;
result.keyword = datatosearch.keyword;
if (criteria == "shop") {
List<Shop> shops = Shop.findByShopName(datatosearch.keyword);
result.shops.addAll(shops);
}
else if (criteria == "product") {
List<Shop> shops = Product.findByShopName(datatosearch.keyword);
result.shops.addAll(shops);
}
return ok(views.html.search.results.render(result));
}
}
if I do String criteria="shop" or String criteria="product" in my SearchController.java then it works fine, meaning my model query is correct, but if I execute the above code with String criteria = datatosearch.criteria it shows a blank screen.
I am using play framework, I am really stuck at this and any help would be appreciated.
You are comparing strings with the == operator which is a no-no. Change your string comparisons to use String.equals so you are actually comparing the values instead of object references.
if (criteria.equals("shop") {
...
}
else if (criteria.equals("product") {
...
}
You probably also want to add some validation to check that criteria isn't NULL.

Combine p:orderList with p:inplace

I would like to have a list of entries which I can shift/order and at the same time editable.
So I tought to combine p:orderList with p:inplace this way:
<p:scrollPanel style="width:300px;height:100px" scrollMode="native">
<p:orderList var="title" value="#{detailModel.afterObject.metadata.getTitlesAsList()}" type="definition">
<f:facet name="description">
<p:inplace id="basic" editor="true">
<p:inputText value="#{title.value}" required="true"/>
</p:inplace>
</f:facet>
</p:orderList>
</p:scrollPanel>
but I get the following error:
java.lang.NullPointerException
at org.primefaces.component.orderlist.OrderListRenderer.encodeOptions(OrderListRenderer.java:152)
at org.primefaces.component.orderlist.OrderListRenderer.encodeList(OrderListRenderer.java:108)
at org.primefaces.component.orderlist.OrderListRenderer.encodeMarkup(OrderListRenderer.java:79)
at org.primefaces.component.orderlist.OrderListRenderer.encodeEnd(OrderListRenderer.java:49)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:61)
at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:45)
at org.primefaces.component.scrollpanel.ScrollPanelRenderer.encodeMarkup(ScrollPanelRenderer.java:51)
at org.primefaces.component.scrollpanel.ScrollPanelRenderer.encodeEnd(ScrollPanelRenderer.java:30)
at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:312)
at com.sun.faces.renderkit.html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:105)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1757)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1757)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1760)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:402)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
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:849)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
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:619)
Do I miss something or it is not possible doing so?
If I use :dataList instead I don't get the error, but it has a strang behaviour; when I click on an entry, all the entries become editable, but then they remain in the edit-mode and nothing more is possibe...
Any suggestions?
EDIT
Here is the bean:
public class DoiDetailModel extends DetailModel
{
private List< String > selectedTitles;
private List< String > selectedCreators;
private String title;
private String creator;
public DoiDetailModel()
{
super();
}
public List< String > getSelectedTitles()
{
return selectedTitles;
}
public void setSelectedTitles( List< String > selectedTitles )
{
this.selectedTitles = selectedTitles;
}
}