JSF :: Passing Backing Bean To Another Class
Mar 7, 2014
I am new to JSF and was trying to find an example.
My question is in the processPage() method... how do i pass the managed bean to the ProjectDAO insert statement?
Faces-config.xml
<managed-bean>
<managed-bean-name>projectBean_backing</managed-bean-name>
<managed-bean-class>com.att.ped.backing.Project</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
[Code] .....
View Replies
ADVERTISEMENT
Apr 6, 2015
I tried to create my first javaweb project. However when some action were being invoke I received an error. Here is what I did:
Person.javapackage org.javaeesample.entities;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
[Code].....
When tried to run my project what happened were:
1. When i clicked the link from show.xhtml
<h:link value="#{p.name}" outcome="details">
<f:param name="pid" value="#{p.id}"/>
</h:link>
It output the page but without data being displayed.
but on the url it shows: [URL] .....
1. When i clicked 'Save' button in create.xhtml here is the error i received:
An Error Occurred:
View Replies
View Related
Dec 11, 2014
I am using a command button to post a form to backing bean method. At the end of that method I am attempting to redirect to an external site after setting various options in the response. I get an IllegalState Exception because of the redirect.
at com.ibm.ws.webcontainer.webapp.WebAppDispatcherContext.sendRedirectWithStatusCode
(WebAppDispatcherContext.java:571)
at com.ibm.ws.webcontainer.webapp.WebAppDispatcherContext.sendRedirect
(WebAppDispatcherContext.java:528)
at com.ibm.ws.webcontainer.srt.SRTServletResponse.sendRedirect(SRTServletResponse.java:1234)
at com.sun.faces.context.ExternalContextImpl.redirect(ExternalContextImpl.java:426)
at com.sun.faces.application.NavigationHandlerImpl.handleNavigation(NavigationHandlerImpl.java:181)
here is the problem code from the backing bean method:
if ( redirectPage != null ) {
logger.debug("attempting redirect: " +
View Replies
View Related
Jun 13, 2014
Here I am taking response data from JSON using jackson API.I found a feature like using Jackson the properties can be set to bean properties.
private static String readUrl(String urlString) throws Exception {
BufferedReader reader = null;
try {
URL url = new URL(urlString);
reader = new BufferedReader(new InputStreamReader(url.openStream()));
[Code] ....
I got the correct output here. But now I want to generalize my method into a utility class so that I can reuse the same method for setting response data directly to respective beans as given below:-
My question is how will I pass the bean object in my utility class?
public static Object getResponseData(String response,[b]String bean[/b]) throws Exception {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
JsonNode root = mapper.readTree(response);
[Code] ....
View Replies
View Related
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
Apr 8, 2014
I have an xhtml file with this content:
<h:inputText tabindex="7" styleClass="input" id="title" value="#{register.title}"
required="true">
</h:inputText>
Basically I want the user to enter his title (e.g. Mr., Dr.), which would be passed on to a bean which would send this information to me in email.
I also have a bean called register, along with setters and getters:
private String title;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
I want to pass this information to a String called body, within the bean:
body = body+"Title: "+this.title+"
";
I would then send the String in an email.
View Replies
View Related
Feb 18, 2014
Class UserAssessBean{
private String username;
private int userid;
private ArrayList<ModuleBean> module;
--{get/set}--
[Code] ....
How can i access the getters/setters of module bean, when it was returned as array list in UserAssessBean?
View Replies
View Related
Jan 8, 2014
I've 3 classes.
1. Circle
2. GetInputFromUser
3. testCircle
package ABC;
public class Circle {
private double radius;
public double getRadius() {
return radius;
[Code] .....
In the testCircle class, in the line: getRadius = ui1.GetInput();
It's showing the error: The method GetInput(float) in the type GetInputFromUser is not applicable for the arguments ()
And when I do: getRadius = ui1.GetInput(rad);
It's showing the error: rad cannot be resolved
View Replies
View Related
Nov 7, 2014
Getting JS -> JSF value to Bean class? I have tried with below code:
JSF code:
<h:commandButton styleClass="buttonpos" value="Get Value" action="#{myBean.action}" onclick="document.getElementById('crForm:hiddenInput').value">
<h:inputHidden id="hiddenInput" value="#{myBean.action}"/>
</h:commandButton>
Java Beans
public class CurrencyExchangeBean {
protected static Logger logger = ILogger.getLogger(CurrencyExchangeBean.class);
[Code] .....
View Replies
View Related
May 10, 2014
here i have my bean class
package com.emp;
public class salarybean {
private String name;
private Double days;
private Double id;
public String getName() {
return name;
[code]...
now i want to retrieve all these values in another servlet where i want to do some calculation but not able to retrieve it is showing null and indicating for this value in my eclispe IDE " Iterator<salarybean> itr=list.iterator(); "
public class Time extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException
[code]....
View Replies
View Related
Feb 23, 2013
I am doing this
@Startup
@Singleton
@ConcurrencyManagement(ConcurrencyManagementType.CONTAINER)
@Lock(LockType.READ)
public class ResourceBean {
[Code] ....
And I call this singleton bean from a stateless session bean like this
@Stateless
public class ClientBean {
@EJB
ResourceBean resource;
public String create(String r)
{
String res=resource.returnString(r);
return res;
}
}
But resource.returnString(r); gives a org.apache.jasper.JasperException: java.lang.NullPointerException I started the glassfish server in debug mode and found out that "resource" was null. but @PostConstruct in singleton does print which means singleton bean exists.
Can we call singleton beans with no interface in such a way form a session bean? I actually want to acquire instance of singleton bean when a client invokes method in Client bean...
View Replies
View Related
Nov 21, 2013
I'm new to JSP but I've to use it to grab data coming from an external site, pass data to a Bean, write data in a DB and redirect the user to another page. Follow the JSP page.
<%@page import="EJB.getResponse"%>
<%
long paymentID = Long.parseLong(request.getParameter("paymentid"));
String responsecode = "9999";
getResponse g = new getResponse();
[Code] ....
This is the bean:
@ManagedBean
@RequestScoped
public class getResponse implements Serializable {
private Long paymentId;
private String result;
private String auth;
[Code] ....
On the console I see the prints but I receive the NullPointerException
WARNING: StandardWrapperValve[jsp]: PWC1406: Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
at EJB.getResponse.printData(getResponse.java:72)
at org.apache.jsp.notify_jsp._jspService(notify_jsp.java from :60)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
[Code] ....
View Replies
View Related
Oct 19, 2014
So the first thing we did was make a program called memory calculator. now we are supposed to make a sub class that modifies the program to also do exponents and natural logs. Then to make a new class that acts as the driver for what is now called the scientific memory calculator which includes the exponent and log. I have watched this through debug and im a little confused. first off it creates a variable for currentValue in current and in sci which are my instances, which i dont think is what i really want to do, I am unsure how to get the things in the Scientificmemcalc to do stuff without calling them directly. so when i try to do the power feature it does everything correct but it sets the sci current value to the correct answer, and now i cant figure out how to pass it on to the current current value.
This is the memory calculator :
public class MemoryCalculator {
public static void main(String[] args) {
MemoryCalculator current = new MemoryCalculator();//creates an instance
int choice = 0;
do{//main loop
System.out.println("Current value: " + current.getCurrentValue() + "
[Code] .....
View Replies
View Related
Oct 30, 2014
I will detailedly explain my requirement below,. I am going to automate a manual process. I will be reading multiple CSV files from a remote location using java.There are five formats of input files are expected, each differs in their header structure. For example, Type 1 - Number, ID, Name, Phone, Address...Type 2 - Number, GID, Employee Name, Address1, Address2, Phone number and so the other three types are also differs.
The precondition is not all the files are expected for a particular run. I need to read these files one by one, validate it, log the validation error and i have to consolidate all the correct data from all the files together in a standard output format, in a single file The standard output format will be like,Number, Name, ID, Address
I need to have the above data alone in the output file and rest of the data can be ignored.What i have tried is as follows, I have created 5 bean classes representing each type's header. I just read an input, identify its type and parsed it. I parsed line by line.
public String[] parseCSV(String inputLine){
try {
String[] fields;
Pattern p =
Pattern.compile(",(?=([^"]*"[^"]*")*(?![^"]*"))");
fields = p.split(inputLine);
/*for ( int i = 0; i < fields.length; i++ ) {
System.out.println(fields[i]);
}*/
[code]...
I have validated as per the validation rules and i appended each line elements into an object. I have added all the objects in to a MAP collection. Likewise, i have created 5 beans and did the same.But, what is the change needed now is,. All the headers in all the five types of rosters are configurable items. hence, i have to change my bean classes everytime when the header structures are changed.
We have to create one single utility, which is configurable for all the five types of input files. To be very clear, if type 1 input comes with 8 columns and type 3 comes with 12 columns, the utility is able to parse it.
We are going to have a table which has the data regarding the header structure of all the five types of inputs alone. Once i read a file and identify its type, i will hit the database and read the header structure of that particular type and its column count. I will match the column count with the input file's header count and i will have to proceed creating a bean class on runtime depending upon the header structure read now. I will validate and consolidate as i did above. The requirement is, Runtime configuration of bean class, depending upon the type of input.
View Replies
View Related
Nov 8, 2014
I am trying to pass value from class to another using net beans but it seems that I am doing something wrong.
find my basic code at sourceforge.net/projects/val1toval2/files/SRC/
I would like to have both VAL1 and VAL2 having same value in Jlabel.
//Main.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
Second SEC = new Second();
l_dis.setText(String.valueOf(getInput()));
l_tot.setText(String.valueOf(SEC.getTotal()));
[code]...
View Replies
View Related
Apr 6, 2015
I enter a value in the text box in one class and want to pass that value to another class in order to compare it and color the cell in a table. In the first class I have
package cege.ui;
import cege.controller.HtmlController;
import cege.controller.ScreenCaptureController;
...
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
[Code] .....
How to pass the threshhold from the first to the second class?
View Replies
View Related
Aug 16, 2014
It just wont work... Everytime I try to pass a variable into a class it sets it to 0. What to do.
The variable should be '2', but it prints out as 0!?
Java Code: package Zoo;
import java.util.Random;
public class Animal {
Random random = new Random();
public void Eat(){
System.out.println("The animal starts to eat.");
[Code]...
The method bash, needs the variable 'playerTwo' to be 2, to carry on. But it prints out 0.
Int the animal constructor, I passed in the variable from another class, and it prints out 2 in the constructor like it should. But outside of the constructor it is equal to 0.
View Replies
View Related
Feb 19, 2015
I am trying to get the username and password for one class and send them to another. However I cannot send them in the constructor because a database class is getting them and I need that constructor blank. However if I do not pass the class in the constructor I get a NULL error, even better when I do pass it in I seem to get a thread lock. I do try to do my own housekeeping and close the one frame before I open a new one but it doesn't work. I will do my best to show the design of the program.
program starts
Java Code: public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
// connects to database and generates a GUI
new UserPromptScreen();
[code]....
I have to pass in UserPromptScreen in for it to work. This will cause me issues later with my design.
View Replies
View Related
Feb 7, 2014
i want to list files from resources folder like this:
@ManagedBean
public class galley implements Serializable {
private List<String> list;
@PostConstruct
public void init() {
list = new ArrayList<String>();
[Code] ....
but it give me a null pointer exception on fList .... The directory of resources is :
How is this caused and how can I solve it?
View Replies
View Related
Nov 15, 2014
Java Code:
createConnection();
try{
String str = "select * from Stocks";
stmt = conn.prepareStatement(str);
ResultSet rs = stmt.executeQuery();
while(rs.next())
jcbStock.addItem(rs.getString("stockID"));
}catch(Exception e){
e.printStackTrace();
} mh_sh_highlight_all('java');
I want to put this code in a class then call it in another class , but i do not how to do that. This code is working fine in my main class , but i want to write this code to another class for call it in main class.
View Replies
View Related
Mar 23, 2015
I'm getting this error, I definitely know that is my error trying to pass method/variable because when I commented received part of my code it ran and worked.
I get this error
at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Here are my 2 classes
Java Code:
import java.awt.BorderLayout;
import java.awt.Checkbox;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
[Code] .....
View Replies
View Related
Sep 7, 2014
I am having trouble taking user input and passing it to another class as a variable. If I assign the value explicitly (see line 59), it works just fine. What I want to do though, is assign the input from inputField to the variable inputVariable. I tried using:
inputVariable = inputField.getText();
This does not work. Regardless of what is typed into inputField, the output I get is just:
"The user typed "
package example;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
[Code] .....
View Replies
View Related
Dec 13, 2014
Assuming that we have two classes B and C which inherit from class A. What is the best way to pass a parameter from an object of class B to an object of class C by the use of class A without using static variable and without defining a get function in B?
View Replies
View Related
Aug 26, 2014
What is the best way to synchronize a Model representing a complex UI composite w/ a FlowPane's backing list?
Currently I have a change listener on the Model. Upon an add I create a new UI composite and manually add it to the FlowPane's backing list via flowPane.getChildren().add(). Similarly if there is a remove, I iterate over the FlowPane's children, grab the right Node, and remove it. Similarly, if there is a modification detected, I iterate over the FlowPane's children, grab the right Node, remove it, recreate the UI composite, and re-add it to the list. I also need the list to be sorted, so I implemented a UIComposite comparator and call FXCollections.sort() on the FlowPane's backing list. I feel like that is hacky, but it works. It would be cool if I could maintain sort order in my model somehow and have that automatically propogated to the FlowPane's list.
I am correct in assuming that there is no way to have a complex binding in between an ObservableList<CompositeViewModel> and the FlowPane's backing list (ObservableList<T>)?
Some kind of translator that could create a new UIComposite whenever there is a new CompositeViewModel added to the Model list.
View Replies
View Related
Nov 9, 2014
I have tried this example ([URL].../) with CarDao extending the BaseDao, it works like a charm.However, from the CarDao class, my NetBeans underlined the class name “CarDao” with the error message “A session bean must not extend another session bean.” But I can compile, deploy and run the application without any problem.
I have also heard that a session bean cannot extend another session bean, but why it works here?
I am using Java EE 6, NetBeans 8.0.1 and WebLogic 12c for this code testing.
View Replies
View Related
Aug 8, 2014
I have a managed bean for a form. I map the fields filled in the form with managed bean properties. when I submit the form and click new form , values from the previous form submitted gets displayed in the input fields. I used the scope of the from bean to session. what should be its scope so that values should be destroyed after I submit the form .For every new form ,new bean has to be initialized. On submit I navigate to another bean with session scope.
View Replies
View Related