JSF :: Request Scoped Action Beans

May 24, 2014

If I have the next request scoped JSF bean for example:

public class UserBean {
private String name;
private String surname;
public String saveUser(){
//service is called to save a user
}
public String updateUser(){
//service is called to update a user

[Code] ....

1.In struts for example the Action classes are singletons and I think is the way it has to be because they contain business logic and is the same logic for every user but in JSF because of you mix properties from a form and methods with business logic, these beans have to be request scoped like the above one but is very wierd that a bean which contains business logic(saveUser()....) be request scoped;I dont see it effective, is like creating a new servlet each time you want to save a user but I think is the way JSF works, right?

2 To avoid the mixing of form properties in a bean with business logic, some people say to have the form beans request scoped and actions beans session scoped.

- Is this right?
- How then can you get the request form bean in the action bean?
- The scopes in JSF are request, session and view so you cannot create singleton action beans, the best you can get is a session action bean, right?. Once again I dont see the point of creating action beans with session scoped,they should be application scoped if it existed

View Replies


ADVERTISEMENT

Servlets :: There Is No Action Mapped For Namespace And Action Name Associated

Nov 16, 2014

This is my first servlet program. I wanted to try a web application where "register" user module will be in servlet program.I can access my index.jsp but when I enter values and click submit.

I get "There is no Action mapped for namespace [/] and action name [RegisterUserServlet] associated with context path [/TrainingApplication]. - [unknown location]".

Here's my index.jsp file:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

[code]....

I am using apache-tomcat-8.0.14 server.

View Replies View Related

JSF :: Application Scoped Data Updating

Feb 18, 2015

I have an application scoped and i want to edit it from request scoped data. I use this code but application scoped data are not updating. What i am doing wrong?

Application Scoped Data

@ManagedBean
@ApplicationScoped
public class ApplicationData {
protected String contactEmail;
public String getContactEmail() {
return contactEmail;

[Code] ....

View Replies View Related

JSF :: How To Access Application Scoped Bean From A Scheduled Job

Mar 29, 2015

I am coming from a Seam 2 and ATG background, and working on re-writing an old Seam 2 application using JSF 2 on Tomcat 8. I've run into a snag:

I have an application scoped managed bean, let's call it EMail. It holds a collection of Email objects, and does some other stuff.

I have an IMAPClient, which is currently setup as an application scoped managed bean (mostly to simply configuration, etc...).

I need to call a method on the IMAPClient to go check email every X seconds (let's call it 60 seconds), and add any new email into the Email managed bean's collection of email. In Seam 2 this was easy with the @Asynchronous annotation. In JSF 2 I can't figure out how to do it. I've tried using Quartz, which will happily run my IMAPCheckJob every 60 seconds, but I am so far unable to figure out how the IMAPCheckJob can get access to either the IMAPClient or the EMail beans.. There's no dependency injection into the Quartz Job, and since it's not executing in a HTTP request flow, there's no Faces context available.

It seems like there has to be some way to allow for scheduling and still have access to the benefits of the Application scoped managed bean DI system...

Or do I need to give up and move to JBoss with EJBs and CDI instead of JSF beans?

View Replies View Related

Servlets :: GET HTTP Request Contain A Request Body?

Feb 25, 2014

I have the following questions:

1. Does a GET HTTP request contain a request body? If yes what is contained in it? Are the request headers also part of the request body?
2. Is it possible to send a byte array as part of the GET request in its body?
3. Is there a size limitation on the data that can be sent via a GET request?

View Replies View Related

JSF :: Persisting Beans In A Database

Apr 8, 2014

This is a general question about best practices for handling persisted data in JSF. My JSF page is going to have several fields that map to a managed bean. Upon a button click the fields of this bean are going to be persisted in a database. Is it better to use another bean with application scope to handle the JDBC code, or should I have a method in the bean itself to handle that? Similarly I'll need a method to retrieve the information upon a user request.

View Replies View Related

EJB / EE :: Session Beans Concurrency

Jan 13, 2015

I'm trying to understand the concurrent model of each EJB session bean types.

The singleton is well documented and seems clear to me... Only one instance and many threads using it but each method by default is synchronized because @Lock is defaulted to WRITE. We can let multiple threads use on method with @Lock(READ).

The stateless beans are in a pool I think I read somewhere that the container will ensure only one thread is using one instance at a time but this instances are recycled/reused so many threads can use the same instance but one at a time.

Is this correct ? or is it possible that multi-threading occur in one instance of SLSB ?If in the client I obtain a single reference of a SLSB and share this "instance reference" in multiple threads is it true that all the threads could use different instances on the server side ?

The stateful instance I obtain in the client is linked to one server instance and any method call will target the same instace. If many threads are using the same reference, all method calls will be synchronized and waiting for a certain amount of time that can be defined in @AccessTimeout and if the timeout is reach will end with a ConcurrentAccessException.

Can we use @Lock(READ) and let many thread use the same method like in a singleton ?

View Replies View Related

JSF :: Viewscoped Managed Beans

Nov 24, 2014

I have a primefaces editable datatable with column filtering feature.The datatable has live scrolling feature.The problem that i am facing here is that both filtering and scrolling are happening correctly with Request scoped managed bean but when the scope of the same bean is changed to view scope(javax.faces.bean.ViewScoped) then the filtering happens but on removing the keyed in key word from filter box the table content is not reset to original state and also i am not able to scroll down to next set of records on reaching the end of scrolling.Cell editing feature is working perfectly.

One thing that i observed is ,currently i am querying 5000 odd records to load into datatable.But if the number of records is limited below 5000 scrolling is happening correctly but problem with filtering remains same.I even tested by upgrading to Primefaces 5.1 from 3.Code snippet of xhtml page

<h:form id="form">
<div id="content">

<p:dataTable id="workSpaceList" var="data"
value="#{workSpaceBean.list}" widgetVar="multiSelection"
selection="#{workSpaceBean.selectedRows}" resizableColumns="true"
liveScroll="true" scrollRows="10" scrollWidth="90%"
scrollHeight="70%" styleClass="datatable"
tableStyle="table-layout:auto;width:auto important!;height:auto important!;padding-left:15px;"
scrollable="true" editable="true" editMode="cell"
filteredValue="#{workSpaceBean.filteredWorkSpaceItems}"
rowKey="#{data.lpID}" >

[code]....

View Replies View Related

JSF :: Using Generic Templates For Managed Beans

Aug 5, 2014

I'm wondering if there's a way to build a template for managed beans which could be extended by a constructor instead of re-writing beans for each entity. I can do that quite easily for Dao objects by creating facades and using those facades to create Dao implementations for specific entities. Not sure if the same concept works for managed beans and haven't really come accross any searches.

I wrote the following but I'm not sure how to implement or even if the concept of generics and templating can be applied to managed beans in the same way it can be applied to Dao classes:

public class BeanTemplate<T> {
private ListDataModel<T> listModel;
@EJB
private GenDao dao;
private Class<T> entityClass;

[Code] .....

The above assumes there's only one method needed in the bean. I thought of extending like this:

public class EmployeeBean extends BeanTemplate<Employee> {
public EmployeeBean() {
super(Employee.class);
}

// how can the methods be called??

Is the same concept for creating dao templates possible for managed beans?

View Replies View Related

JSF :: Not Showing Up Beans Attributes In XHTML

Jan 29, 2015

My code of start.xhtml is:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core">

[Code] .....

when I deploy the app(glassfish) I get this message only:
hi #{user.minimum} a #{user.maximum} .

Instead of a picture: wave.med.gif and message:
hi 0 a 10 .

file hierarchy is attached

View Replies View Related

EJB / EE :: How To Unit Test MDBs And Session Beans

Apr 18, 2014

What are the best practices for unit testing MDBs and session beans ?How can they be tested without running an application server ?

View Replies View Related

Java Beans Usage - Storing Data

Mar 7, 2015

I've spent almost 3 hours on googling about java beans and where it is usable. What I've figured out is that a bean has a public non-arg constructor, properties and getters/setters to manipulate them. I also know that a bean contains no logic, only fields. However, I don't fully understand why I need to use beans instead of normal classes even if a class can do the same things like a bean? Are beans used to store data or what?

View Replies View Related

JSF :: Model Of Backing Beans / Separated Class Or Just Properties?

May 29, 2014

I have seen in some examples like URL... a good design is to have the model and the action methods in one just single bean and the model not to be a separated class but a few properties like this:

public class CustomerBean implements Serializable{
//DI via Spring
CustomerBo customerBo;
[b]public String name;[/b]
[b]public String address;[/b]
//getter and setter methods

[code]...

Some questions:

1. If you are using hibernate or any other ORM like the above example(URL...), why not to use the hibernate pojo bean directly like it represented the form instead of using properties?:

public class CustomerBean implements Serializable{
//DI via Spring
CustomerBo customerBo;
[b]Customer customer;[/b] //represents the properties of a form
//getter and setter methods
public void setCustomerBo(CustomerBo customerBo) {
this.custom

2. Why is it said that JSF represents the purest MVC? Spring separates the model from the view too and Struts does too. I dont really understand it

View Replies View Related

JSF :: Primefaces In-cell Editing Not Working With Viewscoped Managed Beans?

Nov 17, 2014

I have an in-cell editable data table with a viewscoped managed bean.I found that the control never goes to the ajax event method onCellEdit when the scope of the bean is @Viewscoped but it works when the scope is changed to request scope.how to get this feature work with viewscope.Below is my code snippet

xhtml snippet

<p:dataTable id="workSpaceList" var="data"
value="#{workSpaceBean.lpInfoList}" widgetVar="multiSelection"
selection="#{workSpaceBean.selectedRows}"
scrollable="true" rowIndexVar="index" editable="true"
editMode="cell".......>

[code]....

View Replies View Related

Swing/AWT/SWT :: Stopwatch - User Select How Timer Format Is On Java Beans

Mar 17, 2014

I am working on a java bean, on a stopwatch

private String displayFormat = "%02d:%02d:%02d";// produces 00:00:00 hour:min:seconds
public void timerHasChanged() {
currentTime = System.currentTimeMillis();
// How long has been taken so far?
long secsTaken = (currentTime - startTime) / 1000;
long minsTaken = secsTaken / 60;
secsTaken %= 60;
long hoursTaken = minsTaken/60;
minsTaken %= 60;

Formatter fmt = new Formatter();
fmt.format(displayFormat, hoursTaken, minsTaken, secsTaken);
timerJbl.setText(fmt.toString());

How would i code the get and set method for format, so in property tab a user can choose if they want the timer shown in seconds, or minutes or hours or seconds&minutes

View Replies View Related

JSF :: View Scope Versus Application Scope For Beans

Sep 11, 2014

Viewing this example of pagination [URL] and other similar beans for pagination, why do they do these beans view scoped? These beans dont contain any properties for a form so they could be application scoped, right?

View Replies View Related

How To Reference Action Listeners

Mar 15, 2015

I am making an MVC program and I am not allowed to put the action listeners in the view class. I was able to get one button working fine but since I am unable to reference them I cannot give them both individual responses.

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Controller {
HobbyList model;
ListView view;

[code]....

View Replies View Related

ATM Machine - Action Listeners

Mar 27, 2014

My output is all over the place. I cancelled out the borderlayouts beneath each panel I created and it completely changed the output, and I'm not sure why. The first photo below, shows what it looked like with the layouts and the second shows the output without. I still don't understand why I don't see the digits 1-9.

Java Code:

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
public class Atm extends JFrame {
Atm(){
super("ATM");
//Create Panels For ATM
JPanel buttonPanel1 = new JPanel(); //To Contain Digits 1-9

[Code] ....

Why would setting the layout beneath each object change the layout so much? I stayed consistent in my use of BLayout and GLayout in the program.

View Replies View Related

Timer Action Listener

Oct 5, 2014

Whenever i click start button it will just printout start to the jtextfield it wont start the time .

import java.awt.*;
import java.util.Date;
import javax.swing.*; 
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.*;
 
[code]...

View Replies View Related

AWT Action Listener In Swing GUI?

Feb 22, 2014

I'm using Eclipse with the Window Builder Pro plugin to create a Java program. I noticed that when I had Eclipse create an action listener for a combobox in a Swing GUI it created an AWT listener.

Did I choose the wrong type of listener? I want my code to use the Swing components because I understand that they are more portable.

View Replies View Related

Passing Data From One Action Event To Another

Oct 5, 2014

this is the first code

import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class ChickenListener implements ActionListener {
int loopctrl;
static Connection cn;
static Statement st;
static ResultSet rs;
static PreparedStatement ps;
 
[Code]...

the second code

import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class QuantityCounterListener implements ActionListener {
String tempStrng;
int tempInt;
int x = 0;

[Code]...

what my problem is i need to transfer what does "tempString" from code 1 holds to code 2 in the //x part in the prepared statement.

View Replies View Related

Swing/AWT/SWT :: Multiple Action Listeners?

Oct 25, 2014

So im making a calculator just basic 4 function with a clear button. as i am working into this project i am running into an issue of assigning which click sets what. For instance i click the two button how do i tell it to assign it to firstNum, versus secondNum?

private class theHandler implements ActionListener{
public void actionPerformed(ActionEvent event){
if(event.getSource()==one){
firstNum=1;
}
if(event.getSource()==two){
secondNum =2;
}
if(event.getSource()==three){
secondNum =3;
}

So this for instance allows me to set one to the firstNum and then add it to two or three but im not sure what to do next. I have in my mind i want to do something like make three listener classes, that operate in sequential order like you pick the first numbers, click an operation, and then select the second numbers then hit the operation(equal) button to display answer. Am i on the right track or what?

View Replies View Related

JSP :: How To Have Common Page For Different Action Name But Have Same Layout

Mar 16, 2015

I have developed a web portal using jsp and struts 2. I have approximately 10 JSP pages which looks exactly the same and have two text areas and two hidden fields. All 10 pages are exactly the same except for hidden field value. Can't i have a single common jsp page. How can i achieve it. A sample page i am attaching...

<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ page pageEncoding="UTF-8"%>
<%@ page language="java"%>

[Code]....

As this is an Assignment page so hidden field value is assignment. If the page is OBJECTIVEs then value will be OBJECTIVE.

View Replies View Related

How To Change Action On 2nd JButton Click

Aug 3, 2014

I cannot...(actually do not know) how to change the actionlistener (actionPerformed) after the second click in an array of JButtons. This is how the program performs right now.

On the 1st click on the grid, the border of the button clicked will change to 'blue' and another button will change its boarder to 'red'. on the next click the same action is performed.

What I need is to change action when the 'red' bordered button is clicked, lets say change the color of the buttons from the 'red' to the 'blue' buttons.(x 3 buttons).

The logic about how to perform the final result I think I can do on my own but my problem is how to change the action when the red bordered button is clicked.

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;

[Code].....

View Replies View Related

JPanel - JButtons Not Using Action Listener

Apr 22, 2014

In my code 0,1,2 work fine an present my prompts an use my listener correctly but for some reason 3-6 is not an I don't know why? Here's my attached code.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class Guess extends JFrame

[Code] ....

I meant 3-5 not 6

View Replies View Related

Swing/AWT/SWT :: JComboBox Listener - Bound Action?

Jul 14, 2014

I have three JComboBoxes. When the user selects an entry in the first JComboBox the entries in the second are set. For this I use an Action extends AbstractAction which is bound to the first JComboBox.

I have also bound an Action to the second JComboBox.

Problem: this also fires when the entries on the second JCombox are added which leads to a Nullpointer.

I need a Listener which only reacts to user input, and does not react when the model of the JComboBox is changed.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved