Bean bean = (Bean) pageContext.getAttribute("bean", PageContext.REQUEST_SCOPE); if (bean == null) { bean = new Bean(); pageContext.setAttribute("bean", bean, PageContext.REQUEST_SCOPE); } // Use bean ...
if (bean == null) { bean = new Bean(); getServletContext().setAttribute("bean", bean); }
request.setAttribute("bean", new Bean()); request.getRequestDispatcher("page.jsp").forward(request, response);
HttpSession session = request.getSession(false); session == null ? null : session.setAttribute("<keyname>", new Bean());
ServletRequest request = ... // get the reference to the servlet request object request.setAttribute("<keyname>", new Bean());
Bean bean = new Bean(); StringProperty nameProperty() = new JavaBeanStringPropertyBuilder() .bean(bean) .name("name") .build(); nameProperty().addListener((obs, oldName, newName) -> System.out.println("name changed from "+oldName+" to "+newName)); bean.setName("James"); System.out.println(nameProperty().get());
@Produces(MediaType.APPLICATION_JSON) @JacksonFeatures(serializationEnable = { SerializationFeature.INDENT_OUTPUT }) public Bean resource() { return new Bean() }
/** * Create a Bean binding configuration. * * @param beanClass The bean runtime class. * @param beanId The bean ID. * @param createOnElement The element selector used to create the bean instance. * @param createOnElementNS The namespace for the element selector used to create the bean instance. */ public static Bean newBean(Class<?> beanClass, String beanId, String createOnElement, String createOnElementNS) { return new Bean(beanClass, beanId, createOnElement, createOnElementNS); }
/** * Create a Bean binding configuration. * * @param beanClass The bean runtime class. * @param beanId The bean ID. * @param createOnElement The element selector used to create the bean instance. * @param createOnElementNS The namespace for the element selector used to create the bean instance. */ public static Bean newBean(Class<?> beanClass, String beanId, String createOnElement, String createOnElementNS) { return new Bean(beanClass, beanId, createOnElement, createOnElementNS); }
public class MyServlet extends HttpServlet { private static Bean bean1 = new Bean(); // Certainly NOT threadsafe, there is only 1 of it during application's lifetime. private Bean bean2 = new Bean(); // This also NOT, because there's only 1 servlet in application's lifetime which is shared among all requests. protected void doSomething(request, response) { Bean bean3 = new Bean(); // Declared threadlocal, thus certainly threadsafe. request.setAttribute("bean", bean3); // 1 request = 1 thread, thus threadsafe. request.getSession().setAttribute("bean", bean3); // Session is shared among requests/threads from same client, thus NOT threadsafe. getServletContext().setAttribute("bean", bean3); // Context is shared among all sessions from different clients, thus certainly NOT threadsafe. } }
/** * Create a Bean binding configuration. * * @param beanClass The bean runtime class. * @param beanId The bean ID. * @param createOnElement The element selector used to create the bean instance. * @param createOnElementNS The namespace for the element selector used to create the bean instance. */ public static Bean newBean(Class<?> beanClass, String beanId, String createOnElement, String createOnElementNS) { return new Bean(beanClass, beanId, createOnElement, createOnElementNS); }
/** * Create a Bean binding configuration. * * @param beanClass The bean runtime class. * @param beanId The bean ID. * @param createOnElement The element selector used to create the bean instance. * @param createOnElementNS The namespace for the element selector used to create the bean instance. * @param factory The factory that will create the runtime object */ public static <T> Bean newBean(Class<T> beanClass, String beanId, String createOnElement, String createOnElementNS, Factory<T> factory) { return new Bean(beanClass, beanId, createOnElement, createOnElementNS, factory); }
public class DBTest extends AbstractTransactionalJUnit4SpringContextTests { @Autowired private SomeDAO _aBeanDefinedInMyContextFile; @Test public void insert_works() { assert _aBeanDefinedInMyContextFile.findAll() == 0; _aBeanDefinedInMyContextFile.save(new Bean()); assert _aBeanDefinedInMyContextFile.findAll() == 1; } }
ArrayList<Bean> mo1h = new ArrayList<Bean>(); subjectList.moveToFirst(); while(!subjectList.isAfterLast()) { Bean b = new Bean(); b.id = subjectList.getString(subjectList.getColumnIndex(dao.COLUMN_ID)); b.hour =subjectList.getString(subjectList.getColumnIndex(dao.COLUMN_HOUR)); ... ... // all your column mo1h.add(b); }
List<List<?>> body; List<Bean> beans=body.stream().map(row-> { Bean bean=new Bean(); for(int i=0, num=setters.size(); i<num; i++) setters.get(i).accept(bean, row.get(i)); return bean; }).collect(Collectors.toList());
ArrayList al = new ArrayList(); while(rs.next){ Bean b = new Bean(); b.col1(rs.getString(1)); b.col2(rs.getString(2)); if(rs.getString(3)) b.DT_RowClass = "class1"; else b.DT_RowClass = "class2"; al.add(b); }
DAO.deleteRows(); // so I'm inserting into an empty table long time = new Date().getTime(); for(int i=0; i<objectsArray.length()*50; i++){ JSONArray entry = (JSONArray) objectsArray.get(i%objectsArray.length()); Bean bean = new Bean(); bean.setStuff(entry.getInt(0)); // and so on... dao.addObject(bean); } long timeFinish = new Date().getTime(); long timeTotal = timeFinish - time;
private List<Bean> populateBeanList(List<Bean> myList, String[] descArray, String[] photoArray){ for(int i=0; i< descArray.length; i++){ Bean bean = new Bean(); bean.setText(descArray[i]); bean.setUrl(photoArray[i]); myList.Add(bean); } return myList; }
public class Main { public static void main(String[] args) { BeanRepository.putBean(1, new Bean("one")); ClassA a = new ClassA(1); ClassB b = new ClassB(1); a.test(); b.test(); } }
public static void main(String[] args) { Bean testbean = new Bean(); testbean.setName("test"); Rete engine = new Rete(); engine.defclass("bean", "Bean", null, false); engine.definstance("bean", testbean, false); engine.eval("(facts)"); }