javabeans

List<Map<String,Object>> to org.json.JSONObject?

故事扮演 提交于 2019-11-27 14:04:29
问题 List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); Map<String, Object> map = new HashMap<String, Object>(); map.put("abc", "123456"); map.put("def", "hmm"); list.add(map); JSONObject json = new JSONObject(list); try { System.err.println(json.toString(2)); } catch (JSONException e) { e.printStackTrace(); } What's wrong with this code? The output is: {"empty": false} 回答1: public String listmap_to_json_string(List<Map<String, Object>> list) { JSONArray json_arr=new JSONArray(

@PreDestroy never called on @ViewScoped

China☆狼群 提交于 2019-11-27 13:16:52
I have a @ViewScoped bean that has a method with an @PreDestroy annotation that should make sure some remote connections are closed. However, the method is not called when the user navigates away. Is there anything one can do wrong? Do I have to register anything anywhere in order to make it work? It's a simple public method ( void ) that throws no exception. I'm using JSF 2 (MyFaces) with Tomcat 7.0.12. Could it be a problem with Tomcat? UPDATE The @PostConstruct annotation works fine. BalusC This is a known issue and unfortunately not trivial to solve without letting all the navigation take

Spring - set a property only if the value is not null

梦想的初衷 提交于 2019-11-27 12:13:03
问题 When using Spring, is it possible to set a property only if the value passed is not null? Example: <bean name="myBean" class="some.Type"> <property name="abc" value="${some.param}"/> </bean> The behavior I'm looking for is: some.Type myBean = new some.Type(); if (${some.param} != null) myBean.setAbc(${some.param}); The reason I need this is since abc has a default value which I don't want to override with a null . And the Bean I am creating is not under my source control - so I cannot change

Easy way of populating Javabeans based on request parameters

你说的曾经没有我的故事 提交于 2019-11-27 09:18:06
I have a simple person class: package simpleApp.entities; public class Person { private String name; private String secondname; public void setSecondname(String cognome) { this.secondname = cognome; } public String getSecondname() { return secondname; } public void setName(String nome) { this.name = nome; } public String getName() { return name; } } and a simple html page: <html> <body> <form action="/simpleApp/person/" method="POST"> name: <input type="text" name="name"><br> second name: <input type="text" name="secondname"><br> <input type="submit"> </form> </body> </html> and a simple

How can I turn off extra logging?

这一生的挚爱 提交于 2019-11-27 07:02:08
问题 I have a Java service that uses Spring and CXF. The code is from a previous developer and I'm providing maintenance, but I'm seeing this in the logs -------------------------------------- Apr 16, 2013 1:44:11 PM org.apache.cxf.interceptor.AbstractLoggingInterceptor log INFO: Inbound Message ---------------------------- ID: 33 Address: /MyApplication/endpoint Encoding: UTF-8 Http-Method: POST Content-Type: application/x-www-form-urlencoded Headers: {content-type=[application/x-www-form

Using a Stateful Session Bean to track an user's session

不问归期 提交于 2019-11-27 06:46:08
it's my first question here and I hope that I'm doing it right. I need to work on a Java EE project, so, before starting, I'm trying to do something simple and see if I can do that. I'm stuck with Stateful Session Beans . Here's the question : How can I use a SFSB to track an user's session? All the examples that I saw, ended up in "putting" the SFSB into a HttpSession attribute. But I don't understand why! I mean, if the bean is STATEFUL, why do I have to use the HttpSession to keep it? Isn't an EJB Container's task to return the right SFSB to the client? I've tried with a simple counter bean

Difference between managed bean and backing bean

夙愿已清 提交于 2019-11-27 06:43:24
I came across the terms "managed bean" and "backing bean" in several forums. Many people think both are the same. But, there seems to be a slight difference. Can any one help me to understand the exact difference between these two terms? Changing my initial answer - there is no meaningful difference between the two. The tutorial says that backing beans are later declared as managed beans. So, to summarize: a backing bean is the class out of context a managed bean is the backing bean whenever it is declared to be used with the JSF managed bean facility. I've never actually used the term

redirect from jsf?

和自甴很熟 提交于 2019-11-27 05:59:23
问题 I am working on application with jsp, jstl and jsf for my college project, thats being said, I am as well very new to jsf. Everything is going great so far. However, I seems to have a problem figuring out how to do redirect from managed bean to page with dinamyc parameters. For example article.jsp?article_id=2 Can somebody tell me how it is done ? I been trying to use somethinng like FacesContext.getCurrentInstance().getExternalContext().dispatch("faces/article.jsp2?article_id=" + articleId);

How do I print a list of strings contained within another list in iReport?

ぐ巨炮叔叔 提交于 2019-11-27 04:38:45
问题 I am creating a simple reporting program using java and iReport (from jasper), which is supposed to create a report in pdf showing PCs with their IP address, their location, whether it's idle or not at the moment (handled by another system), and a list of projects it is currently attached to (managed elsewhere, too). I'm using iReport for this matter, and have created a dummy collection generating class as follows: public class PCReports { public static java.util.Collection PC_collection;

ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/mail/MessagingException

跟風遠走 提交于 2019-11-27 04:31:18
I am getting a strange ClassFormatError when using the javaMail api to send email on my spring mvc web app. Below is my mail-cfg.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/mvc http://www.springframework