lundi 1 juin 2015

java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'usager' available as request attribute

I want to save the database in a new user, but I have this bean problem. I do not know what to do, here is the error

thank's for your help.

java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'usager' available as request attribute

Controller

@Controller
public class UsagerController {

    @Autowired
    private IUsagerMetier metierUsager;

    @RequestMapping(value="/usagers")
    public String usagers(Model model){
        return "usagers";
    }

    @RequestMapping(value="/nouvelUsager")
    public String nouvelUsager(Model model){
        return "nouvelUsager";
    }

    @RequestMapping(value="/addUsager")
    public String add(Usager U, Model model){

        model.addAttribute("usager" , new Usager());
        metierUsager.addUsager(U);
        return "nouvelUsager"; 
    }

}

Get the Ipaddresses of the machines on the same network

How to get the ipaddresses of machines on the same network. like IP Address Machine Name 192.168.129.111 AAA Machine 192.168.128.112 BBB Machine 192.168.128.113 CCC Machine

Please let me know if any of the open source jar supports.

What is the correct way to publish a message over JMS topic which has been injected in an EJB from a Netty event loop?

I have a @Singleton EJB which is started at @Startup, this bean listens to multicast traffic using netty. And what I would like to do is, on receipt of a message over multicast, send a JMS message on an injected topic (so on Wildfly, with JMS 2.0, I have the following:)

  @Resource(lookup = "java:/jboss/exported/jms/topic/appUpdates")
  private Topic appUpdate;

  @Inject
  private JMSContext context;

I know there are no problems with the topic and publishing a message if I have a @Scheduled function in the ejb, I can happily create a publisher and send a message. However attempt to publish JMS message from the netty event loop context results in:

2:10:34,441 ERROR [stderr] (nioEventLoopGroup-0-1) java.lang.RuntimeException: javax.naming.NameNotFoundException: java:comp/TransactionSynchronizationRegistry 12:10:34,441 ERROR [stderr] (nioEventLoopGroup-0-1) at org.jboss.as.messaging.deployment.JMSContextProducer$JMSContextWrapper.getDelegate(JMSContextProducer.java:217)

So my question is, what is the correct way to publish from the let's say non-jboss context (Netty event loop) to the JMS topic?

(Server: Wildfly 8.2.0.Final using standalone-full.xml config)

JPA Criteria Api - Not in relation entities query

I have a problem with building CriteriaQuery, to check not mapped entity in this relation.

@Entity
@Table(name="table1")
public class Entity1 {

    //Some attributes

    @Column
    private Integer entity2ID;

}

@Entity
@Table(name="table2")
public class Entity2 {

    private Integer id;

    //Some attributes

    @Column
    private Boolean value;

}

CriteriaBuilder code:

public Query buildSelectQuery(EntityManager em, Criteria c) {
    CriteriaBuilder cb = em.getCriteriaBuilder();

    ConcreteCriteria criteria = (ConcreteCriteria) c;

    CriteriaQuery<Entity1> cq = cb.createQuery(Entity1.class);
    Root<Entity1> entity1root = cq.from(Entity1.class);

    List<Predicate> predicates = buildPredicatesList(cb, entity1root, criteria); //other criteria in Entity1

    if (criteria.isValueIsNull() != null) {
        Root<Entity2> entity2root = cq.from(Entity2.class);
        predicates.add(cb.equal(entity1root.get("entity2ID"), entity2root.get("id")));
        predicates.add((criteria.isValueIsNull() ? cb.isNull(entity2root.get("value")) : cb.isNotNull(entity2root.get("value"))));
    }

    cq.where(predicates.toArray(new Predicate[predicates.size()]));

    return em.createQuery(cq);
}

criteria fails on validating. How can i build CriteriaQuery, without appending Entity2 to Entity1 in one to one relation?

NamedQuery resultList returning objects, but all values are null

I have a table in database with these columns:

   id serial NOT NULL, 
   name character varying(255) NOT NULL, 
   url character varying(255)

Netbeans generated the JPA Entity for me. I have 5 records in the database. When I do em.createNamedQuery("MyEntity.findAll").getResultList(); I get a List<MyEntity> with 5 entries, but when I do the following, nothing is returned:

for(MyEntity me : em.createNamedQuery("MyEntity.findAll").getResultList();){
    logger.warn(me.getName());
}

The Named query:

@NamedQuery(name = "MyEntity.findAll", query = "SELECT m FROM MyEntity m")

Output:

2015-06-01 11:23:27,024 WARN com.example.MyEntityBean (MyEntityBean.java:33) -
2015-06-01 11:23:27,034 WARN com.example.MyEntityBean (MyEntityBean.java:33) -
2015-06-01 11:23:27,045 WARN com.example.MyEntityBean (MyEntityBean.java:33) -
2015-06-01 11:23:27,055 WARN com.example.MyEntityBean (MyEntityBean.java:33) -
2015-06-01 11:23:27,066 WARN com.example.MyEntityBean (MyEntityBean.java:33) -

EDIT:

Added the NamedQuery

Failed to determine servlet: java.lang.NullPointerException at org.jboss.as.web.deployment.JBossContextConfig.beforeLoadOnStartup

I'm migrating a WebSphere application to JBoss EAP 6.4. During deployment, I get the below error:

Failed to determine servlet: java.lang.NullPointerException

With this stack trace:

12:48:06,194 DEBUG [org.jboss.as.security] (MSC service thread 1-2) Qualified url patterns: {/=PatternInfo[pattern=/,type=3,isOverridden=false,qualifiers=[]]}
12:48:06,194 FINE  [javax.enterprise.resource.webcontainer.jsf.config] (ServerService Thread Pool -- 132) ConfigureListener.contextInitialized(/scWeb)
12:48:06,224 DEBUG [org.jboss.as.web.security] (ServerService Thread Pool -- 96) Failed to determine servlet: java.lang.NullPointerException
    at org.jboss.as.web.deployment.JBossContextConfig.beforeLoadOnStartup(JBossContextConfig.java:666) [jboss-as-web-7.5.0.Final-redhat-21.jar:7.5.0.Final-redhat-21]
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:178) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]
    at org.jboss.as.web.deployment.JBossContextConfig.lifecycleEvent(JBossContextConfig.java:260) [jboss-as-web-7.5.0.Final-redhat-21.jar:7.5.0.Final-redhat-21]
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:115) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3592) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:3802) [jbossweb-7.5.7.Final-redhat-1.jar:7.5.7.Final-redhat-1]
    at org.jboss.as.web.deployment.WebDeploymentService.doStart(WebDeploymentService.java:163) [jboss-as-web-7.5.0.Final-redhat-21.jar:7.5.0.Final-redhat-21]
    at org.jboss.as.web.deployment.WebDeploymentService.access$000(WebDeploymentService.java:61) [jboss-as-web-7.5.0.Final-redhat-21.jar:7.5.0.Final-redhat-21]
    at org.jboss.as.web.deployment.WebDeploymentService$1.run(WebDeploymentService.java:96) [jboss-as-web-7.5.0.Final-redhat-21.jar:7.5.0.Final-redhat-21]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [rt.jar:1.8.0_45]
    at java.util.concurrent.FutureTask.run(Unknown Source) [rt.jar:1.8.0_45]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:1.8.0_45]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.8.0_45]
    at java.lang.Thread.run(Unknown Source) [rt.jar:1.8.0_45]
    at org.jboss.threads.JBossThread.run(JBossThread.java:122)

12:48:43,934 DEBUG [org.jboss.ejb.client.txn] (Periodic Recovery) Send recover request for transaction origin node identifier 1 to EJB receiver with node name inbaghpc00516
12:52:40,593 ERROR [org.jboss.as.controller.management-operation] (HttpManagementService-threads - 1) JBAS013412: Timeout after [300] seconds waiting for service container stability. Operation will roll back. Step that first updated the service container was 'deploy' at address '[("deployment" => "PCB-5.3.ear")]'

How is this caused and how can I solve it?

Java EE, Servlets, JSP, JSF Recommended ebook

I'll be learning Java EE soon at University. The module name will be Enterprise Application Development. I want to know which ebook is best for a beginner. Can anyone suggest me an ebook for Java Enterprise Apps which is free which is similar like that of Java Programming by Joyce Farell which contains exercises questions at the end of each chapter ?

Awaiting a positive reply. Thanks & Regards :)