Storing inputText values when "jumping" from one controller to another - java

I have the following mask/view:
After entering the name and description, I can add a list of existing attributes by clicking on "Add existing" button.
This opens another mask/view, where I can select from a list of existing attibutes. This (new) mask/view has it's own controller and model too.
When I'm finished with the selection, I have another button that bring me back to this mask.
The problem is that when I come back the name and description fields are empty.
This happens because when I click the "Add existing button" the controller/model of this mask is not called and the values are not stored.
How can avoid this and have the values stored?
Thank you for any help
Francesco

This only works if the new view is inside the same view. E.g. when it's an overlay dialog which is presented by a hidden <div> and not a plain window.open() popup window. This way the beans will have access to each other and you will be able to execute ajax updates instead of submitting/refreshing the entire page.
This is pretty complex to homegrow if you're not that familiar with HTML/CSS/JS. I suggest to look at a component library which offers such a component like RichFaces' <rich:popupPanel> and PrimeFaces' <p:dialog>.

You can store data in session or conversation bean.
Session bean approach have huge drawback when user works in multiple tabs/windows - he uses only one session bean, so he overwrites what he did in other windows.
Conversation scoped bean solves this. But conversation scope was not in javaEE 5, its in CDI (part of EE6).

Related

In ADF Page refresh

I have three tables in a page. When I click on a button, I update only one of the tables. But since I use request scope on button event, the page reloads fully and updated value gets lost. Can you suggest a solution, so that my data will be displayed after button event.
Have you tried to set partialSubmit="true" in your button? If you set this attribute, you must set in each table a PartialTriggers to the button.
I hope help you.
Marcos.
The data has to be in the viewScope/pageFlowScope depending on whether its in a bounded taskFlow or not.
And in your button event you need to update the data in the viewScope/pageFlowScope and then bind your tables with those data.
All the event handlers can be in backingBean scope and not necessarily be in requestScope.

Check for entry in text fields and comboboxes to enable a button Java Desktop Application

I am writing a Java application for digitizing a group of documents in the office that I am working in and I am wanting to check if 5 textfields are populated and 4 combobox fields as well before the save button is enabled (I have it checking if i press a button (that happily says "Check"), but i would much rather have it auto-check to see if they are populated or if they are null).
If it makes a difference i am using NetBeans for this project.
Basically I need the fields to have something in them before the document can be saved.
Any and all help will be greatly appreciated as this is the final step in creating this application... :D
Thanks,
Erik
There are two ways (I can think of):
1- Put a listener on each field, this listener will be triggered when the field is populated. Inside the listener increment a counter for example, or set a flag. If all flags are set or if the counter reaches (9 in your example) then enable the button.
2- Enable the Save button, but call a validate() method before doing the Save action. Any unpopulated field will have a red mark beside it (shown by validating) like in web applications.

How to dynamically select the next page of a wizard

I need to create a wizard in which the first page allows the user to select the type of the element to create, and the following pages create and set-up the selected type. In several aspects it is similar to the standard New Wizard (File->new...) but I need more control on what's happening.
How can I do that? Does there is any tutorial about that?
I see three options on how to achieve this:
Override the getNextPage(...) function of Wizard
or
Add the remaining pages to the wizard just-in-time. That is, after the user has selected what type of element to create.
or
Make the remaining wizard pages dynamic in such a way that they have different contents depending on what kind of element is being created
I recommend the first option.

JSF 2.0 Dynamic Views

I'm working on a web project which uses JSF 2.0, PrimeFaces and PrettyFaces as main frameworks / libraries. The pages have the following (common) structure: Header, Content, Footer.
Header:
The Header always contains the same menu. This menu is a custom component, which generates a recursive html <ul><li> list containing <a href="url"> html links, this is all rendered with a custom renderer. The link looks like 'domain.com/website/datatable.xhtml?ref=2'. Where the ref=2 used to load the correct content from the database. I use prettyfaces to store this request value in a backingbean.
Question 1: Is it ok to render the <a href> links myself, or should I better add an HTMLCommandLink from my UIComponent and render that in the encodeBegin/End?
Question 2: I think passing variables like this is not really the JSF 2.0 style, how to do this in a better way?
Content:
The content contains dynamic data. It can be a (primefaces) datatable, build with dynamic data from the database. It can also be a text page, also loaded from the database. Or a series of graphs. You got the point, it's dynamic. The content is based on the link pressed in the header menu. If the content is of type datatable, then I put the ref=2 variable to a DataTableBean (via prettyfaces), which then loads the correct datatable from the database. If the content is of type chart, I'll put it on the ChartBean.
Question 3: Is this a normal setup? Ideally I would like to update my content via Ajax.
I hope it's clear :)
It's ok to just output link yourself, commandLink is out of the question (it does a postback using javascript, it's not what you want);
Parameter are all in the param implicit object. You can insert them by a #ManagedProperty annotation, like this:
#ManagedProperty("#{param.ref}")
String ref
// .. getters, setters (obligatory!)
You can also use (if you are on JSF 2) the f:viewParam tag (a nice description http://blogs.oracle.com/rlubke/entry/jsf_2_0_bookmarability_view), you get the bonus of validation and conversion.
The way I understand it, your setup is rather complicated. Using a handwritten custom component for a menu is a huge overkill (at least judging from the provided description), a composite component would probably do. JSF has no special way of making ajax calls between views or embedding views one into another, so - unless you use iframes - your only choice would be to include all the possible pieces of content into a single view, wrapped in panels, and render them as required:
<h:panelGroup rendered='#{backingBean.ref == 2}'>
... content 2 ...
</h:panelGroup>
and so on. Careful, this would be heavy on resources.
You could also write your own ajax solution in javascript. This would require all the pieces of content to be fully independent views, with their own forms. Also, all their postbacks would have to go through ajax, so the main page does not get reloaded.

In an Eclipse RCP editor, what is the best way to handle missing mandatory fields?

On an Eclipse RCP application, I'm building an Editor in which some fields are mandatory.
If the user saves the editor with theses fields not filled, what is the best way/practice to handle this ?
(my first guess is to show an error dialog if theses fields are empty in doSave() method but I'm not sure it's the "eclipse" way to deal with this kind of problem)
If you consider some dialog box like "Create a New Java Project",
you simply cannot do any action (like "Next" or "Finish" until you fill the one mandatory field ("Project name")
So it is different than checking on the doSave() event.
If that field is invalid (like if the project name already exist), a warning is displayed in the zone at the top.
If the field is correctly filled, then you can save.
(Note: I know this is not an Editor, but it can give you an idea about the mandatory fields management in eclipse)
alt text http://ds.informatik.uni-marburg.de/MAGE/gdt/images/tutorial/NewJavaProject.png
I agree with VonC and would disable the "Save" button, as long as the user has filed all the important fields.
Showig a warning which fields the user has to fill would help a lot.
EDIT:
Create a component which added himself as change listener. When someone changes the component, you can check whether the input is correct.
Create a window whith all the self-checking components and add the window as listener to all the components.
When somebody change a compounent you can directly check if the input is valid and the user can step to the next page or save the page.
In RCP (Example FieldEditorPreferencePage) a lot of components have the doSave() and isValid() methods.
In isValid() you can check all the components you can find in the window and in doSave(), you sould check the isValid() state, when it is not done automatically, and do some additional save actions.
You could use FieldDecorations to mark the mandatory fields and provide visual feedback if the content of a field is incorrect.

Categories