ADF Refresh page jsf with page fragments jsff after set session variable - jsf

I have a template which includes a button that let you select a profile, you push the button and appear the available profiles, choose one and push accept. After that I set a variable session successfully.
I have a "First" jsf page with two jsff page fragments from a View Link. The view link is composed by a headerView and detailView. The headerView had a bind variable. What I need is that parameter (bindVariableParameter) can be set by the session variable of the template.
This is what I get:
I am in a home page (separate Application Module), I push the template button before I load de "First" jsf page and after that I go to the "First" jsf page the information is loaded successfully. What I do in the Application Module is something like that:
protected void prepareSession(Session session) {
Map sessionScope = ADFContext.getCurrent().getSessionScope();
String company = (String)sessionScope.get("compId");
System.out.println("Default Comapny in BC is: " + company);
super.prepareSession(session);
this.getSession().getUserData().put("Company", company);
System.out.println("After setting value in userData map of BC");
}
And in the bind variable expression of the headerView I use:
adf.userSession.userData.Company
It works great!!!! But!!!!
When I press the button again and I choose another profile, the info is not updated. Neither in the headerView neither in the detailView.
Also, when I go to the "First" jsf page (without previously push the template button), I got no info, which is right, because I don't have any session variable. After that I push the template button and select the profile, but the page is not refreshed.
I tried several ways to to this but I'm lost.
Could you help me?
Regards.

You have two options for this:
Option one: tune your AM as follows:
jbo.doconnectionpooling=true
jbo.txn.disconnect_level = 1
This will ensure prepareSession() method is being called before each operation. This happens to be a best practice in ADF productions systems, increasing scalability (see here )
Option two: Better than using prepareSession(), you can pass the Http Session data to ADF BC through a custom DataControlFactory.
You can find an example here: http://andrejusb.blogspot.co.uk/2012/05/solution-for-sharing-global-user-data.html

Related

ADF using EL in Java code

I've got a main page that displays number of records, when I click on create, it should navigate to create form (another JSF), where on Submitting the new record, it should navigate back to main page and display all the records including the new one.
I've been able to achieve the navigation using navigation rules in adfc-config file. And I've created Action method (beans) that returns expected string used in navigation.
What challenge I'm facing now is on button click, I can invoke only one method (action), which has to return the expected string for navigation. Or I can use EL that does the refresh. So I'm either able to Refresh the page after creating a new record, or able to Navigate. Can't do both. (Usage of actionListener won't work, because actionListener works before action, my requirement needs sequential execution.
Is there a way I can use EL in my Java code? So that I can put it right after the record creation and before return string?
Some method that executes method specified by EL, where I just have to pass the EL as a string?
Update: Both Query (display) and Insert are API calls.
From what you're saying, you're using the Unbounded task flow adfc-config to build your navigation business logic. This is not right! The Unbounded task flow's primary purpose is to define the base structure of your site. For example, on your Homepage, if you have a link for "Create Department" and another one for "Add Employee", there would be only 2 simple navigation rules to link to those independent pages.
To achieve your goal, what you need is a Bounded task flow and a few page fragments. The picture below is an actual Bounded taskflow in one of the applications I worked on. Let's take it as an example.
The main feature of a Bounded task flow is that all fragments in the same task flow will share a common data control (i.e. all fragments will see the same set of data). As you can see from the picture above, my starting page is a Search page for Corporate cards, where I'll display all records based on what users search for.
On this Search page, I also have a Create button to allow users to create a new record, which would lead to the Details page (which is also the page to edit current records). Once users commit the transaction on the Details page, they will be redirected back to the Search page by following the viewCorporateCard navigation rule. Since both the Search page and the Details page share the same data control (the same iterator to be precise), users will automatically see the new record on top of the Search page when they're back here. You don't have to do anything manually to achieve this.
Hope this helps! :)
To pass EL value as string
this.setvalueToExpression("#{bindings.Orderno.inputValue}",
"sample");//pass string value
public void setvalueToExpression(String el, Object val) {
FacesContext facesContext = FacesContext.getCurrentInstance();
ELContext elContext = facesContext.getELContext();
ExpressionFactory expressionFactory =
facesContext.getApplication().getExpressionFactory();
ValueExpression exp =
expressionFactory.createValueExpression(elContext, el,
Object.class);
exp.setValue(elContext, val);
}

How to Refresh ADF jsf page components by pressing a button?

I have a fusion web application that contains an af:query panel (I created it query panel with table), and af:table and af:panelFormLayout that are related with each other. When I search an entry in the query panel results are shown both in table and in panelFormLayout. When I press reset button in the query panel, only the query panel is reset. I want to all the page to reset. How can I do that by using the easiness of ADF?
Basically you want to override the reset functionality of the af:query. In that case, you should:
1. Set the QueryListener property of the af:query to a managed bean method. You can refer to this example which describes all the steps required: Programmatically RESET query panel
Inside it, you'll see this call: AdfFacesContext.getCurrentInstance().addPartialTarget(t1);
It is responsible for the refresh of the table. Now, if you have all the content inside an af:panelGroupLayout for example (or any other payout type component), you can refresh it instead (so you need to bind it with a field on the bean and use it instead of t1 in this call. Otherwise, if you still wish the full page refresh, follow step 2.
2. Add the needed code to make the page refresh:
FacesContext context = FacesContext.getCurrentInstance();
String currentView = context.getViewRoot().getViewId();
ViewHandler vh = context.getApplication().getViewHandler();
UIViewRoot x = vh.createView(context, currentView);
x.setViewId(currentView);
context.setViewRoot(x);
Just put it inside the method described on the above link.

How to access separate yui object from one another

In "Start Workflow" page, "Start Workflow" form is generated from Form-Engine.
I want to disable "Start Workflow" button when submitting form. When
callback, I want to enable this button.
In start-workflow.js, I can get this button by using
var submitButton = Dom.get(this.generateId + "-form-submit-button");
submitButton.setAttribute("disabled", "disabled");
But adding attribute "disabled" does not work in IE8 as button can even click. But it works in mozilla. But by using yui disabled,
this.submitElements[0].set("disabled", true); can be work.
The problem is that how can I access Alfresco.FormUI(form.js) from Alfresco.component.StartWorkflow(start-workflow.js). Since they are separate yui object, I do not know how to access from one another.
If you know, let me share your knowledge and experience.
If the other component extends Alfresco.component.Base then it should have registered its presence on the page when it was instantiated.
You can then use Alfresco.util.ComponentManager (docs) to retrieve the instance you want, e.g. if it is the only instance on the page,
var otherCmpt = Alfresco.util.ComponentManager.findFirst(p_sName)
where p_sName is the full name of the class as a String value, e.g. "Alfresco.FormUI".

Maintaining state between pages in seam

I have a xhtml page with Search criteria and search results. Clicking on search button will dynamically update the results on the same page. I have a controller for search/results xhtml in Page Scope.
There is an edit button in every record in the search results. Clicking on the edit button will open a new page(new controller in Page scope). Once I edit and save I want to come back to the search criteria page with search resutls.
I can store the search criteria in session and requery and display the results. I looked at conversation and I am not sure if I can use it in this scenario?
Any ideas other than dumping the data in session for this scenario?
Pass the search criteria to the edit view as well (but don't display them or something) and then let the edit view pass it back to the search view once editing is finished.
If you want to persist data between two pages, you have many ways:
1) String parameters
2) Session data
3) Long running Conversation
4) Serialize your data elsewhere (DB or other).
Since you are talking about "saving" I may think you are saving your data in a database. If you have persisted your data in the second page in some way you can just query for them.
Otherwise you can use session and conversation, the second has a "smaller" and defined scope. You can decide when to create one and to create destroy. Simply put a in the first page pages.xml and create a bean with conversation scope.
The session scope will keep your data in your session scoped component until you close your browser.
Hope this helps.
I would go with the session scoped bean. If you use a search bean you can go anywhere in your application and maintain your search state, also it lends itself to saving searches in the database (so users can save searches between sessions).
#Scope(ScopeType.SESSION)
#Name("someRandomSearch")
public class SomeRandomSearch {
private SearchObj1 userSelection1;
private List<SearchObj1> searchCriteriaList1;
private SearchObj2 userSelection2;
private List<SearchObj2> searchCriteriaList2;
private String randomUserInput;
// getters/setters, some helper classes, cascade dropdown stuff, etc.....
// clear search criteria
public void reset(){
this.userSelection1 = null;
this.userSelection2 = null;
this.randomUserInput = null;
}
}
Just make sure to implement equals method in your model classes - maybe that's obvious, but when I first started using Seam I missed this little tidbit and it took forever to figure out why we couldn't hold onto dropdown selections in our search pages.
If when you say "open a new page", you mean navigate to another page in the same browser window/tab, then a Conversation is the ideal method for storing the search state.
Depending on your detailed use case, you might prefer to setup nested conversations (when you click on the edit).
You might also want to setup a pageflow to manage that particular navigation logic.
See the official documentation.

Populating a page from Data table in modal panel

I'm trying to get some data from a datatable in rich:modal panel
The whole flow is as follows
When clicking on search button on main page, a modal panel pops up with appropriate data & check box
Till this point the application is working fine
After clicking on ok button, selected data should be populated into main page. This is where the code fails
I tried stuff like getRowData, getValues, etc. but in vain. This could be done by keeping the bean in session scope but I have to keep this bean in request scope using Apache MyFaces JSF 1.2
Two ways comes to mind:
Pass an extra request parameter (the search string and the page number?) so that the bean knows which data to preload.
Make use of MyFaces Orchestra to create a conversation scope which lies in between request and session scope and is exactly the scope you're looking for this particular functional requirement.

Resources